private void ValidateOrderLines(Order order)
        {
            if (order.OrderLines == null)
            {
                throw new ArgumentException("OrderLines is null");
            }
            List <ProductStock> allProductStock = _productStockRepository.ReadAll().ToList();

            order.OrderLines.ForEach(ol =>
            {
                if (ol.ProductStock == null)
                {
                    throw new ArgumentException($"ProductStock of OrderLine is null");
                }

                if (ol.Quantity <= 0)
                {
                    throw new ArgumentException($"Quantity of OrderLine is equal or less then zero.");
                }

                if (ol.Quantity > ol.ProductStock.Quantity)
                {
                    throw new ArgumentException("OrderLine Quantity bigger then ProductStock Quantity");
                }

                ProductStock productStock = allProductStock.Find(p => p.Id == ol.ProductStock.Id);
                ol.ProductStock           = productStock ?? throw new ArgumentException($"Cannot find ProductStock with the Id {ol.ProductStock.Id}");
            }
                                     );
        }
Exemplo n.º 2
0
 public List <ProductStock> ReadAll()
 {
     return(_productStockRepository.ReadAll().ToList());
 }