Esempio n. 1
0
        //returns positive error code or 0 if valid request
        //-1: insufficient qty
        //-2: nonexistant product
        //@param id: store id
        //@param input:product name string or string of product id
        //@param qty: requested quantity of product
        public int ValidateProd(int store_id, string input, int qty, out Decimal price)
        {
            input = input.Trim();
            int id = -1;

            try
            {
                id = int.Parse(input);
            }
            catch (Exception)
            {
                input = input.ToLower();
            }
            //Find requested product
            var listInventory = DAL.GetInventory(store_id);
            var prod          = listInventory.Find(inv => inv.Id == id);

            if (prod == null)
            {
                prod = listInventory.Find(inv => inv.P.Name.ToLower() == input);
            }
            price = -1;
            if (prod == null)
            {
                Console.WriteLine("Item not found");
                return(-2);
            }
            else if (!BusinessValidation.ValidateQuantity(qty, prod.Qty))
            {
                Console.WriteLine("Insufficient stock/Excessive quantity");
                return(-1);
            }
            else
            {
                price = prod.P.Price;
                return(prod.Id);
            }
        }
 public void TestUnreasonableQuantity(int value, int val2)
 {
     Assert.False(BusinessValidation.ValidateQuantity(value, val2));
 }