/// <summary> /// Add a review and associate it with a restaurant. /// </summary> /// <param name="review">The review</param> /// <param name="restaurant">The restaurant</param> public void AddReview(Library.Models.Review review, Library.Models.Restaurant restaurant = null) { if (restaurant.Id != 0) { s_logger.Warn($"Review to be added has an ID ({review.Id}) already: ignoring."); } s_logger.Info($"Adding review to restaurant with ID {restaurant.Id}"); if (restaurant != null) { // get the db's version of that restaurant // (can't use Find with Include) Restaurant restaurantEntity = _dbContext.Restaurant .Include(r => r.Review).First(r => r.Id == restaurant.Id); Review newEntity = Mapper.Map(review); restaurantEntity.Review.Add(newEntity); // also, modify the parameters restaurant.Reviews.Add(review); } else { Review newEntity = Mapper.Map(review); _dbContext.Add(newEntity); } }
/// <summary> /// Update a review. /// </summary> /// <param name="review">The review with changed values</param> public void UpdateReview(Library.Models.Review review) { s_logger.Info($"Updating review with ID {review.Id}"); Review currentEntity = _dbContext.Review.Find(review.Id); Review newEntity = Mapper.Map(review); _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity); }
/// <summary> /// Maps a review business model to an entity for Entity Framework, /// not including the restaurant. /// </summary> /// <param name="review">The review business model.</param> /// <returns>The review entity.</returns> public static Entities.Review Map(Library.Models.Review review) { return(new Entities.Review { Id = review.Id, ReviewerName = review.ReviewerName, Score = review.Score ?? throw new ArgumentException("review score cannot be null.", nameof(review)), Text = review.Text });
public static Entities.Review Map(Library.Models.Review review) { return(new Entities.Review { Id = review.Id, UserId = review.UserId, RecipeId = review.RecipeId, Rating = review.Rating, Comment = review.Comment }); }
public static Entities.Review Map(Library.Models.Review review) => new Entities.Review