mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 17:22:15 +00:00
voting of contest entries
This commit is contained in:
parent
a2eed3b184
commit
746cb59f56
1 changed files with 78 additions and 0 deletions
|
@ -65,6 +65,84 @@ public ActionResult SubmitEntry(string id)
|
||||||
return View(model);
|
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]
|
[HttpPost]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public ActionResult SubmitEntry(SubmitContestEntryViewModel model)
|
public ActionResult SubmitEntry(SubmitContestEntryViewModel model)
|
||||||
|
|
Loading…
Reference in a new issue