public void AddOrChangeRating(int gossipId, int ratingType) { var rating = new Rating(); rating.authorId = HttpContext.Current.User.Identity.GetUserId(); rating.gossipId = gossipId; rating.RatingType = ratingType; var findRating = (from r in db.Ratings where r.authorId == rating.authorId && r.gossipId == rating.gossipId select r).SingleOrDefault(); if(findRating == null) { db.Ratings.Add(rating); db.SaveChanges(); } else { findRating.RatingType = rating.RatingType; db.SaveChanges(); } }
public ActionResult AddRating(Rating rating) { var ratingService = new RatingService(); ratingService.AddOrChangeRating(rating.gossipId, rating.RatingType); return Json(new { success = true }); }