private static Purchase ToPurchase(NameQuantity nameQuantity)
 {
     return(new Purchase
     {
         Name = nameQuantity.Name,
         Quantity = nameQuantity.Quantity
     });
 }
Example #2
0
        private void FillOrders(params string[] basketByNames)
        {
            foreach (var bookName in basketByNames)
            {
                var book = new NameQuantity
                {
                    Name     = bookName,
                    Quantity = 1
                };

                if (this.Order.Any(b => b.Name == bookName))
                {
                    this.Order.FirstOrDefault(b => b.Name == bookName).Quantity++;
                }
                else
                {
                    this.Order.Add(book);
                }
            }
        }
        public NotEnoughInventoryException ValidateBasket(List <Basket> basketToValidate, IEnumerable <Catalog> catalogData)
        {
            NotEnoughInventoryException exception = new NotEnoughInventoryException();

            foreach (var product in basketToValidate)
            {
                var stock = catalogData.Where(n => n.Name == product.Name).First().Quantity;
                if (product.Quantity > stock)
                {
                    NameQuantity missing = new NameQuantity();;
                    missing.createException(product.Name, product.Quantity);
                    exception.AddException(missing);
                }
            }
            if (exception.Missing != null)
            {
                throw exception;
            }
            else
            {
                return(null);
            }
        }