Esempio n. 1
0
 public LinkedList <ProductInStore> getProductsInStore()
 {
     return(ProductManager.getInstance().getAllProductsInStore(storeId));
 }
Esempio n. 2
0
 public static LinkedList <Product> getProducts()
 {
     return(ProductManager.getInstance().getAllProducts());
 }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 public static void restartInstance()
 {
     instance = new ProductManager();
 }