예제 #1
0
        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);
                }
            }
        }
예제 #2
0
 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);
 }
예제 #3
0
 public override Boolean removeDiscount(User session, ProductInStore p)
 {
     if (premissions.checkPrivilege(p.getStore().getStoreId(), session.getUserName(), "removeDiscount"))
     {
         return(base.removeDiscount(session, p));
     }
     return(false);
 }
예제 #4
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
 }
예제 #5
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);
        }
예제 #6
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);
 }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
0
        public ProductInStore addProductInStore(Product product, Store store, int quantity, double price, string category)
        {
            ProductInStore newProduct;

            lock (this)
            {
                newProduct = new ProductInStore(getNextProductInStoreId(), category, product, price, quantity, store);
            }
            if (productsInStores.Count > 0)
            {
                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);
        }