public Review Create(EditReviewViewModel editVm) { Review review = null; if (editVm.GetType() == typeof(EditRestaurantReviewViewModel)) { review = new RestaurantReview { Body = editVm.Body, Rating = editVm.Rating, ReviewerName = editVm.ReviewerName, RestaurantId = editVm.HorecaId }; } else if (editVm.GetType() == typeof(EditCafeReviewViewModel)) { review = new CafeReview { Body = editVm.Body, Rating = editVm.Rating, ReviewerName = editVm.ReviewerName, CafeId = editVm.HorecaId }; } return(review); }
public async Task <CafeReview> AddAsync(CafeReview review) { _context.CafeReviews.Add(review); await _context.SaveChangesAsync(); return(review); }
public async Task UpdateAsync(CafeReview review) { //Review might not be tracked (attached) by the entity framework -> get original from DB and copy values var original = _context.CafeReviews.Find(review.Id); var entry = _context.Entry(original); entry.CurrentValues.SetValues(review); await _context.SaveChangesAsync(); }