private async Task UpdateMealInRepository(MealAddUpdateModel mealAddUpdateModel) { var mealImage = mealsImagesRepository.GetMealImage(mealAddUpdateModel.Meal.EntityId); mealAddUpdateModel.Meal.Image.MealId = mealAddUpdateModel.Meal.MealId; mealsImagesRepository.Remove(mealImage); mealImage = mealAddUpdateModel.Meal.Image; mealAddUpdateModel.Meal.Image = null; mealsRepository.Update(mealAddUpdateModel.Meal); await mealsImagesRepository.AddAsync(mealImage); }
public async Task <IActionResult> UpdateMeal([FromBody] MealAddUpdateModel mealAddUpdateModel) { try { if (!IsMealModifyingAllow(mealAddUpdateModel.AccountId, mealAddUpdateModel.Meal)) { return(BadRequest(noRightsForModifying)); } await UpdateMealInRepository(mealAddUpdateModel); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }