diff options
| author | Michael <[email protected]> | 2017-05-20 20:06:42 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-05-20 20:06:42 -0400 |
| commit | e37b3223dbcd7957bbe113c5cb9a5698205fb722 (patch) | |
| tree | bb6abeb3f6cf408b69745331fd09bb7fcca0f48e /Project-Unite/Controllers/ContestsController.cs | |
| parent | b0c200196e5506b456895f9ee0c4c8dcd547fdb7 (diff) | |
| download | project-unite-e37b3223dbcd7957bbe113c5cb9a5698205fb722.tar.gz project-unite-e37b3223dbcd7957bbe113c5cb9a5698205fb722.tar.bz2 project-unite-e37b3223dbcd7957bbe113c5cb9a5698205fb722.zip | |
create contest page
Diffstat (limited to 'Project-Unite/Controllers/ContestsController.cs')
| -rw-r--r-- | Project-Unite/Controllers/ContestsController.cs | 53 |
1 files changed, 53 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 |
