From e8b18cbf92db1537d9dd4e864ef848383a4ec65a Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 6 Apr 2017 17:51:38 -0400 Subject: [PATCH] Make release screenshots optional. --- .../Controllers/DeveloperController.cs | 29 ++++++++++--------- Project-Unite/Models/Download.cs | 1 - .../Views/Download/ViewRelease.cshtml | 3 ++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Project-Unite/Controllers/DeveloperController.cs b/Project-Unite/Controllers/DeveloperController.cs index 9e2921b..da0022e 100644 --- a/Project-Unite/Controllers/DeveloperController.cs +++ b/Project-Unite/Controllers/DeveloperController.cs @@ -145,21 +145,24 @@ public ActionResult AddRelease(PostDownloadViewModel model) //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.ToLower(); ; - foreach (var c in file_name_d.ToCharArray()) + if (model.Screenshot != null) { - if (!ApprovedIdChars.Contains(c)) - file_name_d = file_name_d.Replace(c, '_'); + 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.ToLower(); ; + 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.Remove(0, 1); + model.Screenshot.SaveAs(mapped_dir); } - download_dir += file_name_d; - mapped_dir = Server.MapPath(download_dir); - download.ScreenshotUrl = download_dir.Remove(0,1); - model.Screenshot.SaveAs(mapped_dir); //Now we just save to the database... db.Downloads.Add(download); diff --git a/Project-Unite/Models/Download.cs b/Project-Unite/Models/Download.cs index 2216507..69de79e 100644 --- a/Project-Unite/Models/Download.cs +++ b/Project-Unite/Models/Download.cs @@ -45,7 +45,6 @@ public class PostDownloadViewModel [Required(ErrorMessage = "You must name your build!")] public string Name { get; set; } - [Required(ErrorMessage ="A screenshot is necessary for getting users into the game.")] [DataType(DataType.Upload)] public HttpPostedFileBase Screenshot { get; set; } diff --git a/Project-Unite/Views/Download/ViewRelease.cshtml b/Project-Unite/Views/Download/ViewRelease.cshtml index 1ff6df8..56b8453 100644 --- a/Project-Unite/Views/Download/ViewRelease.cshtml +++ b/Project-Unite/Views/Download/ViewRelease.cshtml @@ -24,7 +24,10 @@ } + @if (!string.IsNullOrWhiteSpace(Model.ScreenshotUrl)) + { + } @Html.Markdown(Model.Changelog)