diff --git a/Project-Unite/Controllers/ContestsController.cs b/Project-Unite/Controllers/ContestsController.cs new file mode 100644 index 0000000..8439008 --- /dev/null +++ b/Project-Unite/Controllers/ContestsController.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using Project_Unite.Models; + +namespace Project_Unite.Controllers +{ + public class ContestsController : Controller + { + // GET: Contests + public ActionResult Index() + { + var model = new ApplicationDbContext().Contests.ToArray(); + return View(model); + } + } +} \ No newline at end of file diff --git a/Project-Unite/Models/ContestModels.cs b/Project-Unite/Models/ContestModels.cs new file mode 100644 index 0000000..80533c1 --- /dev/null +++ b/Project-Unite/Models/ContestModels.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Project_Unite.Models +{ + public class Contest + { + public string Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public DateTime StartedAt { get; set; } + public DateTime EndsAt { get; set; } + public string VideoId { get; set; } + public long CodepointReward1st { get; set; } + public long CodepointReward2nd { get; set; } + public long CodepointReward3rd { get; set; } + + + public bool IsEnded + { + get + { + return DateTime.Now >= EndsAt; + } + } + + public ContestEntry[] Entries + { + get + { + var db = new ApplicationDbContext(); + return db.ContestEntries.Where(x => x.ContestId == this.Id).ToArray(); + } + } + + } + + public class ContestEntry + { + public string Id { get; set; } + public string AuthorId { get; set; } + public string ContestId { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public string VideoId { get; set; } + public string DownloadURL { get; set; } + public DateTime PostedAt { get; set; } + public bool Disqualified { get; set; } + + public Like[] Downvotes + { + get + { + var db = new ApplicationDbContext(); + return db.Likes.Where(x => x.Topic == this.Id && x.IsDislike).ToArray(); + } + } + + public Like[] Upvotes + { + get + { + var db = new ApplicationDbContext(); + return db.Likes.Where(x => x.Topic == this.Id && !x.IsDislike).ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Project-Unite/Models/IdentityModels.cs b/Project-Unite/Models/IdentityModels.cs index 68c21fe..8959a8e 100644 --- a/Project-Unite/Models/IdentityModels.cs +++ b/Project-Unite/Models/IdentityModels.cs @@ -244,6 +244,8 @@ namespace Project_Unite.Models return new ApplicationDbContext(); } + public DbSet Contests { get; set; } + public DbSet ContestEntries { get; set; } public DbSet Bugs { get; set; } public DbSet BugTags { get; set; } public DbSet BlogPosts { get; set; } diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj index 6fcf989..2d40155 100644 --- a/Project-Unite/Project-Unite.csproj +++ b/Project-Unite/Project-Unite.csproj @@ -623,6 +623,7 @@ + @@ -809,6 +810,7 @@ + @@ -965,6 +967,7 @@ + diff --git a/Project-Unite/Views/Contests/Index.cshtml b/Project-Unite/Views/Contests/Index.cshtml new file mode 100644 index 0000000..b234340 --- /dev/null +++ b/Project-Unite/Views/Contests/Index.cshtml @@ -0,0 +1,130 @@ +@model IEnumerable +@{ + ViewBag.Title = "Contests"; + var open = Model.Where(x => x.IsEnded == false).OrderByDescending(x=>x.StartedAt); + var closed = Model.Where(x => x.IsEnded == true).OrderByDescending(x => x.StartedAt); + +} + +

Contests

+ +

ShiftOS may have a team of developers behind it, but we like getting you guys, the community, involved as well. Contests are a fun and competitive way to get involved with the development of ShiftOS, whether it be through coding, art or anything else!

+ +

Below is a list of all contests.

+ + + +@if (Request.IsAuthenticated) +{ + if (User.Identity.IsDeveloper()) + { + + } +} + +
+ +
+
+

Open contests

+

Below is a list of all open contests.

+ +
+
Contest
+
Actions
+
+ @if(open.Count() < 1) + { +
+
+

Sadly, no contests are open at this time. Please check back later!

+
+
+ } + else + { + foreach(var c in open) + { +
+
+ @Html.ActionLink(c.Name, "ViewContest", "Contests", new { id=c.Id}, null)
+

Started at @c.StartedAt • Ends at @c.EndsAt

+

Rewards: Gold: @c.CodepointReward1st CPGold: @c.CodepointReward2nd CPBronze: @c.CodepointReward3rd CP

+
+
+ @if (!string.IsNullOrWhiteSpace(c.VideoId)) + { + Watch video + } + @if (Request.IsAuthenticated) + { + if (User.Identity.IsDeveloper()) + { + End contest + } + } +
+
+ + } + } + +
+
+

Closed contests

+

These contests have been closed and you can no longer enter to win them.

+ +
+
Contest
+
Actions
+
+ @if (closed.Count() < 1) + { +
+
+

No closed contests yet, maybe there's an open one?

+
+
+ } + else + { + foreach (var c in closed) + { +
+
+ @Html.ActionLink(c.Name, "ViewContest", "Contests", new { id = c.Id }, null)
+

Started at @c.StartedAt • Ends at @c.EndsAt

+

Rewards: Gold: @c.CodepointReward1st CPGold: @c.CodepointReward2nd CPBronze: @c.CodepointReward3rd CP

+
+
+ @if (!string.IsNullOrWhiteSpace(c.VideoId)) + { + Watch video + } +
+
+ + } + } + +
+
+
\ No newline at end of file