Beispiel #1
0
        public IActionResult Post([FromBody] ProductItemDto productItemDto)
        {
            var productService = TransparentProxy <IProductService> .Create(new ProductManager(_memoryCache), _memoryCache);

            productService.AddProduct(productItemDto);

            return(Created(string.Empty, true));
        }
Beispiel #2
0
 public static ProductItem MapToProductItem(this ProductItemDto source)
 {
     return(new ProductItem
     {
         Id = source.Id,
         Name = source.Name,
         Price = source.Price,
     });
 }
Beispiel #3
0
        public ProductItemDto UpdateProductItem(ProductItemDto itemToBeUpdated)
        {
            var updatedItem = _ProductRepository
                              .UpdateProductItem(itemToBeUpdated.MapToProductItem());

            if (updatedItem != null)
            {
                return(updatedItem.MapToProductItemDto());
            }

            return(null);
        }
        public ActionResult <ProductItemDto> Patch([FromBody] ProductItemDto itemToBeUpdated)
        {
            if (itemToBeUpdated == null || itemToBeUpdated.Id == 0)
            {
                return(this.Problem($"Invalid product item", null, 400));
            }

            if (string.IsNullOrWhiteSpace(itemToBeUpdated.Name) || itemToBeUpdated.Price == 0)
            {
                return(this.Problem($"New values must be valid", null, 400));
            }

            var updatedItem = _ProductManager.UpdateProductItem(itemToBeUpdated);

            if (updatedItem == null)
            {
                return(this.Problem($"Unable to update item.", null, 500));
            }

            return(updatedItem);
        }
Beispiel #5
0
 public ProductItemDto AddProduct(ProductItemDto productItem)
 {
     _memoryCache.Set("product_item_list", productItem);
     return(productItem);
 }
Beispiel #6
0
 public async Task <IActionResult> Put(ProductItemDto dto)
 {
     return(Ok(
                await _mediator.Send(new UpdateProductItemCommand(dto))
                ));
 }