Example #1
0
        private void checkAndUpdateDiscountsByPolicys(string country)
        {
            Boolean skip = false;

            foreach (UserCart uc in products)
            {
                Sale s = SalesManager.getInstance().getSale(uc.getSaleId());
                LinkedList <Discount> relevantDiscounts = DiscountsManager.getInstance().getAllDiscountsById(s.ProductInStoreId);
                uc.PriceAfterDiscount = uc.Price;
                LinkedList <PurchasePolicy> policys = PurchasePolicyManager.getInstance().getAllRelevantPolicysForProductInStore(s.ProductInStoreId, country);
                foreach (PurchasePolicy p in policys)
                {
                    if (p.NoDiscount)
                    {
                        skip = true;
                    }
                }
                if (skip)
                {
                    skip = false;
                    continue;
                }

                foreach (Discount d in relevantDiscounts)
                {
                    checkPolicysAndUpdatePrice(uc, d, country, s.TypeOfSale);
                }
            }
        }
        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);
        }
Example #3
0
        public int removeFromCart(User session, int saleId)
        {
            Sale isExist = SalesManager.getInstance().getSale(saleId);

            if (isExist == null)
            {
                return(-2); // -2 = the sale id does not exist
            }
            if (!(session.getState() is Guest))
            {
                if (!UserCartsManager.getInstance().removeUserCart(session.getUserName(), saleId))
                {
                    return(-3); // trying to remove a product that does not exist in the cart
                }
            }

            foreach (UserCart c in products)
            {
                if (c.getUserName().Equals(session.getUserName()) && c.getSaleId() == saleId)
                {
                    products.Remove(c);

                    return(1);
                }
            }
            return(-3);
        }
Example #4
0
        public LinkedList <UserCart> getShoppingCartBeforeCheckout(User session)
        {
            if (!(session.getState() is Guest))
            {
                products = UserCartsManager.getInstance().getUserShoppingCart(session.getUserName());
            }

            updateRegularPricesForCart(); // set all the regular prices for the cart - before discount
            foreach (UserCart uc in products)
            {
                Sale sale = SalesManager.getInstance().getSale(uc.getSaleId());
                LinkedList <Discount> discounts = DiscountsManager.getInstance().getAllDiscountsById(sale.ProductInStoreId);
                uc.PriceAfterDiscount = uc.Price;
                foreach (Discount d in discounts)
                {
                    if (fulfillTypeOfSaleRestriction(sale.TypeOfSale, d))
                    {
                        double dis          = uc.PriceAfterDiscount * (d.Percentage / 100);
                        double updatedPrice = uc.PriceAfterDiscount - dis;
                        uc.PriceAfterDiscount = updatedPrice;
                    }
                }
            }
            return(products);
        }
Example #5
0
 public static SalesManager getInstance()
 {
     if (instance == null)
     {
         instance = new SalesManager();
     }
     return(instance);
 }
Example #6
0
 private void updateRegularPricesForCart()
 {
     foreach (UserCart uc in products)
     {
         Sale   s            = SalesManager.getInstance().getSale(uc.getSaleId());
         double pricePerUnit = ProductManager.getInstance().getProductInStore(s.ProductInStoreId).getPrice();
         uc.Price = pricePerUnit * uc.getAmount();
     }
 }
        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 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);
                }
            }
        }
Example #9
0
        public static LinkedList <Sale> viewSalesByProductInStoreId(int product)
        {
            LinkedList <Sale> ans = SalesManager.getInstance().getSalesByProductInStoreId(product);

            if (ans.Count == 0)
            {
                return(null);
            }
            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);
        }
Example #11
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);
        }
Example #12
0
        public int addToCart(User session, int saleId, int amount)
        {
            Sale saleExist = SalesManager.getInstance().getSale(saleId);

            if (saleExist == null)
            {
                return(-3); //-3 = saleId entered doesn't exist
            }
            if (!checkValidDate(saleExist))
            {
                return(-4); // -4 = the date for the sale is no longer valid
            }
            if (saleExist.TypeOfSale != 1)
            {
                return(-5); //-5 = trying to add a sale with type different from regular sale type
            }
            int amountInStore = ProductManager.getInstance().getProductInStore(saleExist.ProductInStoreId).getAmount();

            if (amount > amountInStore || amount <= 0)
            {
                return(-6); // -6 = amount is bigger than the amount that exist in stock
            }
            int amountForSale = SalesManager.getInstance().getSale(saleId).Amount;

            if (amount > amountForSale || amount <= 0)
            {
                return(-7); //amount is bigger than the amount currently up for sale
            }
            if (!(session.getState() is Guest))
            {
                UserCartsManager.getInstance().updateUserCarts(session.getUserName(), saleId, amount);
            }

            UserCart toAdd = new UserCart(session.getUserName(), saleId, amount);

            foreach (UserCart c in products)
            {
                if (c.getUserName().Equals(toAdd.getUserName()) && c.getSaleId() == toAdd.getSaleId())
                {
                    if (c.getAmount() + amount <= amountForSale)
                    {
                        c.setAmount(c.getAmount() + amount);
                        return(1); // OK
                    }
                    return(-7);
                }
            }
            //in updateUserCarts we already add the product in case it doesn't exist, so no need to add to DB here also
            products.AddLast(toAdd);
            return(1);
        }
Example #13
0
        public LinkedList <UserCart> applyCoupon(User session, string couponId, string country)
        {
            if (couponId == null || couponId.Equals(""))
            {
                return(products);
            }
            if (country == null)
            {
                country = "";
            }
            if (usedCoupons.Contains(couponId))
            {
                return(products);
            }
            Coupon coupon = CouponsManager.getInstance().getCoupon(couponId);

            if (coupon == null)
            {
                return(products);
            }
            Boolean skip = false;

            foreach (UserCart uc in products)
            {
                Sale s = SalesManager.getInstance().getSale(uc.getSaleId());
                LinkedList <Coupon>         relevantCoupons = CouponsManager.getInstance().getAllCouponsById(s.ProductInStoreId);
                LinkedList <PurchasePolicy> policys         = PurchasePolicyManager.getInstance().getAllRelevantPolicysForProductInStore(s.ProductInStoreId, country);
                foreach (PurchasePolicy p in policys)
                {
                    if (p.NoCoupons)
                    {
                        skip = true;
                    }
                }
                if (skip)
                {
                    skip = false;
                    continue;
                }
                if (relevantCoupons.Contains(coupon))
                {
                    checkAndUpdateCouponByPolicy(uc, coupon, country, s.TypeOfSale);
                }
            }
            usedCoupons.AddLast(couponId);
            return(products);
        }
Example #14
0
        public LinkedList <Sale> getAllSales()
        {
            LinkedList <ProductInStore> products = getProductsInStore();
            LinkedList <Sale>           ans      = new LinkedList <Sale>();

            foreach (Sale sale in SalesManager.getInstance().getAllSales())
            {
                foreach (ProductInStore product in products)
                {
                    if (sale.ProductInStoreId.Equals(product.getProductInStoreId()))
                    {
                        ans.AddLast(sale);
                    }
                }
            }
            return(ans);
        }
Example #15
0
        public int addToCartRaffle(User session, int saleId, double offer)
        {
            Sale sale = SalesManager.getInstance().getSale(saleId);

            if (sale == null)
            {
                return(-3); // sale id entered does not exist
            }
            if (sale.TypeOfSale != 3)
            {
                return(-4); // sale is not of type raffle
            }
            if (!checkValidDate(sale))
            {
                return(-5); // the date for the sale is no longer valid
            }
            UserCart isExist = UserCartsManager.getInstance().getUserCart(session.getUserName(), sale.SaleId);

            if (isExist != null)
            {
                return(-6); // already have an instance of the raffle sale in the cart
            }
            double remainingSum = getRemainingSumForOffers(sale.SaleId);

            if (offer > remainingSum || offer <= 0)
            {
                return(-8); // offer is bigger than remaining sum to pay
            }
            if (!(session.getState() is Guest))
            {
                UserCartsManager.getInstance().updateUserCarts(session.getUserName(), sale.SaleId, 1, offer);
            }
            else
            {
                return(-7); // cannot add a raffle sale to cart while on guest mode
            }

            //UserCart toAdd = UserCartsManager.getInstance().getUserCart(session.getUserName(), sale.SaleId);
            UserCart toAdd = new UserCart(session.getUserName(), sale.SaleId, 1);

            toAdd.setOffer(offer);
            session.getShoppingCart().AddLast(toAdd);

            return(1);
        }
Example #16
0
        private double getRemainingSumForOffers(int saleId)
        {
            Sale   currSale               = SalesManager.getInstance().getSale(saleId);
            double totalPrice             = ProductManager.getInstance().getProductInStore(currSale.ProductInStoreId).getPrice();
            LinkedList <RaffleSale> sales = RaffleSalesManager.getInstance().getAllRaffleSalesBySaleId(saleId);

            if (sales.Count() == 0)
            {
                return(totalPrice);
            }
            else
            {
                foreach (RaffleSale sale in sales)
                {
                    totalPrice -= sale.Offer;
                }
                return(totalPrice);
            }
        }
Example #17
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
        }
Example #18
0
 public virtual int removeSaleFromStore(User session, Store s, int saleId)
 {
     if (session == null)
     {
         return(-1);// -1 if user Not Login
     }
     if (s == null)
     {
         return(-6); //-6 if illegal store id
     }
     if (SalesManager.getInstance().getSale(saleId) == null)
     {
         return(-8);// -8 if illegal sale id
     }
     if (SalesManager.getInstance().removeSale(saleId))
     {
         return(0);
     }
     return(-9); //database error
 }
Example #19
0
 public virtual int editSale(User session, Store s, int saleId, int amount, String dueDate)
 {
     if (SalesManager.getInstance().getSale(saleId) == null)
     {
         return(-8);// -8 if illegal sale id
     }
     if (session == null)
     {
         return(-1);// -1 if user Not Login
     }
     if (s == null)
     {
         return(-6); //-6 if illegal store id
     }
     if (ProductManager.getInstance().getProductInStore(SalesManager.getInstance().getSale(saleId).ProductInStoreId).getAmount() < amount)
     {
         return(-5);// -5 if illegal amount bigger then amount in stock
     }
     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 (SalesManager.getInstance().editSale(saleId, amount, dueDate))
     {
         return(0);
     }
     return(-9);//-9 database eror
 }
Example #20
0
 public Boolean removeProductInStore(int productId, int storeId)
 {
     foreach (ProductInStore p in productsInStores)
     {
         if (p.getProductInStoreId() == productId && p.getStore().getStoreId() == storeId)
         {
             if (p.getIsActive() == 0)
             {
                 return(false);
             }
             if (SalesManager.getInstance().getSalesByProductInStoreId(p.getProductInStoreId()).Count > 0)
             {
                 return(false);
             }
             productInStoreDB.Remove(p);
             p.IsActive = 0;
             productInStoreDB.Add(p);
             return(true);
         }
     }
     return(false);
 }
Example #21
0
 public static Sale viewSalesBySaleId(int saleId)
 {
     return(SalesManager.getInstance().getSale(saleId));
 }
Example #22
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);
        }
Example #23
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);
        }
Example #24
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);
        }
Example #25
0
 public static void restartInstance()
 {
     instance = new SalesManager();
 }