diff --git a/Project-Unite/Controllers/ContestsController.cs b/Project-Unite/Controllers/ContestsController.cs index fd0c39f..a99b342 100644 --- a/Project-Unite/Controllers/ContestsController.cs +++ b/Project-Unite/Controllers/ContestsController.cs @@ -121,6 +121,41 @@ public ActionResult Downvote(string id) } + [RequiresAdmin] + public ActionResult Disqualify(string id) + { + var db = new ApplicationDbContext(); + var c = db.ContestEntries.FirstOrDefault(x => x.Id == id); + if (c == null) + return new HttpStatusCodeResult(404); + var model = new DisqualifySubmissionViewModel(); + model.Entry = id; + return View(model); + } + + [RequiresAdmin] + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult Disqualify(DisqualifySubmissionViewModel model) + { + if (!ModelState.IsValid) + return View(model); + var db = new ApplicationDbContext(); + var e = db.ContestEntries.FirstOrDefault(x => x.Id == model.Entry); + if (e == null) + return new HttpStatusCodeResult(404); + e.Disqualified = true; + e.DisqualifiedBy = User.Identity.GetUserId(); + e.DisqualifiedReason = model.Reason; + db.SaveChanges(); + + NotificationDaemon.NotifyUser(User.Identity.GetUserId(), e.AuthorId, "Submission disqualified.", $@"We have disqualified your contest submission ""{e.Name}"". + +Reason: {e.DisqualifiedReason}"); + + return RedirectToAction("ViewSubmission", new { id = model.Entry }); + } + public ActionResult RemoveVote(string id) { string uid = User.Identity.GetUserId(); diff --git a/Project-Unite/Models/ContestModels.cs b/Project-Unite/Models/ContestModels.cs index ef2cf85..9316d14 100644 --- a/Project-Unite/Models/ContestModels.cs +++ b/Project-Unite/Models/ContestModels.cs @@ -65,6 +65,14 @@ public ContestEntry[] Entries } + public class DisqualifySubmissionViewModel + { + public string Entry { get; set; } + + [Required(AllowEmptyStrings =false, ErrorMessage ="You must provide a reason.")] + public string Reason { get; set; } + } + public class ContestEntry { public string Id { get; set; } diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj index c8e3dd6..d2c2ee8 100644 --- a/Project-Unite/Project-Unite.csproj +++ b/Project-Unite/Project-Unite.csproj @@ -974,6 +974,7 @@ + diff --git a/Project-Unite/Views/Contests/Disqualify.cshtml b/Project-Unite/Views/Contests/Disqualify.cshtml new file mode 100644 index 0000000..f59a126 --- /dev/null +++ b/Project-Unite/Views/Contests/Disqualify.cshtml @@ -0,0 +1,30 @@ +@model Project_Unite.Models.DisqualifySubmissionViewModel +@{ + ViewBag.Title = "Disqualify contest submission"; +} + +

Disqualify contest submission

+ +

Are you sure you want to disqualify this entry?

+ +
+
+

Warning!
You cannot reverse this. Once the entry is disqualified, there's no re-qualifying it.

+
+
+ +@using (Html.BeginForm()) +{ + @Html.ValidationSummary() + @Html.AntiForgeryToken() + @Html.HiddenFor(Model=>Model.Entry) + +
+
Disqualification reason:
+
Why did you disqualify this submission? @Html.TextBoxFor(Model=>Model.Reason, new { @class = "form-control" })
+
+ +
+ + Go back +} \ No newline at end of file