public ActionResult VoteForBookmark(Bookmark bookmark) { if (bookmark == null) { return this.HttpNotFound(); } var vote = new Vote { BookmarkId = bookmark.Id, UserId = this.UserProfille.Id, UserVote = 1 }; this.Data.Votes.Add(vote); bookmark.VotesResult = bookmark.VotesResult + 1; this.Data.SaveChanges(); return this.Content(bookmark.VotesResult.ToString()); }
public ActionResult Vote(int id) { var bookmark = this.Data.Bookmarks.All().FirstOrDefault(x => x.Id == id); if (bookmark != null) { var userId = this.User.Identity.GetUserId(); var vote = new Vote { BookmarkId = id, UserId = userId, Value = 1 }; this.Data.Votes.Add(vote); this.Data.SaveChanges(); var votesCount = bookmark.Votes.Sum(x => x.Value); return this.Json(votesCount, JsonRequestBehavior.AllowGet); } return this.Json("Error"); }