Пример #1
0
        public virtual int addStoreManager(User session, Store s, String newManagerUserName)
        {
            User newManager = UserManager.getInstance().getUser(newManagerUserName);

            if (session == null)
            {
                return(-1);//-1 if user Not Login
            }
            if (s == null)
            {
                return(-3);//-3 if illegal store id
            }
            if (newManager == null)
            {
                return(-2);//-2 if new manager name not exist
            }
            StoreRole sr = StoreManagement.getInstance().getStoreRole(s, newManager);

            if (sr != null && (sr is StoreOwner || sr is StoreManager))
            {
                return(-6);//-6 already owner or manneger
            }
            if (sr != null && (sr is Customer))
            {
                StoreManagement.getInstance().removeStoreRole(s.getStoreId(), newManager.getUserName());
            }
            StoreRole m = new StoreManager(newManager, s, session.userName);

            if (StoreManagement.getInstance().addStoreRole(m, s.getStoreId(), newManager.getUserName()))
            {
                return(0);
            }
            return(-5);//-5 database error
        }
Пример #2
0
        public virtual int removeManagerPermission(User session, String permission, Store s, String managerUsername)
        {
            if (managerUsername == null)
            {
                return(-6); //manager name doesn't exists
            }
            User manager = UserManager.getInstance().getUser(managerUsername);

            if (permission == null)
            {
                return(-7); //No permissions
            }
            if (manager == null)
            {
                return(-6); //manager name doesnt exists
            }
            if (session == null)
            {
                return(-1); //user not logged in
            }
            if (s == null)
            {
                return(-3); //Illegal store id
            }
            StoreRole sR = StoreManagement.getInstance().getStoreRole(s, manager);

            if (correlate(manager, s, permission, sR, false))
            {
                return(0);
            }
            return(-7); //No permissions
        }
Пример #3
0
        public Premissions getPremissions(string manager, int storeId)
        {
            Store s           = StoreManagement.getInstance().getStore(storeId);
            User  managerUser = UserManager.getInstance().getUser(manager);

            return(state.getPremissions(managerUser, s));
        }
Пример #4
0
        public virtual Boolean addStoreOwner(User session, Store s, String newOwnerUserName)
        {
            User newOwner = UserManager.getInstance().getUser(newOwnerUserName);

            if (newOwner == null || s == null || session == null)
            {
                return(false);
            }
            StoreRole sr = StoreManagement.getInstance().getStoreRole(s, newOwner);

            if (sr != null && (sr is StoreOwner))
            {
                return(false);
            }
            if (sr != null && (sr is StoreManager))
            {
                removeStoreManager(session, s, newOwnerUserName);
            }
            if (sr != null && (sr is Customer))
            {
                StoreManagement.getInstance().removeStoreRole(s.getStoreId(), newOwner.getUserName());
            }
            StoreRole owner = new StoreOwner(newOwner, s, session.userName);
            Boolean   ans   = StoreManagement.getInstance().addStoreRole(owner, s.getStoreId(), newOwner.getUserName());

            if (ans)
            {
                NotificationPublisher.getInstance().signToCategory(this, NotificationPublisher.NotificationCategories.Purchase);
                NotificationPublisher.getInstance().signToCategory(this, NotificationPublisher.NotificationCategories.RaffleSale);
                NotificationPublisher.getInstance().signToCategory(this, NotificationPublisher.NotificationCategories.Store);
            }
            return(ans);
        }
Пример #5
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));
        }
Пример #6
0
        public virtual int addManagerPermission(User session, String permission, Store s, String managerUserName)
        {
            User manager = UserManager.getInstance().getUser(managerUserName);

            if (session == null)
            {
                return(-1);//-1 if user Not Login
            }
            if (permission == null)
            {
                return(-7);//-7 no such premition
            }
            if (manager == null)
            {
                return(-6);//-6 manager name doesn't exsist
            }
            if (s == null)
            {
                return(-3);// -3 if illegal store id
            }
            StoreRole sR = StoreManagement.getInstance().getStoreRole(s, manager);

            if (!(sR is StoreManager))
            {
                return(-8);
            }
            if (correlate(manager, s, permission, sR, true))
            {
                return(0);
            }
            return(-7);//-7 no such premition
        }
Пример #7
0
        public LinkedList <Tuple <int, String, String> > getManagersPermissionsInStore(int storeId)
        {
            if (StoreManagement.getInstance().getStore(storeId) == null)
            {
                return(null);
            }
            LinkedList <Tuple <int, String, String> > ans = new LinkedList <Tuple <int, String, String> >();
            StorePremissions SP;

            try
            {
                SP = this.privilegesOfaStore[storeId];
            }
            catch (Exception e)
            {
                return(ans);
            }
            Dictionary <string, Premissions> privileges = SP.getAllPrivileges();

            foreach (KeyValuePair <string, Premissions> entry in privileges)
            {
                foreach (KeyValuePair <string, Boolean> entry2 in entry.Value.getPrivileges())
                {
                    if (entry2.Value)
                    {
                        ans.AddFirst(new Tuple <int, String, String>(storeId, entry.Key, entry2.Key));
                    }
                }
            }
            return(ans);
        }
Пример #8
0
        public virtual int removeStoreManager(User session, Store s, String oldManager)
        {
            User session2 = UserManager.getInstance().getUser(oldManager);

            if (session == null)
            {
                return(-1);//-1 if user Not Login
            }
            if (s == null)
            {
                return(-3);//-3 if illegal store id
            }
            if (oldManager == null)
            {
                return(-6);// -6 old manager name doesn't exsist
            }
            StoreRole sr = StoreManagement.getInstance().getStoreRole(s, session2);

            if (sr != null && !(sr is StoreManager))
            {
                return(-7);
            }
            if (StoreManagement.getInstance().removeStoreRole(s.getStoreId(), oldManager))
            {
                NotificationPublisher.getInstance().removeAllNotificationSubscriptionsOfAStoreRole(this);
                return(0);
            }
            return(-5);//-5 database eror
        }
Пример #9
0
 public virtual int removeAmountPolicyOnStore(User session, int storeId)
 {
     if (StoreManagement.getInstance().getStore(storeId) == null)
     {
         return(-1);
     }
     return(PurchasePolicyManager.getInstance().removeAmountPolicyOnStore(storeId));
 }
Пример #10
0
 public virtual int setNoDiscountPolicyOnProductInStore(User session, int storeId, int productInStoreId)
 {
     if (StoreManagement.getInstance().getStore(storeId) == null)
     {
         return(-1);
     }
     return(PurchasePolicyManager.getInstance().setNoDiscountPolicyOnProductInStore(productInStoreId));
 }
Пример #11
0
 public virtual int removeNoDiscountPolicyOnCategoty(User session, int storeId, String category)
 {
     if (StoreManagement.getInstance().getStore(storeId) == null)
     {
         return(-1);
     }
     return(PurchasePolicyManager.getInstance().removeNoDiscountPolicyOnCategoty(storeId, category));
 }
Пример #12
0
 public virtual int removeNoCouponPolicyOnProductInStore(User session, int storeId, int productInStoreId)
 {
     if (StoreManagement.getInstance().getStore(storeId) == null)
     {
         return(-1);
     }
     return(PurchasePolicyManager.getInstance().removeNoCouponPolicyOnProductInStore(productInStoreId));
 }
Пример #13
0
 public virtual int removeNoCouponPolicyOnCountry(User session, int storeId, string country)
 {
     if (StoreManagement.getInstance().getStore(storeId) == null)
     {
         return(-1);
     }
     return(PurchasePolicyManager.getInstance().removeNoCouponPolicyOnCountry(storeId, country));
 }
Пример #14
0
 internal LinkedList <StoreRole> getAllStoreRolesOfAUser(string username)
 {
     if (username == this.userName || state is Admin)
     {
         return(StoreManagement.getInstance().getAllStoreRolesOfAUser(username));
     }
     return(null);
 }
Пример #15
0
 public virtual int setNoCouponsPolicyOnStore(User session, int storeId)
 {
     if (StoreManagement.getInstance().getStore(storeId) == null)
     {
         return(-1);
     }
     return(PurchasePolicyManager.getInstance().setNoCouponsPolicyOnStore(storeId));
 }
Пример #16
0
 public static StoreManagement getInstance()
 {
     if (instance == null)
     {
         instance = new StoreManagement();
     }
     return(instance);
 }
Пример #17
0
 public virtual int setAmountPolicyOnCountry(User session, int storeId, string country, int minAmount, int maxAmount)
 {
     if (StoreManagement.getInstance().getStore(storeId) == null || minAmount < 0 || maxAmount < 0)
     {
         return(-1);
     }
     return(PurchasePolicyManager.getInstance().setAmountPolicyOnCountry(storeId, country, minAmount, maxAmount));
 }
Пример #18
0
 public static StoreRole getStoreRole(Store store, User user)
 {
     if (store == null || user == null)
     {
         return(null);
     }
     return(StoreManagement.getInstance().getStoreRole(store, user));
 }
Пример #19
0
 public virtual int setAmountPolicyOnProductInStore(User session, int storeId, int productInStoreId, int minAmount, int maxAmount)
 {
     if (StoreManagement.getInstance().getStore(storeId) == null || minAmount < 0 || maxAmount < 0)
     {
         return(-1);
     }
     return(PurchasePolicyManager.getInstance().setAmountPolicyOnProductInStore(productInStoreId, minAmount, maxAmount));
 }
Пример #20
0
        public virtual int createStore(String storeName, User session)
        {
            Store     newStore = StoreManagement.getInstance().addStore(storeName, session);
            StoreRole sR       = new StoreOwner(session, newStore, session.getUserName());

            StoreManagement.getInstance().addStoreRole(sR, newStore.getStoreId(), session.getUserName());
            NotificationPublisher.getInstance().signToCategory(sR, NotificationPublisher.NotificationCategories.Purchase);
            NotificationPublisher.getInstance().signToCategory(sR, NotificationPublisher.NotificationCategories.RaffleSale);
            NotificationPublisher.getInstance().signToCategory(sR, NotificationPublisher.NotificationCategories.Store);
            return(newStore.getStoreId());
        }
Пример #21
0
        /*
         *   0 if user removed successfuly
         *  -2 user to remove is not exist
         *  -6 user who is owner or creator of store can not be removed
         */

        public int removeUser(string userName)
        {
            foreach (User u in users)
            {
                if (u.getUserName().Equals(userName))
                {
                    UDB.Remove(u);
                    LinkedList <Store> allStores = StoreManagement.getInstance().getAllStore();
                    foreach (Store s in allStores)
                    {
                        if (s.getStoreCreator().getUserName().Equals(u.getUserName()) && s.getIsActive() == 1)
                        {
                            return(-6);
                        }
                    }
                    //users.Remove(u);
                    u.setIsActive(false);
                    UDB.Add(u);
                    return(0);
                }
            }
            return(-2);
        }
Пример #22
0
        public void removeUserFromNotifications(string notification, int storeId)
        {
            Store     store = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR    = StoreRole.getStoreRole(store, this);

            switch (notification)
            {
            case "Store":
                NotificationPublisher.getInstance().removeFromCategory(sR, NotificationPublisher.NotificationCategories.Store);
                break;

            case "Purchase":
                NotificationPublisher.getInstance().removeFromCategory(sR, NotificationPublisher.NotificationCategories.Purchase);
                break;

            case "RaffleSale":
                NotificationPublisher.getInstance().removeFromCategory(sR, NotificationPublisher.NotificationCategories.RaffleSale);
                break;

            default:
                break;
            }
        }
Пример #23
0
        private Boolean removeAllRolesOfAUser(LinkedList <StoreRole> roles)
        {
            Boolean res = true;

            foreach (StoreRole sr in roles)
            {
                if (sr is StoreOwner)
                {
                    if (sr.getStore().getOwners().Count > 1)
                    {
                        res = res && StoreManagement.getInstance().removeStoreRole(sr.getStore().getStoreId(), sr.getUser().getUserName());
                    }
                    else
                    {
                        throw new Exception("something went seriously wrong");  // in the interval between the call to the safety check to now, something occured
                    }
                }
                else
                {
                    res = res && StoreManagement.getInstance().removeStoreRole(sr.getStore().getStoreId(), sr.getUser().getUserName());
                }
            }
            return(res);
        }
Пример #24
0
        public virtual int removeStoreOwner(User session, Store s, String ownerToDelete)
        {
            User      oldOwner = UserManager.getInstance().getUser(ownerToDelete);
            StoreRole sR2      = StoreRole.getStoreRole(s, oldOwner);

            if (ownerToDelete == user.getUserName())
            {
                return(-10);//-10 can't remove himself
            }
            if (!(sR2 is StoreOwner))
            {
                return(-11);//-11 not a owner
            }
            if (s.getStoreCreator().getUserName().Equals(ownerToDelete))
            {
                return(-12);//-12 if dealet creator
            }
            if (StoreManagement.getInstance().removeStoreRole(s.getStoreId(), ownerToDelete))
            {
                NotificationPublisher.getInstance().removeAllNotificationSubscriptionsOfAStoreRole(this);
                return(0);
            }
            return(-9);//-9 database eror
        }
Пример #25
0
 public static void restartInstance()
 {
     instance = new StoreManagement();
 }
Пример #26
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);
        }
Пример #27
0
        public override LinkedList <Purchase> viewStoreHistory(Store store, User session)
        {
            StoreRole sR = StoreManagement.getInstance().getStoreRole(store, session);

            return(sR.viewPurchasesHistory(session, store));
        }
Пример #28
0
 public static Store createStore(String name, User session)
 {
     return(StoreManagement.getInstance().addStore(name, session));
 }
Пример #29
0
 public static LinkedList <Store> viewStores()
 {
     return(StoreManagement.getInstance().getAllStore());
 }
Пример #30
0
 public LinkedList <StoreManager> getManagers()
 {
     return(StoreManagement.getInstance().getAllManagers(storeId));
 }