summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Project-Unite/Controllers/ContestsController.cs53
-rw-r--r--Project-Unite/Models/ContestModels.cs49
-rw-r--r--Project-Unite/Project-Unite.csproj1
-rw-r--r--Project-Unite/Views/Contests/CreateContest.cshtml38
4 files changed, 141 insertions, 0 deletions
diff --git a/Project-Unite/Controllers/ContestsController.cs b/Project-Unite/Controllers/ContestsController.cs
index 4b41f91..143f885 100644
--- a/Project-Unite/Controllers/ContestsController.cs
+++ b/Project-Unite/Controllers/ContestsController.cs
@@ -26,5 +26,58 @@ namespace Project_Unite.Controllers
return new HttpStatusCodeResult(404);
return View(c);
}
+
+ [RequiresAdmin]
+ public ActionResult CloseContest(string id)
+ {
+ var db = new ApplicationDbContext();
+ var c = db.Contests.FirstOrDefault(x => x.Id == id);
+ if (c == null)
+ return new HttpStatusCodeResult(404);
+ c.EndsAt = DateTime.Now;
+ db.SaveChanges();
+ return RedirectToAction("Index");
+
+ }
+
+ [RequiresAdmin]
+ public ActionResult CreateContest()
+ {
+ var model = new CreateContestViewModel();
+ return View(model);
+ }
+
+ [RequiresAdmin]
+ [HttpPost]
+ [ValidateAntiForgeryToken]
+ public ActionResult CreateContest(CreateContestViewModel model)
+ {
+ if (!ModelState.IsValid)
+ return View(model);
+
+ var db = new ApplicationDbContext();
+
+ string allowed = "abcdefghijklmnopqrstuvwxyz_0123456789";
+
+ var c = new Contest();
+
+ c.Name = model.Name;
+ c.Description = model.Description;
+ c.StartedAt = DateTime.Now;
+ c.EndsAt = model.EndDate;
+ c.VideoId = model.VideoId;
+ string id = c.Name.ToLower() + "_" + db.Contests.Count();
+ foreach (char ch in id.ToCharArray())
+ if (!allowed.Contains(ch))
+ id = id.Replace(ch, '_');
+ c.Id = id;
+ c.CodepointReward1st = model.GoldReward;
+ c.CodepointReward2nd = model.SilverReward;
+ c.CodepointReward3rd = model.BronzeReward;
+ db.Contests.Add(c);
+ db.SaveChanges();
+
+ return RedirectToAction("ViewContest", new { id = c.Id });
+ }
}
} \ No newline at end of file
diff --git a/Project-Unite/Models/ContestModels.cs b/Project-Unite/Models/ContestModels.cs
index 80533c1..6af7aca 100644
--- a/Project-Unite/Models/ContestModels.cs
+++ b/Project-Unite/Models/ContestModels.cs
@@ -2,9 +2,58 @@
using System.Collections.Generic;
using System.Linq;
using System.Web;
+using System.ComponentModel.DataAnnotations;
+using System.Web.Mvc;
namespace Project_Unite.Models
{
+ public class CreateContestViewModel
+ {
+ [Required(AllowEmptyStrings =false, ErrorMessage ="You must name your contest!")]
+ [MinLength(5, ErrorMessage ="Your contest name must contain at least 5 characters.")]
+ [MaxLength(35, ErrorMessage ="Your contest's name must not have more than 35 characters!")]
+ public string Name { get; set; }
+
+ public string ContestId { get; set; }
+
+ public List<SelectListItem> Contests
+ {
+ get
+ {
+ var db = new ApplicationDbContext();
+ var list = new List<SelectListItem>();
+ foreach (var c in db.Contests.Where(x => x.IsEnded == false).OrderByDescending(x => x.StartedAt).ToArray())
+ {
+ list.Add(new SelectListItem
+ {
+ Value = c.Id,
+ Text = c.Name
+ });
+ }
+ return list;
+ }
+ }
+
+ [AllowHtml]
+ [Required(AllowEmptyStrings = false, ErrorMessage = "Please describe your contest!")]
+ public string Description { get; set; }
+
+ [Required(ErrorMessage ="Please set an end date for the contest.")]
+ public DateTime EndDate { get; set; }
+
+ [Required(ErrorMessage ="Please specify a Codepoint reward for the gold winner.")]
+ public long GoldReward { get; set; }
+
+ [Required(ErrorMessage = "Please specify a Codepoint reward for the silver winner.")]
+ public long SilverReward { get; set; }
+
+ [Required(ErrorMessage = "Please specify a Codepoint reward for the bronze winner.")]
+ public long BronzeReward { get; set; }
+
+
+ public string VideoId { get; set; }
+ }
+
public class Contest
{
public string Id { get; set; }
diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj
index e9c5b83..11608fd 100644
--- a/Project-Unite/Project-Unite.csproj
+++ b/Project-Unite/Project-Unite.csproj
@@ -969,6 +969,7 @@
<Content Include="Views\Home\SendFeedback.cshtml" />
<Content Include="Views\Contests\Index.cshtml" />
<Content Include="Views\Contests\ViewContest.cshtml" />
+ <Content Include="Views\Contests\CreateContest.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
diff --git a/Project-Unite/Views/Contests/CreateContest.cshtml b/Project-Unite/Views/Contests/CreateContest.cshtml
new file mode 100644
index 0000000..e134312
--- /dev/null
+++ b/Project-Unite/Views/Contests/CreateContest.cshtml
@@ -0,0 +1,38 @@
+@model Project_Unite.Models.CreateContestViewModel
+
+@{
+ ViewBag.Title = "Create contest";
+}
+
+<h2>Create contest</h2>
+
+<p>This page will let you create a ShiftOS community contest.</p>
+<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"
+ integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E="
+ crossorigin="anonymous"></script>
+<script>
+ $('#enddate').datepicker();
+</script>
+
+@using (Html.BeginForm())
+{
+ @Html.AntiForgeryToken()
+
+ <dl>
+ <dt>Contest name:</dt>
+ <dd>@Html.TextBoxFor(Model=>Model.Name, new { @class = "form-control" })</dd>
+ <dt>Contest description</dt>
+ <dd>@Html.TextAreaFor(Model => Model.Description, new { @class = "form-control" })</dd>
+ <dt>Video ID:</dt>
+ <dd>If you have posted a YouTube video for this contest, paste its ID here. @Html.TextBoxFor(Model => Model.VideoId, new { @class = "form-control" })</dd>
+ <dt>Gold reward:</dt>
+ <dd>@Html.EditorFor(Model => Model.GoldReward, new { @class = "form-control" })</dd>
+ <dt>Silver reward:</dt>
+ <dd>@Html.EditorFor(Model => Model.SilverReward, new { @class = "form-control" })</dd>
+ <dt>Bronze reward:</dt>
+ <dd>@Html.EditorFor(Model => Model.BronzeReward, new { @class = "form-control" })</dd>
+ </dl>
+
+ <hr/>
+ <input type="submit" class="btn btn-primary" value="Open the contest!"/>
+} \ No newline at end of file