public IActionResult Update([FromBody] RecipeUpdateRequest request) { if (!ModelState.IsValid) { return(Ok(ModelState)); } var response = new BaseResponse <bool>(); var item = recipeRepo.GetById(request.Id); if (item == null) { return(NotFound()); } var ingredients = ingredientRepo.GetBy(x => x.RecipeID == item.Id).ToList(); if (ingredients.Any()) { ingredientRepo.DeleteRange(ingredients); } var steps = stepRepo.GetBy(x => x.RecipeID == item.Id).ToList(); if (steps.Any()) { stepRepo.DeleteRange(steps); } var images = imageRepo.GetBy(x => x.RecipeID == item.Id).ToList(); if (images.Any()) { imageRepo.DeleteRange(images); } var recipeCategory = categoryRepo.GetBy(x => x.RecipeID == item.Id).ToList(); if (recipeCategory.Any()) { categoryRepo.DeleteRange(recipeCategory); } item.Title = request.Title; item.Details = request.Details; item.CookingTime = request.CookingTime; item.Calories = request.Calories; item.PrepareTime = request.PrepareTime; item.ServiceCount = request.ServiceCount; item.Ingredients = request.Ingredients.Select(y => new RecipeIngredient { Title = y.Title }).ToList(); item.Steps = request.Steps.Select(y => new Entity.Definition.Step { Title = y.Title }).ToList(); item.Images = request.Images.Select(y => new RecipeImage { Image = y.Image }).ToList(); item.RecipeCategories = request.Categories.Select(y => new RecipeCategory { CategoryID = y.CategoryID }).ToList(); recipeRepo.Update(item); response.Message = "Kayıt başarıyla güncellenmiştir."; return(Ok(response)); }
public async Task <RecipeUpdateResponse> Update([FromBody] RecipeUpdateRequest request) { return(await Mediator.Send(request)); }