public async Task <RestaurantHall> GetRestaurantHallById(int restaurntHallId) { RestaurantHall result = await dbContext.RestaurantHalls .Where(x => x.Id == restaurntHallId) .FirstOrDefaultAsync(); return(result); }
public async Task <RestaurantHall> DeleteRestaurantHall(int restaurantHallId) { RestaurantHall dbEntry = dbContext.RestaurantHalls.Find(restaurantHallId); if (dbEntry == null) { throw new InvalidOperationException("Restaurant hall not found"); } dbContext.RestaurantHalls.Remove(dbEntry); await dbContext.SaveChangesAsync(); return(dbEntry); }
public async Task <int> SaveRestaurantHall(RestaurantHall restaurantHall) { if (restaurantHall == null) { throw new ArgumentNullException(nameof(restaurantHall), "Parameter is null"); } if (restaurantHall.Id == 0) { dbContext.RestaurantHalls.Add(restaurantHall); } else { RestaurantHall dbEntry = dbContext.RestaurantHalls.Find(restaurantHall.Id); if (dbEntry == null) { throw new InvalidOperationException("Restaurant hall not found"); } dbEntry.Name = restaurantHall.Name; } await dbContext.SaveChangesAsync(); return(restaurantHall.Id); }