public double?GetAverageGrade() { if (Reviews.Any()) { return(Math.Round(Reviews.Average(g => g.Grade), 1)); } else { return(null); } }
public GameDetailsViewModel(Game game) { var gameService = new DbService(); Game = game; Reviews = gameService.GetReviews(game.Id); Platforms = gameService.GetPlatforms(game.Platforms); if (Reviews.Any()) { AverageRating = gameService.GetAverageRating(game.Id); } }
public GameItemViewModel(Game game, ApplicationDbContext context) { var gameService = new DbService(); Game = game; PlatformImageUrls = Game.Platforms .Select(platform => context.Platforms.SingleOrDefault(p => p.ApiPlatformId == platform)) .Where(platformToAdd => platformToAdd != null) .Select(p => p.ImageAddress) .ToList(); Reviews = gameService.GetReviews(game.Id); if (Reviews.Any()) { AverageRating = gameService.GetAverageRating(game.Id); } }
public virtual bool AddReview(Review review) { if (Reviews == null) { Reviews = new Collection <Review>(); } if (Reviews.Any(x => x.User.Id == review.User.Id)) { return(false); } if (review.Like) { Likes++; } else { Dislikes++; } Reviews.Add(review); return(true); }