From b0c200196e5506b456895f9ee0c4c8dcd547fdb7 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 20 May 2017 19:42:32 -0400 Subject: [PATCH] viewcontest page --- .../Controllers/ContestsController.cs | 11 +++ Project-Unite/Project-Unite.csproj | 1 + .../Views/Contests/ViewContest.cshtml | 94 +++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 Project-Unite/Views/Contests/ViewContest.cshtml diff --git a/Project-Unite/Controllers/ContestsController.cs b/Project-Unite/Controllers/ContestsController.cs index 8439008..4b41f91 100644 --- a/Project-Unite/Controllers/ContestsController.cs +++ b/Project-Unite/Controllers/ContestsController.cs @@ -7,13 +7,24 @@ namespace Project_Unite.Controllers { + [Authorize] public class ContestsController : Controller { + [AllowAnonymous] // GET: Contests public ActionResult Index() { var model = new ApplicationDbContext().Contests.ToArray(); return View(model); } + + public ActionResult ViewContest(string id) + { + var db = new ApplicationDbContext(); + var c = db.Contests.FirstOrDefault(x => x.Id == id); + if (c == null) + return new HttpStatusCodeResult(404); + return View(c); + } } } \ No newline at end of file diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj index 2d40155..e9c5b83 100644 --- a/Project-Unite/Project-Unite.csproj +++ b/Project-Unite/Project-Unite.csproj @@ -968,6 +968,7 @@ + diff --git a/Project-Unite/Views/Contests/ViewContest.cshtml b/Project-Unite/Views/Contests/ViewContest.cshtml new file mode 100644 index 0000000..a78cdbc --- /dev/null +++ b/Project-Unite/Views/Contests/ViewContest.cshtml @@ -0,0 +1,94 @@ +@model Project_Unite.Models.Contest +@{ + ViewBag.Title = "Contest: " + Model.Name; +} + +

@Model.Name

+ + + + +
+
+ @if (!string.IsNullOrWhiteSpace(Model.VideoId)) + { + + + if (Model.IsEnded) + { +

This contest has ended on @Model.EndsAt

+ } + else + { +

This contest is open - and will be closed at @Model.EndsAt

+ } + +

@Html.Markdown(Model.Description)

+ +

Contest rewards:

+ +
+
Gold:
@Model.CodepointReward1st Codepoints
+
Silver:
+
@Model.CodepointReward2nd Codepoints
+
Bronze:
+
@Model.CodepointReward3rd Codepoints
+
+ } +
+
+

Want to win this contest?

+ + @if (Model.IsEnded) + { +

Unfortunately, this contest has ended and you cannot submit an entry. Perhaps there's another contest still going?

+ } + else + { +

Good news! This contest is still open. Hurry and submit your entry!

+ + Go, go, go! Submit an entry! + } + +

Current winners:

+ + @{ + var toptobottom = Model.Entries.OrderByDescending(x => (x.Upvotes.Length - x.Downvotes.Length)); + + } + + @if(toptobottom.Count() >= 3) + { + var first = toptobottom.ToArray()[0]; + var second = toptobottom.ToArray()[1]; + var third = toptobottom.ToArray()[2]; + +
+
First place:
+
@first.Name by @Html.UserLink(first.AuthorId)
+
Second place:
+
@second.Name by @Html.UserLink(second.AuthorId)
+
Third place:
+
@third.Name by @Html.UserLink(third.AuthorId)
+
+ } + else + { +

Not enough people have entered into this contest.

+ } + +
+
+