public async Task <DishContaining> DeleteDishContaining(int dishContainingId) { DishContaining dbEntry = dbContext.DishContainings.Find(dishContainingId); if (dbEntry == null) { throw new InvalidOperationException("Dish containing not found"); } dbContext.DishContainings.Remove(dbEntry); await dbContext.SaveChangesAsync(); return(dbEntry); }
public async Task <int> SaveDishContaining(DishContaining dishContaining) { if (dishContaining == null) { throw new ArgumentNullException(nameof(dishContaining), "Parameter is null"); } if (dishContaining.Id == 0) { dbContext.DishContainings.Add(dishContaining); } else { DishContaining dbEntry = dbContext.DishContainings.Find(dishContaining.Id); if (dbEntry == null) { throw new InvalidOperationException("Dish containing not found"); } dbEntry.Quantity = dishContaining.Quantity; } await dbContext.SaveChangesAsync(); return(dishContaining.Id); }