Ejemplo n.º 1
0
 public void signAndAddOwner(int storeId, string owner, string pending, StoreRole toAdd)
 {
     //SqlConnection connection = Connector.getInstance().getSQLConnection();
     lock (connection)
     {
         connection.Open();
         using (var transaction = connection.BeginTransaction())
         {
             try
             {
                 ownerTrans = transaction;
                 signContract(storeId, owner, pending, true);
                 removePendingOwner(storeId, pending);
                 addStoreRole(toAdd);
                 transaction.Commit();
                 connection.Close();
             }
             catch (Exception e)
             {
                 connection.Close();
                 ownerTrans = null;
                 throw e;
             }
         }
         ownerTrans = null;
     }
 }
Ejemplo n.º 2
0
        public void addManager(int storeid, string username,
                               bool editProduct, bool editDiscount, bool editPolicy, Session session)
        {
            SubscribedUser toAdd = DBSubscribedUser.getInstance().getSubscribedUser(username);

            if (toAdd == null)
            {
                throw new DoesntExistException("no such username");
            }
            Store store = DBStore.getInstance().getStore(storeid);

            if (store == null)
            {
                throw new DoesntExistException("no such store");
            }
            StoreRole sr = store.getStoreRole(session.getSubscribedUser());

            if (sr.getStore() != store)
            {
                throw new RoleException("this user can't appoint to this store");
            }
            Permissions permissions = new Permissions(editProduct, editDiscount, editPolicy);

            sr.addManager(toAdd, permissions);
        }
Ejemplo n.º 3
0
        public void init()
        {
            storeDB.init();
            productDB.init();
            DBSubscribedUser.getInstance().cleanDB();
            session1 = new Session();
            session1.register("eyal", "123");

            session2 = new Session();
            session2.register("bar", "123");

            session3 = new Session();
            session3.register("etay", "123");

            session1.login("eyal", "123");
            session2.login("bar", "123");
            session3.login("etay", "123");

            store = session1.createStore("mystore", "a store");

            per  = new Permissions(true, true, true);
            per2 = new Permissions(false, false, false);

            sr = session1.getSubscribedUser().getStoreRole(store);
            sr.addManager(session2.getSubscribedUser(), per);
            sr.addManager(session3.getSubscribedUser(), per2);

            sr1 = session2.getSubscribedUser().getStoreRole(store);
            sr2 = session3.getSubscribedUser().getStoreRole(store);

            p  = new Product("product", "cat", 10, 0, 10, store);
            p1 = new Product("product1", "cat", 10, 0, 10, store);
        }
Ejemplo n.º 4
0
        public void TestInitialize()
        {
            MarketSystem.initTestWitOutRead();
            session1 = new Session();
            string pass = DomainBridge.getInstance().encryptPassword("123");

            session1.register("eyal", pass);

            session2 = new Session();
            session2.register("bar", pass);

            session3 = new Session();
            session3.register("etay", pass);

            session1.login("eyal", "123");
            session2.login("bar", "123");
            session3.login("etay", "123");

            store = session1.createStore("mystore", "a store");
            sr    = session1.getSubscribedUser().getStoreRole(store);
            p     = new Product("product", "cat", 10, 0, 10, store);
            p1    = new Product("product1", "cat", 10, 0, 10, store);

            per = new Permissions(true, true, true);
        }
Ejemplo n.º 5
0
 public void TestInitialize()
 {
     DBStore.getInstance().DBinit();
     s  = new Store("store", "store");
     su = new SubscribedUser("u", "u", new ShoppingBasket());
     sr = new StoreOwner(null, su, s);
 }
Ejemplo n.º 6
0
 public void addStoreRole(StoreRole toAdd)
 {
     if (toAdd is StoreOwner)
     {
         numOfOwners++;
     }
     roles.Add(toAdd);
 }
Ejemplo n.º 7
0
 public void removeStoreRole(StoreRole toRemove)
 {
     if (toRemove is StoreOwner)
     {
         numOfOwners--;
     }
     roles.Remove(toRemove);
 }
Ejemplo n.º 8
0
 public void TestInitialize()
 {
     MarketSystem.initTestWitOutRead();
     s = new Store("store", "store");
     DBStore.getInstance().addStore(s);
     su = new SubscribedUser("u", "u", new ShoppingBasket());
     sr = new StoreOwner(null, su, s);
 }
Ejemplo n.º 9
0
 public void addStoreRoleFromInitOwner(StoreRole toAdd)
 {
     if (toAdd is StoreOwner)
     {
         numOfOwners++;
         DBStore.getInstance().addownerNumerByOne(storeId, numOfOwners);
     }
     roles.Add(toAdd);
 }
Ejemplo n.º 10
0
        public void ViewSlaeInStoreAsMannegerWithPremition()
        {
            zahiOwner.addManagerPermission(zahi, "addSaleToStore", store, "aviad");
            aviadManeger = new StoreManager(aviad, store);
            int saleId = aviadManeger.addSaleToStore(aviad, store, cola.getProductInStoreId(), 1, 1, "20/5/2018");
            LinkedList <Sale> saleList = store.getAllSales();

            Assert.AreEqual(saleList.Count, 1);
        }
Ejemplo n.º 11
0
        public void removeStoreRole(Store store, SubscribedUser user)
        {
            StoreRole sr = getStoreRole(store, user);

            if (sr != null)
            {
                storeRole.Remove(sr);
            }
        }
Ejemplo n.º 12
0
        public int addProduct(string productName, string productCategory, int price, int rank, int quantityLeft, int storeID, Session session)
        {
            DBStore   storeDB = DBStore.getInstance();
            Store     store   = storeDB.getStore(storeID);
            StoreRole sr      = store.getStoreRole(session.getSubscribedUser());
            Product   product = new Product(productName, productCategory, price, rank, quantityLeft, store);

            sr.addProduct(product);
            return(product.getProductID());
        }
Ejemplo n.º 13
0
        public Boolean removeDiscount(ProductInStore p, Store s, User session)
        {
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(false);
            }
            return(sR.removeDiscount(session, p));
        }
Ejemplo n.º 14
0
        public Boolean addDiscount(ProductInStore p, int percentage, String dueDate, User session, Store s)
        {
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(false);
            }
            return(sR.addDiscount(session, p, percentage, dueDate));
        }
Ejemplo n.º 15
0
        public Boolean addCouponDiscount(User session, Store s, String couponId, ProductInStore p, int percentage, String dueDate)
        {
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(false);
            }
            return(sR.addNewCoupon(session, couponId, p, percentage, dueDate));
        }
Ejemplo n.º 16
0
        public void RemoveMangerFromStoreAsMannegerWithPremition()
        {
            zahiOwner.addStoreManager(zahi, store, "niv");
            zahiOwner.addManagerPermission(zahi, "removeStoreManager", store, "aviad");
            aviadManeger = new StoreManager(aviad, store);
            int temp = aviadManeger.removeStoreManager(aviad, store, "niv");

            Assert.IsTrue(temp > -1);
            Assert.AreEqual(store.getManagers().Count, 1);
        }
Ejemplo n.º 17
0
        public Boolean removeCoupon(Store s, User session, String couponId)
        {
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(false);
            }
            return(sR.removeCoupon(session, s, couponId));
        }
Ejemplo n.º 18
0
 public void removeStoreRole(StoreRole toRemove)
 {
     if (toRemove is StoreOwner)
     {
         numOfOwners--;
         DBStore.getInstance().removeOwnerNumerByOne(storeId, numOfOwners);
     }
     roles.Remove(toRemove);
     DBStore.getInstance().removeStoreRole(toRemove);
 }
Ejemplo n.º 19
0
        public void removeUser(String user)
        {
            if (Equals(user, "u1"))
            {
                throw new UserException("admin cannot be removed");
            }
            SubscribedUser subscribedUser = DBSubscribedUser.getInstance().getSubscribedUser(user);

            if (subscribedUser == null)
            {
                throw new UserException("user to be removed does not exist");
            }
            try
            {
                Session session = dbSession.getSessionOfSubscribedUser(subscribedUser);
                if (session != null)
                {
                    if (session.getState() is LoggedIn)
                    {
                        session.logout();
                        session.setSubscribedUser(null);
                    }
                }
            }
            catch (DoesntExistException) { }
            LinkedList <StoreRole> toDelete      = new LinkedList <StoreRole>();
            LinkedList <Store>     toDeleteStore = new LinkedList <Store>();

            foreach (StoreRole role in subscribedUser.getStoreRoles())
            {
                role.removeAllAppointedBy();
                Store          store = role.getStore();
                SubscribedUser appointedBySubscribedUser = role.getAppointedBy();
                toDelete.AddFirst(role);
                if (appointedBySubscribedUser != null)
                {
                    StoreRole appointedByStoreRole = store.getStoreRole(role.getAppointedBy());
                    store.removeStoreRole(role);
                    appointedByStoreRole.removeRoleAppointedByMe(role);
                }
                if (role is StoreOwner && role.getStore().getNumberOfOwners() == 1)
                {
                    closeStore(role.getStore());
                }
                //DBStore.getInstance().removeStoreRole(role);
            }
            foreach (StoreRole sr in toDelete)
            {
                DBStore.getInstance().removeStoreRole(sr);
                subscribedUser.removeStoreRole(sr);
                sr.getStore().removeStoreRole(sr);
            }

            dbSubscribedUser.remove(subscribedUser);
        }
Ejemplo n.º 20
0
        public int setAmountPolicyOnProductInStore(User session, int storeId, int productInStoreId, int minAmount, int maxAmount)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.setAmountPolicyOnProductInStore(session, storeId, productInStoreId, minAmount, maxAmount));
        }
Ejemplo n.º 21
0
        //req 3.4 c

        /*
         *       return:
         *           0 on sucess
         *          -1 if user Not Login
         *          -2 if Store Name already exist
         *          -3 if illegal store id
         *          -4 if don't have premition
         *          -5 database eror
         *          -6 manager name doesn't exsist
         *          -7 no such premition
         *          -8 the mannager to add is not a manager in this store
         *          -10 can't remove himself
         */
        public int addManagerPermission(String permission, int storeId, String managerToAdd, User session)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-4); //-4 if don't have premition
            }
            return(sR.addManagerPermission(session, permission, s, managerToAdd));
        }
Ejemplo n.º 22
0
        //req 3.4 d
        public int removeManagerPermission(String permission, int storeId, String manager, User session)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-4); //-4 if you do not have permissions
            }
            return(sR.removeManagerPermission(session, permission, s, manager));
        }
Ejemplo n.º 23
0
        /*
         *        return:
         *           0  on sucess the SaleID
         *          -1 if user Not Login
         *          -4 if don't have premition
         *          -6 if illegal store id
         *          -8 if illegal sale id
         *          -9 database eror
         */
        public int removeSaleFromStore(User session, int storeId, int saleId)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-4);
            }
            return(sR.removeSaleFromStore(session, s, saleId));
        }
Ejemplo n.º 24
0
        public int removeNoCouponPolicyOnCountry(User session, int storeId, string country)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.removeNoCouponPolicyOnCountry(session, storeId, country));
        }
Ejemplo n.º 25
0
        /*
         * return:
         *           0  on sucess the SaleID
         *          -1 if user Not Login
         *          -4 if don't have premition
         *          -5 if illegal amount bigger then amount in stock
         *          -6 if illegal store id
         *          -7 if illegal price
         *          -8 if illegal sale id
         *          -9 database eror
         *          -10 due date not good
         *          -12 if illegal amount
         */
        public int editSale(User session, int storeId, int saleId, int amount, String dueDate)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-4);//-4 if don't have premition
            }
            return(sR.editSale(session, s, saleId, amount, dueDate));
        }
Ejemplo n.º 26
0
        public int removeNoCouponPolicyOnProductInStore(User session, int storeId, int productInStoreId)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.removeNoCouponPolicyOnProductInStore(session, storeId, productInStoreId));
        }
Ejemplo n.º 27
0
        public int removeNoDiscountPolicyOnStore(User session, int storeId)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.removeNoDiscountPolicyOnStore(session, storeId));
        }
Ejemplo n.º 28
0
        public int setNoCouponsPolicyOnStore(User session, int storeId)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.setNoCouponsPolicyOnStore(session, storeId));
        }
Ejemplo n.º 29
0
        public int setNoDiscountPolicyOnCountry(User session, int storeId, String country)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.setNoDiscountPolicyOnCategoty(session, storeId, country));
        }
Ejemplo n.º 30
0
        public int setAmountPolicyOnCountry(User session, int storeId, string country, int minAmount, int maxAmount)
        {
            Store     s  = StoreManagement.getInstance().getStore(storeId);
            StoreRole sR = StoreRole.getStoreRole(s, session);

            if (sR == null)
            {
                return(-1);
            }
            return(sR.setAmountPolicyOnCountry(session, storeId, country, minAmount, maxAmount));
        }