public UpdatePizzaResponse UpdatePizza(UpdatePizzaRequest updatePizzaRequest) { UpdatePizzaResponse result = new UpdatePizzaResponse(); try { Pizza existingPizza = _pizzaRepository.FindBy(updatePizzaRequest.Id); if (existingPizza != null) { Pizza assignableProperties = AssignAvailablePropertiesToDomain(updatePizzaRequest.PizzaProperties); existingPizza.Name = assignableProperties.Name ?? existingPizza.Name; existingPizza.LaunchDate = assignableProperties.LaunchDate ?? existingPizza.LaunchDate; existingPizza.Price = assignableProperties.Price; existingPizza.PizzaRecipe = assignableProperties.PizzaRecipe ?? existingPizza.PizzaRecipe; ThrowExceptionIfPizzaIsInvalid(existingPizza); _pizzaRepository.Update(existingPizza); return(new UpdatePizzaResponse()); } else { GetStandardPizzaNotFoundException(); } } catch (Exception ex) { result.StatusCode = HttpStatusCode.InternalServerError; result.StatusDesciption = ex.Message; } return(result); }
public UpdatePizzaResponse Update(UpdatePizzaRequest request) { var pizza = request.ProjectedAs <Pizza>(); var response = _service.Update(pizza); if (response.IsSuccess) { _uow.Commit(); } return(response.ProjectedAs <UpdatePizzaResponse>()); }
//[SwaggerResponse(System.Net.HttpStatusCode.OK, Type = typeof(UpdateUserRequest))] public IActionResult Put(UpdatePizzaVM updatePizzaVM) { UpdatePizzaRequest req = new UpdatePizzaRequest(updatePizzaVM.Id) { PizzaProperties = new PizzaPropertiesVM() { Name = updatePizzaVM.Name, LaunchDate = updatePizzaVM.LaunchDate, Price = updatePizzaVM.Price, Ingredients = updatePizzaVM.Ingredients, CookingTime = updatePizzaVM.CookingTime, Description = updatePizzaVM.Description } }; UpdatePizzaResponse updatePizzaResponse = _pizzaService.UpdatePizza(req); return(Ok(updatePizzaResponse)); }
public IActionResult Update([FromBody] UpdatePizzaRequest request) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorResponse())); } var response = _service.Update(request); if (!response.Success) { return(BadRequest(response.Erros)); } return(Ok()); } catch (Exception ex) { return(BadRequest(ex)); } }