示例#1
0
        public String checkout(String address, String creditCard)
        {
            String res = "";
            int    sum = 0;

            foreach (KeyValuePair <Product, int> entry in productList)
            {
                if (entry.Key.getQuantityLeft() > entry.Value)
                {
                    sum = entry.Key.getPrice() * entry.Value;
                    Boolean isOk = PaymentService.getInstance().checkOut(creditCard, sum);
                    if (isOk)
                    {
                        entry.Key.setQuantityLeft(entry.Key.getQuantityLeft() - entry.Value);

                        if (DeliveryService.getInstance().sendToUser(address, entry.Key) == false)
                        {
                            entry.Key.setQuantityLeft(entry.Key.getQuantityLeft() + entry.Value);
                            throw new CartException("Cannot deliver " + entry.Key.getProductName());
                        }
                    }
                    else
                    {
                        throw new CartException("Payment for " + entry.Key.getProductName());
                    }
                }
                else
                {
                    throw new CartException("Not enough quantity of " + entry.Key.getProductName());
                }
            }
        }
示例#2
0
 public static DeliveryService getInstance()
 {
     if (instance == null)
     {
         instance = new DeliveryService();
     }
     return(instance);
 }
示例#3
0
        private void init()
        {
            SubscribedUser admin = new SubscribedUser("Admin", "1234", new ShoppingBasket());

            DBSubscribedUser.getInstance().register(admin);
            PaymentService.getInstance().connectToSystem();
            DeliveryService.getInstance().connectToSystem();
            ConsistencySystem.getInstance().connectToSystem();
        }
示例#4
0
 public static void initWitOutRead()
 {
     DBProduct.getInstance().init();
     DBSession.getInstance().init();
     DBDiscount.getInstance().init();
     DBSubscribedUser.getInstance().init();
     DBStore.getInstance().init();
     DBSubscribedUser.getInstance().updateShoppingBasket();
     DBNotifications.getInstance().init();
     PaymentService.getInstance().connectToSystem();
     DeliveryService.getInstance().connectToSystem();
     ConsistencySystem.getInstance().connectToSystem();
     NotificationsBridge.getInstance().setObserver(DomainBridge.getInstance());
 }
示例#5
0
 public static void initTestWitOutRead()
 {
     testsMode = true;
     SystemLogger.configureLogs();
     DBProduct.getInstance().initTests();
     DBSession.getInstance().initTests();
     DBDiscount.getInstance().initTests();
     DBSubscribedUser.getInstance().initTests();
     DBStore.getInstance().initTests();
     DBNotifications.getInstance().initTests();
     PaymentService.getInstance().connectToSystem();
     DeliveryService.getInstance().connectToSystem();
     ConsistencySystem.getInstance().connectToSystem();
     NotificationsBridge.getInstance().setObserver(DomainBridge.getInstance());
     DomainBridge.getInstance().addAdmin("u1", "123");
 }
示例#6
0
        //public void addCoupon(string coupon, int storeID)
        //{
        //    ShoppingCart sc = getShoppingCartByID(storeID);
        //    if (sc != null)
        //        sc.addStoreCoupon(coupon);
        //    else
        //        throw new DoesntExistException("no such store ID in Shopping basket");
        //}

        //public void removeCoupon(int storeID)
        //{
        //    ShoppingCart sc = getShoppingCartByID(storeID);
        //    if (sc != null)
        //        sc.removeCoupon();
        //    else
        //        throw new DoesntExistException("no such store ID in Shopping basket");
        //}

        public int purchaseBasket(string address, string creditcard, string month, string year, string holder, string cvv)
        {
            //    foreach (KeyValuePair<int, ShoppingCart> pair1 in shoppingCarts)
            //    {
            //        ShoppingCart cart = pair1.Value;
            //        Dictionary<Product, int> productsInCart = cart.getProductsInCarts();
            //        foreach (KeyValuePair<Product, int> pair2 in productsInCart)
            //        {
            //            Product product = pair2.Key;
            //            int amount = pair2.Value;
            //            if (product.getQuantityLeft() < amount)
            //            {

            //                throw new IllegalAmountException("Error: Cannot complete purchase- " + product.getProductName() + " does not have enough quantity left");
            //            }
            //            product.decQuantityLeft(amount);
            //        }

            //    }

            int resultPay     = PaymentService.getInstance().checkOut(address, creditcard, month, year, holder, cvv);
            int resultDeliver = -1;


            if (resultPay != -1)
            {
                resultDeliver = DeliveryService.getInstance().sendToUser(address, creditcard, month, year, holder, cvv);

                if (resultDeliver == -1)
                {
                    int res2 = PaymentService.getInstance().cancelPayment(resultPay + "");

                    throw new CartException("Delivery FAILED");
                }
                if (username != null)
                {
                    foreach (KeyValuePair <int, ShoppingCart> pair1 in shoppingCarts)
                    {
                        ShoppingCart cart = pair1.Value;
                        Dictionary <Product, int> productsInCart = cart.getProductsInCarts();
                        foreach (KeyValuePair <Product, int> pair2 in productsInCart)
                        {
                            Product product = pair2.Key;
                            int     amount  = pair2.Value;
                            if (product.getQuantityLeft() < amount)
                            {
                                throw new IllegalAmountException("Error: Cannot complete purchase- " + product.getProductName() + " does not have enough quantity left");
                            }
                            product.decQuantityLeft(amount);
                        }
                    }
                    DBSubscribedUser.getInstance().updateTablesAfterPurchase(username, shoppingCarts);
                }
            }
            else
            {
                throw new CartException("Payment FAILED");
            }
            //throw new SuccessPaymentExeption("OK");
            return(resultDeliver);
        }