Exemplo n.º 1
0
        public void Update(T entity)
        {
            T itemFromDB = Context.Set <T>().FirstOrDefault(t => t.ID == entity.ID);

            if (itemFromDB == null)
            {
                throw new ArgumentException();
            }

            Context.Entry(itemFromDB).State = EntityState.Detached;
            Context.Entry(entity).State     = EntityState.Modified;
            Context.SaveChanges();
        }
        public void UpdateRestaurant(Restaurant item)
        {
            var oldRest = _db.Restaurants.Find(item.ID);

            _db.Entry(oldRest).CurrentValues.SetValues(item);

            //Restaurant restaurant = new Restaurant();
            //var temp = _db.Restaurants.Find(item.ID);
            //restaurant.ID = temp.ID;
            //restaurant.name = temp.name;
            //restaurant.address = temp.address;
            //restaurant.city = temp.city;
            //restaurant.state = temp.state;
            //restaurant.zipCode = temp.zipCode;
            //restaurant.phoneNumber = temp.phoneNumber;
            //restaurant.avgRating = temp.avgRating;
            _db.Restaurants.Remove(oldRest);
            _db.Restaurants.Add(ToData(item));
            _db.SaveChanges();
        }