public void CreateDish(Dish dish) { using (var context = new LunchDbContext()) { context.Dishes.Add(dish); context.SaveChanges(); } }
public void UpdateDish(Dish dish) { using (var context = new LunchDbContext()) { var original = context.Dishes.Find(dish.Id); if (original == null) { throw new InvalidOperationException(); } context.Entry(original).CurrentValues.SetValues(dish); context.SaveChanges(); } }