예제 #1
0
        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);
        }
예제 #2
0
        public async Task <CafeReview> AddAsync(CafeReview review)
        {
            _context.CafeReviews.Add(review);

            await _context.SaveChangesAsync();

            return(review);
        }
예제 #3
0
        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();
        }