예제 #1
0
 public static ProductItem MapToProductItem(this InsertedProductItemDto source)
 {
     return(new ProductItem
     {
         Name = source.Name,
         Price = source.Price,
     });
 }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }