Пример #1
0
 public IActionResult CreateProviderOrder([FromBody] ProviderOrderDto dto)
 {
     try
     {
         return(Ok(_providerOrderServices.CreateOrder(dto)));
     }
     catch (ArgumentException e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #2
0
        public Guid CreateOrder(ProviderOrderDto dto)
        {
            var provider = _providerRepository.GetById(dto.ProviderId);

            if (provider == null)
            {
                throw new ArgumentException("Provider not found.");
            }

            var order = ProviderOrder.MakeProviderOrder(dto.RegisterNumber, provider);

            var products = _productRepository
                           .FindBy(p => dto.Items
                                   .Select(r => r.ProductId)
                                   .Contains(p.Id))
                           .AsEnumerable();

            dto.Items
            .ForEach(i => order.AddItem(products.FirstOrDefault(p => p.Id.Equals(i.ProductId)), i.Amount));

            _repository.Add(order);

            return(order.Id);
        }