コード例 #1
0
        private void checkPolicysAndUpdatePrice(UserCart uc, Discount d, string country, int typeOfSale)
        {
            string restrictions = d.Restrictions;

            if (restrictions.Equals(""))
            {
                uc.PriceAfterDiscount -= uc.PriceAfterDiscount * (d.Percentage / 100);
            }
            else
            {
                if (restrictions.Contains("TOS") && restrictions.Contains("COUNTRY"))
                {
                    if (restrictions.Contains(typeOfSale.ToString()) && restrictions.Contains(country))
                    {
                        uc.PriceAfterDiscount -= uc.PriceAfterDiscount * (d.Percentage / 100);
                    }
                }
                else if (restrictions.Contains("TOS"))
                {
                    if (restrictions.Contains(typeOfSale.ToString()))
                    {
                        uc.PriceAfterDiscount -= uc.PriceAfterDiscount * (d.Percentage / 100);
                    }
                }
                else if (restrictions.Contains("COUNTRY"))
                {
                    if (restrictions.Contains(country))
                    {
                        uc.PriceAfterDiscount -= uc.PriceAfterDiscount * (d.Percentage / 100);
                    }
                }
            }
        }
コード例 #2
0
 private Boolean checkValidAmount(Sale sale, UserCart cart)
 {
     if (cart.getAmount() <= sale.Amount)
     {
         return(true);
     }
     return(false);
 }
コード例 #3
0
 public Boolean payForProduct(string creditCard, User session, UserCart product)
 {
     if (creditCard == null || creditCard == "" || session == null || product == null)
     {
         return(false);
     }
     return(true);
 }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
0
        public void checkAndUpdateCouponByPolicy(UserCart uc, Coupon c, string country, int typeOfSale)
        {
            if (DateTime.Compare(DateTime.Parse(c.DueDate), DateTime.Now) < 0)
            {
                return;
            }
            string restrictions = c.Restrictions;

            if (restrictions.Equals(""))
            {
                uc.PriceAfterDiscount -= uc.PriceAfterDiscount * (c.Percentage / 100);
            }
            else
            {
                if (restrictions.Contains("TOS") && restrictions.Contains("COUNTRY"))
                {
                    if (restrictions.Contains(typeOfSale.ToString()) && restrictions.Contains(country))
                    {
                        uc.PriceAfterDiscount -= uc.PriceAfterDiscount * (c.Percentage / 100);
                    }
                }
                else if (restrictions.Contains("TOS"))
                {
                    if (restrictions.Contains(typeOfSale.ToString()))
                    {
                        uc.PriceAfterDiscount -= uc.PriceAfterDiscount * (c.Percentage / 100);
                    }
                }
                else if (restrictions.Contains("COUNTRY"))
                {
                    if (restrictions.Contains(country))
                    {
                        uc.PriceAfterDiscount -= uc.PriceAfterDiscount * (c.Percentage / 100);
                    }
                }
            }
        }