Exemplo n.º 1
0
        /*
         * return :
         *          0 if user removed successfuly
         *          -2 user to remove is not exist
         *          -3 user to remove allready removed
         *          -4 user cannot remove himself
         *          -5 user who has raffle sale can not be removed
         *          -6 user who is owner or creator of store can not be removed
         */


        public override int removeUser(User session, string userDeleted)
        {
            User userToDelete = UserManager.getInstance().getUser(userDeleted);

            if (userToDelete == null)
            {
                return(-2);
            }
            if (!userToDelete.getIsActive())
            {
                return(-3);
            }
            if (userToDelete.getUserName() == session.getUserName())
            {
                return(-4);
            }
            if (RaffleSalesManager.getInstance().getAllRaffleSalesByUserName(userDeleted).Count > 0)
            {
                return(-5);
            }
            LinkedList <StoreRole> roles = StoreManagement.getInstance().getAllStoreRolesOfAUser(userDeleted);

            if (checkLoneOwnerOrCreator(roles))
            {
                return(-6);
            }
            removeAllRolesOfAUser(roles);
            return(UserManager.getInstance().removeUser(userDeleted));
        }
Exemplo n.º 2
0
 public static RaffleSalesManager getInstance()
 {
     if (instance == null)
     {
         instance = new RaffleSalesManager();
     }
     return(instance);
 }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
 public static void restartInstance()
 {
     instance = new RaffleSalesManager();
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }