public double getRemainingSumToPayInRaffleSale(int saleId)
        {
            Sale s = SalesManager.getInstance().getSale(saleId);

            if (s == null)
            {
                return(-2);
            }
            ProductInStore p = ProductManager.getInstance().getProductInStore(s.ProductInStoreId);

            if (p == null)
            {
                return(-3);
            }
            double price = p.getPrice();

            foreach (RaffleSale rs in raffleSales)
            {
                if (rs.SaleId == saleId)
                {
                    price -= rs.Offer;
                }
            }
            return(price);
        }
Beispiel #2
0
 /*
  * return:
  *           0 < on sucess
  *          -1 if user Not Login
  *          -2 if Store Name already exist
  *          -3 if illegal product name
  *          -4 if don't have premition
  *          -5 if illegal amount
  *          -6 if illegal store id
  *          -7 if illegal price
  *          -8 if illegal product in store Id
  */
 public virtual int editProductInStore(User session, ProductInStore p, int quantity, double price)
 {
     if (session == null)
     {
         return(-1);// -1 if user Not Login
     }
     if (p == null)
     {
         return(-8);// -8 if illegal product in store Id
     }
     if (price < 0)
     {
         return(-7);// -7 if illegal price
     }
     if (quantity < 0)
     {
         return(-5);// -7 if illegal price
     }
     p.Price    = price;
     p.Quantity = quantity;
     if (ProductManager.getInstance().updateProductInStore(p))
     {
         return(0); // OK
     }
     return(-9);    // -9 database eror
 }
Beispiel #3
0
 public virtual Boolean addNewCoupon(User session, String couponId, ProductInStore p, int percentage, String dueDate)
 {
     if (session == null || couponId == null || p == null || percentage < 0 || dueDate == null || percentage <= 0)
     {
         return(false);
     }
     return(CouponsManager.getInstance().addNewCoupon(couponId, p.getProductInStoreId(), percentage, dueDate));
 }
Beispiel #4
0
 public virtual Boolean addDiscount(User session, ProductInStore p, int percentage, String dueDate)
 {
     if (session == null || p == null || percentage < 0 || percentage >= 100 || dueDate == null)
     {
         return(false);
     }
     return(DiscountsManager.getInstance().addNewDiscount(p.getProductInStoreId(), 1, "", percentage, dueDate, ""));
 }
 public override Boolean addNewCoupon(User session, String couponId, ProductInStore p, int percentage, String dueDate)
 {
     if (premissions.checkPrivilege(p.getStore().getStoreId(), session.getUserName(), "addNewCoupon"))
     {
         return(base.addNewCoupon(session, couponId, p, percentage, dueDate));
     }
     return(false);
 }
Beispiel #6
0
 public virtual Boolean removeDiscount(User session, ProductInStore p)
 {
     if (p == null || session == null)
     {
         return(false);
     }
     return(DiscountsManager.getInstance().removeDiscount(p.getProductInStoreId()));
 }
 public override Boolean removeDiscount(User session, ProductInStore p)
 {
     if (premissions.checkPrivilege(p.getStore().getStoreId(), session.getUserName(), "removeDiscount"))
     {
         return(base.removeDiscount(session, p));
     }
     return(false);
 }
 public override int removeProductFromStore(User session, Store s, ProductInStore p)
 {
     if (premissions.checkPrivilege(s.getStoreId(), session.getUserName(), "removeProductFromStore"))
     {
         return(base.removeProductFromStore(session, s, p));
     }
     return(-4);// -4 if don't have permission
 }
        public void sendMessageTORaffleWinner(int saleId)
        {
            Sale                    s         = SalesManager.getInstance().getSale(saleId);
            ProductInStore          p         = ProductManager.getInstance().getProductInStore(s.ProductInStoreId);
            LinkedList <RaffleSale> relevant  = new LinkedList <RaffleSale>();
            double                  realPrice = p.price;
            double                  acc       = 0;

            foreach (RaffleSale rs in raffleSales)
            {
                if (rs.SaleId == saleId)
                {
                    acc += rs.Offer;
                    relevant.AddLast(rs);
                }
            }
            if (acc == realPrice)
            {
                int        index   = 1;
                Random     rand    = new Random();
                int        winner  = rand.Next(1, (int)realPrice);
                RaffleSale winnerS = null;
                foreach (RaffleSale r in relevant)
                {
                    if (winner <= r.Offer + index && winner >= index)
                    {
                        string message = r.UserName + " WON THE RAFFLE SALE ON PRODUCT: " + getProductNameFromSaleId(r.SaleId);
                        NotificationPublisher.getInstance().publish(NotificationPublisher.NotificationCategories.RaffleSale, message, p.getStore().storeId);
                        StoreRole sR = StoreRole.getStoreRole(p.getStore(), UserManager.getInstance().getUser(r.UserName));
                        NotificationPublisher.getInstance().removeAllNotificationSubscriptionsOfAStoreRole(sR);
                        //NotificationManager.getInstance().notifyUser(r.UserName, message);
                        winnerS = r;
                        break;
                    }
                    else
                    {
                        index += (int)r.Offer;
                    }
                }
                if (winnerS != null)
                {
                    RSDB.Remove(winnerS);
                    raffleSales.Remove(winnerS);
                    relevant.Remove(winnerS);
                }
                foreach (RaffleSale r in relevant)
                {
                    string message = r.UserName + " LOST THE RAFFLE SALE ON PRODUCT: " + getProductNameFromSaleId(r.SaleId);
                    NotificationPublisher.getInstance().publish(NotificationPublisher.NotificationCategories.RaffleSale, message, p.getStore().storeId);
                    StoreRole sR = StoreRole.getStoreRole(p.getStore(), UserManager.getInstance().getUser(r.UserName));
                    NotificationPublisher.getInstance().removeAllNotificationSubscriptionsOfAStoreRole(sR);
                    //NotificationManager.getInstance().notifyUser(r.UserName, message);
                    RSDB.Remove(winnerS);
                    raffleSales.Remove(r);
                }
            }
        }
        private string getProductNameFromSaleId(int saleId)
        {
            string         ans = "";
            Sale           s   = SalesManager.getInstance().getSale(saleId);
            ProductInStore p   = ProductManager.getInstance().getProductInStore(s.ProductInStoreId);

            ans = p.product.name;
            return(ans);
        }
        public Boolean addRaffleSale(int saleId, String userName, double offer, String dueDate)
        {
            RaffleSale     toAdd = new RaffleSale(saleId, userName, offer, dueDate);
            ProductInStore pis   = ProductManager.getInstance().getProductInStore(SalesManager.getInstance().getSale(saleId).ProductInStoreId);
            StoreRole      sR    = StoreRole.getStoreRole(pis.store, UserManager.getInstance().getUser(userName));

            NotificationPublisher.getInstance().signToCategory(sR, NotificationPublisher.NotificationCategories.RaffleSale);
            RSDB.Add(toAdd);
            raffleSales.AddLast(toAdd);
            return(true);
        }
Beispiel #12
0
 public override int editProductInStore(User session, ProductInStore p, int quantity, double price)
 {
     if (session != null && p != null && price >= 0 && quantity >= 0)
     {
         if (premissions.checkPrivilege(p.getStore().getStoreId(), session.getUserName(), "editProductInStore"))
         {
             return(base.editProductInStore(session, p, quantity, price));
         }
     }
     return(-4);//-4 if don't have permission
 }
Beispiel #13
0
        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);
        }
        public LinkedList <PurchasePolicy> getAllRelevantPolicysForProductInStore(int productInStoreId, string country)
        {
            // 1-Product(system level) , 2- Store, 3-category, 4- product in store, 5-country
            LinkedList <PurchasePolicy> ans = new LinkedList <PurchasePolicy>();
            ProductInStore pis = ProductManager.getInstance().getProductInStore(productInStoreId);

            appendLists(ans, getAllStorePolicys(pis.store.storeId));
            appendLists(ans, getAllCategoryPolicys(pis.category, pis.store.storeId));
            appendLists(ans, getAllCountryPolicys(country, pis.store.storeId));
            appendLists(ans, getAllProductInStorePolicys(productInStoreId));
            appendLists(ans, getAllProductPolicys(pis.product.name));
            return(ans);
        }
Beispiel #15
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
        }
Beispiel #16
0
        public virtual int addProductInStore(User session, Store s, String productName, double price, int amount, string category)
        {
            if (productName == null || productName == "" ||
                productName[productName.Length - 1] == ' ')
            {
                return(-3);//-3 if illegal product name
            }
            if (session == null)
            {
                return(-1);// -1 if user Not Login
            }
            if (s == null)
            {
                return(-6);// -6 if illegal store id
            }
            if (amount <= 0)
            {
                return(-5);// -5 if illegal amount
            }
            if (price <= 0)
            {
                return(-7);// -7 if illegal price
            }
            //if(check if session is owner or manager with the right permission)
            Product p2 = ProductManager.getInstance().getProductByName(productName);

            if (p2 == null)
            {
                p2 = Product.addProduct(productName);
            }
            ProductManager pa  = ProductManager.getInstance();
            ProductInStore pis = pa.addProductInStore(p2, s, amount, price, category);

            if (pis != null)
            {
                return(pis.getProductInStoreId());
            }
            else
            {
                return(-8);
            }
        }
        /*
         *         Product product;
         * Store store;
         * int quantity; //will be removed in the future
         * double price;
         * int isActive;
         * int productInStoreId;
         */


        public ProductInStore addProductInStore(Product product, Store store, int quantity, double price)
        {
            ProductInStore newProduct;

            lock (this)
            {
                newProduct = new ProductInStore(getNextProductInStoreId(), "", product, price, quantity, store);
            }

            foreach (ProductInStore p in productsInStores)
            {
                if (p.getProduct().getProductId() == newProduct.getProduct().getProductId() && p.getStore().getStoreId() == newProduct.getStore().getStoreId())
                {
                    return(null);
                }
            }
            productInStoreDB.Add(newProduct);
            productsInStores.AddLast(newProduct);
            return(newProduct);
        }
Beispiel #18
0
 public virtual int removeProductFromStore(User session, Store s, ProductInStore p)
 {
     if (session == null)
     {
         return(-1);//-1 if user Not Login
     }
     if (s == null)
     {
         return(-6);//-6 if illegal store id
     }
     if (p == null)
     {
         return(-8);//-8 if illegal product in store Id
     }
     if (ProductManager.getInstance().removeProductInStore(p.getProductInStoreId(), s.getStoreId()))
     {
         return(0);
     }
     return(-9);
 }
Beispiel #19
0
        public LinkedList <Discount> getAllDiscountsById(int productInStoreId)
        {
            LinkedList <Discount> ans = new LinkedList <Discount>();

            foreach (Discount d in discounts)
            {
                if (DateTime.Compare(DateTime.Parse(d.DueDate), DateTime.Now) < 0)
                {
                    continue;
                }
                ProductInStore p           = ProductManager.getInstance().getProductInStore(productInStoreId);
                string         category    = p.category;
                string         productName = p.product.name;

                switch (d.Type)
                {
                case 1:     // discount on a product in store
                    if (d.ProductInStoreId == productInStoreId)
                    {
                        ans.AddLast(d);
                    }
                    break;

                case 2:     // discount on a category
                    if (d.Category.Equals(category))
                    {
                        ans.AddLast(d);
                    }
                    break;

                case 3:     // discount on a PRODUCT (not in store)
                    if (d.ProductName.Equals(productName))
                    {
                        ans.AddLast(d);
                    }
                    break;
                }
            }
            return(ans);
        }
 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);
 }
        public LinkedList <Coupon> getAllCouponsById(int productInStoreId)
        {
            LinkedList <Coupon> ans = new LinkedList <Coupon>();

            foreach (Coupon c in coupons)
            {
                ProductInStore p           = ProductManager.getInstance().getProductInStore(productInStoreId);
                string         category    = p.category;
                string         productName = p.product.name;

                switch (c.Type)
                {
                case 1:     // discount on a product in store
                    if (c.ProductInStoreId == productInStoreId)
                    {
                        ans.AddLast(c);
                    }
                    break;

                case 2:     // discount on a category
                    if (c.Category.Equals(category))
                    {
                        ans.AddLast(c);
                    }
                    break;

                case 3:     // discount on a PRODUCT (not in store)
                    if (c.ProductName.Equals(productName))
                    {
                        ans.AddLast(c);
                    }
                    break;
                }
            }
            return(ans);
        }
Beispiel #22
0
 public override int removeProductFromStore(User session, Store s, ProductInStore p)
 {
     return(-4);//-4 if don't have premition
 }
Beispiel #23
0
 public override int editProductInStore(User session, ProductInStore p, int quantity, double price)
 {
     return(-4);//-4 if don't have premition
 }
Beispiel #24
0
 public override Boolean addNewCoupon(User session, String couponId, ProductInStore p, int percentage, String dueDate)
 {
     return(false);
 }
Beispiel #25
0
 public override Boolean addDiscount(User session, ProductInStore p, int percentage, String dueDate)
 {
     return(false);
 }
Beispiel #26
0
        private int checkAmountFulfillment(string country)
        {
            foreach (UserCart uc in products)
            {
                Sale           s          = SalesManager.getInstance().getSale(uc.getSaleId());
                ProductInStore theProduct = ProductManager.getInstance().getProductInStore(s.ProductInStoreId);
                LinkedList <PurchasePolicy> storePolicys          = PurchasePolicyManager.getInstance().getAllStorePolicys(theProduct.store.storeId);
                LinkedList <PurchasePolicy> countrysPolicys       = PurchasePolicyManager.getInstance().getAllCountryPolicys(country, theProduct.store.storeId);
                LinkedList <PurchasePolicy> categorysPolicys      = PurchasePolicyManager.getInstance().getAllCategoryPolicys(theProduct.Category, theProduct.store.storeId);
                LinkedList <PurchasePolicy> productPolicys        = PurchasePolicyManager.getInstance().getAllProductPolicys(theProduct.getProduct().name);
                LinkedList <PurchasePolicy> productInStorePolicys = PurchasePolicyManager.getInstance().getAllProductInStorePolicys(theProduct.getProductInStoreId());

                int currAmount = uc.getAmount();
                foreach (PurchasePolicy p in storePolicys)
                {
                    if (!p.NoLimit)
                    {
                        if (currAmount < p.MinAmount || currAmount > p.MaxAmount)
                        {
                            return(uc.getSaleId());
                        }
                    }
                }
                foreach (PurchasePolicy p in countrysPolicys)
                {
                    if (!p.NoLimit)
                    {
                        if (currAmount < p.MinAmount || currAmount > p.MaxAmount)
                        {
                            return(uc.getSaleId());
                        }
                    }
                }
                foreach (PurchasePolicy p in categorysPolicys)
                {
                    if (!p.NoLimit)
                    {
                        if (currAmount < p.MinAmount || currAmount > p.MaxAmount)
                        {
                            return(uc.getSaleId());
                        }
                    }
                }
                foreach (PurchasePolicy p in productPolicys)
                {
                    if (!p.NoLimit)
                    {
                        if (currAmount < p.MinAmount || currAmount > p.MaxAmount)
                        {
                            return(uc.getSaleId());
                        }
                    }
                }
                foreach (PurchasePolicy p in productInStorePolicys)
                {
                    if (!p.NoLimit)
                    {
                        if (currAmount < p.MinAmount || currAmount > p.MaxAmount)
                        {
                            return(uc.getSaleId());
                        }
                    }
                }
            }
            return(-1);
        }
Beispiel #27
0
        public Boolean buyProducts(User session, String creditCard, String couponId)
        {
            LinkedList <UserCart> toDelete = new LinkedList <UserCart>();
            Boolean allBought = true;

            if (creditCard == null || creditCard.Equals(""))
            {
                return(false);
            }
            foreach (UserCart product in products)
            {
                if (couponId != null && couponId != "")
                {
                    product.activateCoupon(couponId);
                }
                Sale sale = SalesManager.getInstance().getSale(product.getSaleId());
                if (sale.TypeOfSale == 1 && checkValidAmount(sale, product) && checkValidDate(sale)) //regular buy
                {
                    if (PaymentSystem.getInstance().payForProduct(creditCard, session, product))
                    {
                        ShippingSystem.getInstance().sendShippingRequest();
                        ProductInStore p           = ProductManager.getInstance().getProductInStore(sale.ProductInStoreId);
                        int            productId   = p.getProduct().getProductId();
                        int            storeId     = p.getStore().getStoreId();
                        String         userName    = session.getUserName();
                        double         price       = product.updateAndReturnFinalPrice(couponId);
                        DateTime       currentDate = DateTime.Today;
                        String         date        = currentDate.ToString();
                        int            amount      = product.getAmount();
                        int            typeOfSale  = sale.TypeOfSale;
                        BuyHistoryManager.getInstance().addBuyHistory(productId, storeId, userName, price, date, amount,
                                                                      typeOfSale);
                        //products.Remove(product);
                        toDelete.AddLast(product);
                        SalesManager.getInstance().setNewAmountForSale(product.getSaleId(), sale.Amount - product.getAmount());
                    }
                    else
                    {
                        allBought = false;
                    }
                }
                else if (sale.TypeOfSale == 2) // auction buy
                {
                }
                else if (sale.TypeOfSale == 3 && checkValidDate(sale)) // raffle buy
                {
                    double offer        = product.getOffer();
                    double remainingSum = getRemainingSumForOffers(sale.SaleId);
                    if (offer > remainingSum)
                    {
                        allBought = false;
                    }
                    else
                    {
                        if (RaffleSalesManager.getInstance().addRaffleSale(sale.SaleId, session.getUserName(), offer, sale.DueDate))
                        {
                            PaymentSystem.getInstance().payForProduct(creditCard, session, product);
                            ProductInStore p           = ProductManager.getInstance().getProductInStore(sale.ProductInStoreId);
                            int            productId   = p.getProduct().getProductId();
                            int            storeId     = p.getStore().getStoreId();
                            String         userName    = session.getUserName();
                            DateTime       currentDate = DateTime.Today;
                            String         date        = currentDate.ToString();
                            int            amount      = product.getAmount();
                            int            typeOfSale  = sale.TypeOfSale;
                            BuyHistoryManager.getInstance().addBuyHistory(productId, storeId, userName, offer, date, amount,
                                                                          typeOfSale);
                            //products.Remove(product);
                            toDelete.AddLast(product);
                        }
                        else
                        {
                            allBought = false;
                        }
                    }
                }
            }
            foreach (UserCart uc in toDelete)
            {
                products.Remove(uc);
            }

            return(allBought);
        }
Beispiel #28
0
        public int buyProductsInCart(User session, string country, string adress, string creditCard)
        {
            int allBought = 1;
            LinkedList <UserCart> toDelete = new LinkedList <UserCart>();

            if (creditCard == null || creditCard.Equals(""))
            {
                return(-2);
            }
            foreach (UserCart product in products)
            {
                Sale sale = SalesManager.getInstance().getSale(product.getSaleId());
                if (sale.TypeOfSale == 1 && checkValidAmount(sale, product) && checkValidDate(sale)) //regular buy
                {
                    if (paymentProxy.payForProduct(creditCard, session, product))
                    {
                        if (!shippingProxy.sendShippingRequest(session, country, adress, creditCard))
                        {
                            return(-9);
                        }

                        ProductInStore p           = ProductManager.getInstance().getProductInStore(sale.ProductInStoreId);
                        int            productId   = p.getProduct().getProductId();
                        int            storeId     = p.getStore().getStoreId();
                        String         userName    = session.getUserName();
                        DateTime       currentDate = DateTime.Today;
                        String         date        = currentDate.ToString();
                        int            amount      = product.getAmount();
                        int            typeOfSale  = sale.TypeOfSale;
                        Purchase.addBuyHistory(productId, storeId, userName, product.PriceAfterDiscount, date, amount, typeOfSale);
                        //BuyHistoryManager.getInstance().addBuyHistory(productId, storeId, userName, product.PriceAfterDiscount, date, amount,
                        //    typeOfSale);
                        toDelete.AddLast(product);
                        SalesManager.getInstance().setNewAmountForSale(product.getSaleId(), sale.Amount - product.getAmount());
                        Purchase.alertOwnersOnPurchase(StoreManagement.getInstance().getAllOwners(p.store.storeId), p.productInStoreId, 1);
                    }
                    else
                    {
                        allBought = -4;
                    }
                }
                else if (sale.TypeOfSale == 2) // auction buy
                {
                }
                else if (sale.TypeOfSale == 3 && checkValidDate(sale)) // raffle buy
                {
                    double offer        = product.getOffer();
                    double remainingSum = getRemainingSumForOffers(sale.SaleId);
                    if (offer > remainingSum)
                    {
                        allBought = -4;
                    }
                    else
                    {
                        if (paymentProxy.payForProduct(creditCard, session, product))
                        {
                            RaffleSalesManager.getInstance().addRaffleSale(sale.SaleId, session.getUserName(), offer, sale.DueDate);
                            ProductInStore p           = ProductManager.getInstance().getProductInStore(sale.ProductInStoreId);
                            int            productId   = p.getProduct().getProductId();
                            int            storeId     = p.getStore().getStoreId();
                            String         userName    = session.getUserName();
                            DateTime       currentDate = DateTime.Today;
                            String         date        = currentDate.ToString();
                            int            amount      = product.getAmount();
                            int            typeOfSale  = sale.TypeOfSale;
                            Purchase.addBuyHistory(productId, storeId, userName, offer, date, amount, typeOfSale);
                            //BuyHistoryManager.getInstance().addBuyHistory(productId, storeId, userName, offer, date, amount,
                            //    typeOfSale);
                            RaffleSalesManager.getInstance().sendMessageTORaffleWinner(sale.SaleId);
                            SalesManager.getInstance().setNewAmountForSale(product.getSaleId(), sale.Amount - product.getAmount());
                            Purchase.alertOwnersOnPurchase(StoreManagement.getInstance().getAllOwners(p.store.storeId), p.productInStoreId, 3);
                            toDelete.AddLast(product);
                        }
                        else
                        {
                            allBought = -4;
                        }
                    }
                }
                else
                {
                    return(-5); // unknown error - should not happen
                }
            }
            foreach (UserCart uc in toDelete)
            {
                if (!(session.getState() is Guest))
                {
                    UserCartsManager.getInstance().removeUserCart(session.userName, uc.SaleId);
                }
                products.Remove(uc);
            }

            return(allBought);
        }