public ActionResult Rate(string userName, int photoId, int rating, string photoName, int page = 1) { UserViewModel currentUser = userService.GetUserEntityByLogin(User.Identity.Name).ToMvcUser(); RatingViewModel userRating = ratingService.GetUserRatingOfPhoto(currentUser.Id, photoId).ToMvcRating(); if (userRating == null) { userRating = new RatingViewModel { PhotoId = photoId, UserId = currentUser.Id, UserRate = rating }; ratingService.CreateEntity(userRating.ToBllRating()); } else { userRating.UserRate = rating; ratingService.UpdateEntity(userRating.ToBllRating()); } return(RedirectToAction("Photos", "Photo", new { userName = userName, page = page, currentPhotoId = photoId, photoName = photoName })); }
public ActionResult Rate(int value, int titleId, int userId) { try { lock (ratingService) { if (!ratingService.CheckIfRatedByUser(userId, titleId)) { lock (ratingService) { ratingService.CreateEntity(new RatingEntity { TextDescId = titleId, UserId = userId, Value = value }); } } else { lock (ratingService) { var entity = ratingService.GetRateByUserAndTitleId(userId, titleId); entity.Value = value; ratingService.UpdateEntity(entity); } } var actual = Math.Round(ratingService.GetAverageRatingForTitle(titleId), 2); return(Json(new { ActualValue = actual })); } } catch { return(RedirectToAction("Internal", "Error")); } }