disqualification

This commit is contained in:
Michael 2017-05-21 09:53:59 -04:00
parent 746cb59f56
commit ba7bfaabc5
4 changed files with 74 additions and 0 deletions

View file

@ -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}"".
<strong>Reason:</strong> {e.DisqualifiedReason}");
return RedirectToAction("ViewSubmission", new { id = model.Entry });
}
public ActionResult RemoveVote(string id)
{
string uid = User.Identity.GetUserId();

View file

@ -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; }

View file

@ -974,6 +974,7 @@
<Content Include="Views\Contests\CreateContest.cshtml" />
<Content Include="Views\Contests\SubmitEntry.cshtml" />
<Content Include="Views\Contests\ViewSubmission.cshtml" />
<Content Include="Views\Contests\Disqualify.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />

View file

@ -0,0 +1,30 @@
@model Project_Unite.Models.DisqualifySubmissionViewModel
@{
ViewBag.Title = "Disqualify contest submission";
}
<h2>Disqualify contest submission</h2>
<p>Are you sure you want to disqualify this entry?</p>
<div class="panel panel-warning">
<div class="panel-body">
<p><strong>Warning!</strong><br/>You cannot reverse this. Once the entry is disqualified, there's no re-qualifying it.</p>
</div>
</div>
@using (Html.BeginForm())
{
@Html.ValidationSummary()
@Html.AntiForgeryToken()
@Html.HiddenFor(Model=>Model.Entry)
<dl>
<dt>Disqualification reason:</dt>
<dd>Why did you disqualify this submission? @Html.TextBoxFor(Model=>Model.Reason, new { @class = "form-control" })</dd>
</dl>
<hr/>
<input type="submit" value="Disqualify" class="btn btn-default" />
<a href="#" onclick="window.history.back()" class="btn btn-default">Go back</a>
}