コード例 #1
0
ファイル: StoreRole.cs プロジェクト: shaybenh7/workshop182v3
        public virtual int addSaleToStore(User session, Store s, int productInStoreId, int typeOfSale, int amount, String dueDate)
        {
            ProductInStore pis = ProductManager.getInstance().getProductInStore(productInStoreId);

            if (session == null)
            {
                return(-1);// -1 if user Not Login
            }
            if (s == null)
            {
                return(-6); //-6 if illegal store id
            }
            if (pis == null)
            {
                return(-8);//-8 if illegal product in store Id
            }
            if (typeOfSale > 3 || typeOfSale < 1)
            {
                return(-11);// -11 illegal type of sale not
            }
            if (pis.getAmount() < amount)
            {
                return(-5);//-5 if illegal amount
            }
            if (amount < 0)
            {
                return(-12);// -12 if illegal amount
            }
            try {
                DateTime.Parse(dueDate);
            }
            catch (Exception)
            {
                return(-10);
            }
            if (dueDate == null || DateTime.Compare(DateTime.Parse(dueDate), DateTime.Now) < 0)
            {
                return(-10);//-10 due date not good
            }
            if (pis.getStore().getStoreId() != s.getStoreId())
            {
                return(-13);//-13 product not in this store
            }
            if (typeOfSale == 2)
            {
                //will be implemented next version
                return(-11);// -11 illegal type of sale not
            }
            Sale sale = SalesManager.getInstance().addSale(productInStoreId, typeOfSale, amount, dueDate);

            return((sale == null) ? -9 : sale.SaleId);
        }
コード例 #2
0
        public int editCart(User session, int saleId, int newAmount)
        {
            Sale sale = SalesManager.getInstance().getSale(saleId);

            if (sale == null)
            {
                return(-2);
            }

            if (sale.TypeOfSale == 3)
            {
                return(-3); // trying to edit amount of a raffle sale
            }
            ProductInStore p = ProductManager.getInstance().getProductInStore(sale.ProductInStoreId);

            if (newAmount > sale.Amount)
            {
                return(-4); // new amount is bigger than currently up for sale
            }
            if (newAmount > p.getAmount())
            {
                return(-5); // new amount is bigger than currently exist in stock
            }
            if (newAmount <= 0)
            {
                return(-6); // new amount can't be zero or lower
            }
            if (!(session.getState() is Guest))
            {
                UserCartsManager.getInstance().editUserCarts(session.getUserName(), saleId, newAmount);
            }

            foreach (UserCart product in products)
            {
                if (product.getUserName().Equals(session.getUserName()) && saleId == product.getSaleId())
                {
                    product.setAmount(newAmount);

                    return(1);
                }
            }
            return(-7); // trying to edit amount of product that does not exist in cart
        }
コード例 #3
0
 public Boolean updateProductInStore(ProductInStore newProduct)
 {
     if (newProduct == null)
     {
         return(false);
     }
     if (newProduct.getProduct() == null || newProduct.getStore() == null || newProduct.getAmount() < 0 || newProduct.getPrice() < 0)
     {
         return(false);
     }
     foreach (ProductInStore p in productsInStores)
     {
         if (p.getProduct().getProductId() == newProduct.getProduct().getProductId() && p.getStore().getStoreId() == newProduct.getStore().getStoreId())
         {
             productInStoreDB.Remove(p);
             productsInStores.Remove(p);
             productInStoreDB.Add(newProduct);
             productsInStores.AddLast(newProduct);
             return(true);
         }
     }
     return(false);
 }