public IActionResult Delete(string id) { var command = new DeleteProductCommand(id.ToValidGuid()); var handler = ProductCommandHandlerFactory.Build(command); var response = handler.Execute(); if (!response.Success) { return(StatusCode(500, response)); } return(Ok(response)); }
public IActionResult Post([FromBody] Product product) { var command = new SaveProductCommand(product); var handler = ProductCommandHandlerFactory.Build(command); var response = handler.Execute(); if (!response.Success) { return(StatusCode(500, response)); } product.Id = response.Id; return(Ok(product)); }
public IActionResult Post([FromBody] ProductViewModel productViewModel) { var product = new Product { Id = productViewModel.Id, CategoryId = productViewModel.CategoryId, CreatedOn = DateTime.UtcNow, Description = productViewModel.Description, Image = productViewModel.Image, IsDeleted = productViewModel.IsDeleted, Name = productViewModel.Name, Price = productViewModel.Price }; var command = new SaveProductCommand(product); var handler = ProductCommandHandlerFactory.Build(command); var response = handler.Execute(); if (!response.Success) { return(StatusCode(500, response)); } product.Id = response.Id; return(Ok(product)); }