summaryrefslogtreecommitdiff
path: root/Project-Unite/Controllers
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-04-05 20:24:19 -0400
committerMichael <[email protected]>2017-04-05 20:24:19 -0400
commitae757d47d51a57f83a43a527481d01f63b9fc741 (patch)
treee9812164ffc125d512d98556eac8c6fbcb678c7e /Project-Unite/Controllers
parent371fb31867415b880e080664ef9fc42b6c62bd1f (diff)
downloadproject-unite-ae757d47d51a57f83a43a527481d01f63b9fc741.tar.gz
project-unite-ae757d47d51a57f83a43a527481d01f63b9fc741.tar.bz2
project-unite-ae757d47d51a57f83a43a527481d01f63b9fc741.zip
You can now release builds from the dev CP.
Diffstat (limited to 'Project-Unite/Controllers')
-rw-r--r--Project-Unite/Controllers/DeveloperController.cs101
1 files changed, 101 insertions, 0 deletions
diff --git a/Project-Unite/Controllers/DeveloperController.cs b/Project-Unite/Controllers/DeveloperController.cs
index b380acb..0825eb1 100644
--- a/Project-Unite/Controllers/DeveloperController.cs
+++ b/Project-Unite/Controllers/DeveloperController.cs
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
+using Microsoft.AspNet.Identity;
using Project_Unite.Models;
namespace Project_Unite.Controllers
@@ -22,5 +24,104 @@ namespace Project_Unite.Controllers
var db = new ApplicationDbContext();
return View(db.Downloads);
}
+
+ public ActionResult AddRelease()
+ {
+ if (!ACL.Granted(User.Identity.Name, "CanReleaseBuilds"))
+ return new HttpStatusCodeResult(403);
+ ViewBag.Developer = true;
+
+ var build = new PostDownloadViewModel();
+ return View(build);
+ }
+
+ const string ApprovedIdChars = ".-_abcdefghijklmnopqrstuvwxyz1234567890";
+
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult AddRelease(PostDownloadViewModel model)
+ {
+ if (!ACL.Granted(User.Identity.Name, "CanReleaseBuilds"))
+ return new HttpStatusCodeResult(403);
+ if (!ModelState.IsValid)
+ return View(model);
+
+ //Create a new database context.
+ var db = new ApplicationDbContext();
+
+ //Create a new "Download" data object
+ var download = new Download();
+ //Set the ID.
+ string new_id = model.Name.ToLower();
+
+ foreach(var c in new_id.ToCharArray())
+ {
+ if (!ApprovedIdChars.Contains(c))
+ new_id = new_id.Replace(c, '_');
+ }
+ new_id += "_" + db.Downloads.Count().ToString();
+ download.Id = new_id;
+ //Set the name.
+ download.Name = model.Name;
+ //Set the author
+ download.ReleasedBy = User.Identity.GetUserId();
+ //Set the time
+ download.PostDate = DateTime.Now;
+
+ //Can't forget the changelog. Literally, I almost forgot.
+ download.Changelog = model.Changelog;
+
+ //Set the YT ID
+ download.DevUpdateId = model.DevUpdateId;
+
+ //Set whether the build is stable
+ download.IsStable = model.IsStable;
+
+ //We're not obsolete.
+ download.Obsolete = false;
+
+ //Now we upload the download.
+
+ string download_dir = "~/Uploads/Releases/";
+ string mapped_dir = Server.MapPath(download_dir);
+ if (!Directory.Exists(mapped_dir))
+ Directory.CreateDirectory(mapped_dir);
+
+ string file_name_d = model.Download.FileName;
+ foreach(var c in file_name_d.ToCharArray())
+ {
+ if (!ApprovedIdChars.Contains(c))
+ file_name_d = file_name_d.Replace(c, '_');
+ }
+ download_dir += file_name_d;
+ mapped_dir = Server.MapPath(download_dir);
+ download.DownloadUrl = download_dir;
+ //Now the download is saved in the DB. Let's get it on the server.
+ model.Download.SaveAs(mapped_dir);
+
+ download_dir = "~/Uploads/Releases/Screenshots/";
+ mapped_dir = Server.MapPath(download_dir);
+ if (!Directory.Exists(mapped_dir))
+ Directory.CreateDirectory(mapped_dir);
+
+ file_name_d = model.Screenshot.FileName;
+ foreach (var c in file_name_d.ToCharArray())
+ {
+ if (!ApprovedIdChars.Contains(c))
+ file_name_d = file_name_d.Replace(c, '_');
+ }
+ download_dir += file_name_d;
+ mapped_dir = Server.MapPath(download_dir);
+ download.ScreenshotUrl = download_dir;
+ model.Screenshot.SaveAs(mapped_dir);
+
+ //Now we just save to the database...
+ db.Downloads.Add(download);
+ db.SaveChanges();
+
+ return RedirectToAction("Releases");
+ }
}
+
+
} \ No newline at end of file