public async Task <ActionResult> Update(RecipeUpdateInputModel input) { try { await this.recipesService.UpdateAsync(input.Id, input.Title, input.Content, input.CategoryName, input.CookingTime, input.PreparationTime, input.Portions, input.Ingredients, input.Picture); return(this.Ok(new { Message = Messages.SuccessfullyUpdated, })); } catch (Exception) { return(this.BadRequest(new BadRequestViewModel { Message = Messages.UnknownError, })); } }
public async Task <ActionResult> Update(RecipeUpdateInputModel input) { var isTitleAlreadyExisting = await this.recipesService.IsTitleAlreadyExistingAsync(input.Title); if (isTitleAlreadyExisting) { var existingRecipeId = await this.recipesService.GetIdByTitleAsync(input.Title); if (existingRecipeId != input.Id) { return(this.BadRequest(new BadRequestViewModel { Message = Messages.Error.AlreadyExistsRecipe, })); } } try { var ingredients = PrepareIngredients(input.Ingredients); await this.recipesService.UpdateAsync(input.Id, input.Title, input.Content, input.CategoryName, input.CookingTime, input.PreparationTime, input.Portions, ingredients, input.Picture); return(this.Ok(new { Message = Messages.Success.Updated, })); } catch (Exception) { return(this.BadRequest(new BadRequestViewModel { Message = Messages.Error.Unknown, })); } }