예제 #1
0
 private static Rating CreateRatingDto(Entities.Rating dbRating)
 => new Rating
 {
     Id          = dbRating.Id,
     RatingScore = dbRating.Score,
     Comment     = dbRating.Comment,
     Date        = dbRating.Date,
     User        = $"{dbRating.User.FirstName} {dbRating.User.LastName}".Trim()
 };
예제 #2
0
        public async Task <NewRating> RateAsync(Guid restaurantId, double score, string comment)
        {
            // Saves the new rating to the database.
            var dbRating = new Entities.Rating
            {
                RestaurantId = restaurantId,
                Score        = score,
                Comment      = comment,
                Date         = DateTime.UtcNow,
                UserId       = UserId.Value
            };

            DataContext.Insert(dbRating);
            await DataContext.SaveAsync();

            // Retrieves the new average rating for the restaurant.
            var averageScore = await DataContext.GetData <Entities.Rating>().Where(r => r.RestaurantId == restaurantId).AverageAsync(r => r.Score);

            var result = new NewRating(restaurantId, Math.Round(averageScore, 2));

            return(result);
        }