public static ProductItem MapToProductItem(this InsertedProductItemDto source) { return(new ProductItem { Name = source.Name, Price = source.Price, }); }
public ProductItemDto CreateProductItem(InsertedProductItemDto inputDto) { var item = inputDto.MapToProductItem(); var newItemId = _ProductRepository.CreateProductItem(item); if (newItemId.HasValue) { return(_ProductRepository .GetProductItem(newItemId.Value) .MapToProductItemDto()); } return(null); }
public ActionResult <ProductItemDto> Post([FromBody] InsertedProductItemDto inputDto) { if (inputDto == null || string.IsNullOrWhiteSpace(inputDto.Name) || inputDto.Price == 0) { return(this.Problem($"Item name and price must be provided", null, 400)); } var result = _ProductManager.CreateProductItem(inputDto); if (result == null) { return(this.Problem("Unable to create item", null, 500)); } return(result); }