public Restaurant Put(Restaurant restaurant)
        {
            var original = _context.Restaurants.Find(restaurant.Id);
            var entry    = _context.Entry(original);

            entry.CurrentValues.SetValues(restaurant);
            _context.SaveChanges();
            return(restaurant);
        }
Exemple #2
0
        public Restaurant Update(Restaurant restaurant)
        {
            var original = _context.Restaurants.First(r => r.Id == restaurant.Id);
            var entry    = _context.Entry(original);

            entry.CurrentValues.SetValues(restaurant);
            _context.SaveChanges();
            return(restaurant);
        }
        public async Task UpdateAsync(RestaurantReview review)
        {
            //Review might not be tracked (attached) by the entity framework -> get original from DB and copy values
            var original = _context.RestaurantReviews.Find(review.Id);
            var entry    = _context.Entry(original);

            entry.CurrentValues.SetValues(review);

            await _context.SaveChangesAsync();
        }
        public async Task <Review> PutAsync(Review review)
        {
            var original = _context.Reviews.Find(review.Id);
            var entry    = _context.Entry(original);

            entry.CurrentValues.SetValues(review);

            await _context.SaveChangesAsync();

            return(review);
        }
Exemple #5
0
        public T Update(T updated, int key)
        {
            if (updated == null)
            {
                return(null);
            }

            T existing = _context.Set <T>().Find(key);

            if (existing != null)
            {
                _context.Entry(existing).CurrentValues.SetValues(updated);
                _context.SaveChanges();
            }
            return(existing);
        }