public async Task <IHttpActionResult> Post(Dish dish) { try { if (ModelState.IsValid) { var dishToUpdate = _repo.GetDishById(dish.DishId).Result; if (dishToUpdate != null) { dishToUpdate.DishName = dish.DishName; dishToUpdate.CategoryId = dish.CategoryId; dishToUpdate.Active = dish.Active; dishToUpdate.Price = dish.Price; if (_repo.SaveChanges()) { return(Ok(dishToUpdate)); } } else { _repo.AddDish(dish); if (await _repo.SaveChangesAsync()) { return(Created("GetDishes", dish)); } } } } catch (Exception ex) { return(BadRequest(ex.Message)); } return(BadRequest()); }