Esempio n. 1
0
        public async Task <ActionResult <StockLevel> > Remove(
            int productId,
            [FromBody] RemoveStocks.Command command,
            CancellationToken cancellationToken
            )
        {
            try
            {
                command.ProductId = productId;
                var product = await _mediator.Send(command, cancellationToken);

                var stockLevel = _mapper.Map <DTO.StockLevel>(product);

                return(Ok(stockLevel));
            }
            catch (NotEnoughStockException ex)
            {
                return(Conflict(new
                {
                    ex.Message,
                    ex.AmountToRemove,
                    ex.QuantityInStock
                }));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult <StockLevel> > RemoveAsync(
            int productId,
            [FromBody] RemoveStocks.Command command
            )
        {
            try
            {
                command.ProductId = productId;
                var product = await _mediator.Send(command);

                var stockLevel = new StockLevel(product.QuantityInStock);
                return(Ok(stockLevel));
            }
            catch (NotEnoughStockException ex)
            {
                return(Conflict(new
                {
                    ex.Message,
                    ex.AmountToRemove,
                    ex.QuantityInStock
                }));
            }
        }