public IActionResult CreateProviderOrder([FromBody] ProviderOrderDto dto) { try { return(Ok(_providerOrderServices.CreateOrder(dto))); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
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); }