public void RateUser(RateUserFormData formData) { var ratings = _context.Rating.Where(r => r.UserRatedId == formData.UserRatedId).ToList(); Rating rating = new Rating(); rating.Rate = formData.Rate; rating.UserRatedId = formData.UserRatedId; rating.UserRatingId = formData.UserRatingId; if (ratings.Any(x => x.UserRatingId == formData.UserRatingId)) { ratings.First(x => x.UserRatingId == formData.UserRatingId).Rate = formData.Rate; } else { _context.Rating.Add(rating); } _context.SaveChanges(); }
public IActionResult RateUser(RateUserFormData formData) { _userContext.RateUser(formData); return(Ok()); }