diff options
| author | Michael <[email protected]> | 2017-05-21 09:40:50 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-05-21 09:40:50 -0400 |
| commit | 746cb59f560fff853c5129b1ec3e217543a4de42 (patch) | |
| tree | 5cd498e11cb1502ab8bd2d3f9f33fd51464eb2c1 /Project-Unite/Controllers/ContestsController.cs | |
| parent | a2eed3b184cfacf2319ae259292915a72ddbb839 (diff) | |
| download | project-unite-746cb59f560fff853c5129b1ec3e217543a4de42.tar.gz project-unite-746cb59f560fff853c5129b1ec3e217543a4de42.tar.bz2 project-unite-746cb59f560fff853c5129b1ec3e217543a4de42.zip | |
voting of contest entries
Diffstat (limited to 'Project-Unite/Controllers/ContestsController.cs')
| -rw-r--r-- | Project-Unite/Controllers/ContestsController.cs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Project-Unite/Controllers/ContestsController.cs b/Project-Unite/Controllers/ContestsController.cs index 8cdb229..fd0c39f 100644 --- a/Project-Unite/Controllers/ContestsController.cs +++ b/Project-Unite/Controllers/ContestsController.cs @@ -65,6 +65,84 @@ namespace Project_Unite.Controllers return View(model); } + public ActionResult Upvote(string id) + { + string uid = User.Identity.GetUserId(); + var db = new ApplicationDbContext(); + var s = db.ContestEntries.FirstOrDefault(x => x.Id == id); + if (s == null) + return new HttpStatusCodeResult(404); + var like = db.Likes.FirstOrDefault(x => x.User == uid && x.Topic == id); + if (like != null) + { + if (like.IsDislike == false) + return new HttpStatusCodeResult(403); + else + like.IsDislike = false; + } + else + { + like = new Like(); + like.Id = Guid.NewGuid().ToString(); + like.IsDislike = false; + like.User = uid; + like.Topic = id; + } + db.SaveChanges(); + return RedirectToAction("ViewSubmission", new { id = id }); + + } + + public ActionResult Downvote(string id) + { + string uid = User.Identity.GetUserId(); + var db = new ApplicationDbContext(); + var s = db.ContestEntries.FirstOrDefault(x => x.Id == id); + if (s == null) + return new HttpStatusCodeResult(404); + var like = db.Likes.FirstOrDefault(x => x.User == uid && x.Topic == id); + if (like != null) + { + if (like.IsDislike == true) + return new HttpStatusCodeResult(403); + else + like.IsDislike = true; + } + else + { + like = new Like(); + like.Id = Guid.NewGuid().ToString(); + like.IsDislike = true; + like.User = uid; + like.Topic = id; + } + db.SaveChanges(); + return RedirectToAction("ViewSubmission", new { id = id }); + + } + + public ActionResult RemoveVote(string id) + { + string uid = User.Identity.GetUserId(); + var db = new ApplicationDbContext(); + var s = db.ContestEntries.FirstOrDefault(x => x.Id == id); + if (s == null) + return new HttpStatusCodeResult(404); + var like = db.Likes.FirstOrDefault(x => x.User == uid && x.Topic == id); + if (like != null) + { + db.Likes.Remove(like); + } + else + { + return new HttpStatusCodeResult(403); + } + db.SaveChanges(); + return RedirectToAction("ViewSubmission", new { id = id }); + + } + + [HttpPost] [ValidateAntiForgeryToken] public ActionResult SubmitEntry(SubmitContestEntryViewModel model) |
