public bool CreateCoffee(CoffeeResourceModel coffeeRM) { try { var coffee = new Coffee() { Name = coffeeRM.Name }; this._coffeeRepo.CreateCoffee(coffee); return(true); } catch (Exception) { return(false); } }
public CoffeeResourceModel GetCoffeeDetails(int id) { CoffeeResourceModel rm = new CoffeeResourceModel(); var coffee = this._coffeeRepo.GetCoffee(id); var userRatingIds = this._coffeeUserRatingRepo.GetUserRatingsForCoffee(id); foreach (var userRatingsId in userRatingIds) { var userRating = this._userRatingRepo.GetUserRating(userRatingsId); rm.UserRatings.Add(new ResourceModels.Rating.UserRatingResourceModel() { Id = userRating.Id, Comment = userRating.Comment, RatingValue = userRating.RatingValue }); } rm.AverageRating = rm.UserRatings.Sum(x => x.RatingValue) / rm.UserRatings.Count; return(rm); }