Exemple #1
0
 public IActionResult AddProviderOrderItem(Guid id, [FromBody] ProviderOrderItemDto dto)
 {
     try
     {
         Guid itemView = _providerOrderServices.AddItem(id, dto);
         return(Ok(itemView));
     }
     catch (ArgumentException e)
     {
         return(BadRequest(e.Message));
     }
 }
Exemple #2
0
        public IActionResult UpdateProviderOrderItem(Guid id, [FromBody] ProviderOrderItemDto dto)
        {
            try
            {
                _providerOrderItemServices.UpdateProviderOrderItem(id, dto);
                return(Ok());
            }
            catch (ArgumentException e)
            {
                if (e.Message == "Item not found.")
                {
                    return(NotFound());
                }

                return(BadRequest(e.Message));
            }
        }
        public void UpdateProviderOrderItem(Guid id, ProviderOrderItemDto dto)
        {
            var item = _repository.GetById(id);

            if (item == null)
            {
                throw new ArgumentException("Item not found.");
            }

            if (dto.Amount != 0)
            {
                item.ChangeAmount(dto.Amount);
            }

            if (dto.Price != 0)
            {
                item.ChangePrice(dto.Price);
            }
        }
        public Guid AddItem(Guid orderId,
                            ProviderOrderItemDto dto)
        {
            var order = _repository.GetById(orderId);

            if (order == null)
            {
                throw new ArgumentException("Order not found.");
            }

            var product = _productRepository.GetById(dto.ProductId);

            if (product == null)
            {
                throw new ArgumentException("Product not found.");
            }

            Guid id = order.AddItem(product, dto.Amount);

            _repository.Update(order);

            return(id);
        }