private void SeedRatings() { if (!Ratings.Any() || _context.Ratings.Any()) { return; } _context.Ratings.AddRange(Ratings); }
public double GetAverageRating() { if (!Ratings.Any()) { return(0); } return(Ratings.Average(r => r.Rating)); }
public void AddRating(User user, decimal value, string comment) { if (Ratings == null) { Ratings = new List <Rating>(); } if (Ratings.Any(r => r.UserId == user.Id)) { throw SheaftException.Validation("Vous avez déjà noté ce produit."); } Ratings.Add(new Rating(Guid.NewGuid(), value, user, comment)); RefreshRatings(); }
private void RefreshRatings() { Rating = Ratings.Any() ? Ratings.Average(r => r.Value) : (decimal?)null; RatingsCount = Ratings.Count; }
private bool HasUserWrittenRating(int userId) { return(Ratings.Any(rat => rat.UserId == userId)); }