/* * 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)); }
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 }
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); }
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 }
public Premissions getPremissions(string manager, int storeId) { Store s = StoreManagement.getInstance().getStore(storeId); User managerUser = UserManager.getInstance().getUser(manager); return(state.getPremissions(managerUser, s)); }
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); }
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 }
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 }
public virtual int removeNoDiscountPolicyOnCategoty(User session, int storeId, String category) { if (StoreManagement.getInstance().getStore(storeId) == null) { return(-1); } return(PurchasePolicyManager.getInstance().removeNoDiscountPolicyOnCategoty(storeId, category)); }
public virtual int removeAmountPolicyOnStore(User session, int storeId) { if (StoreManagement.getInstance().getStore(storeId) == null) { return(-1); } return(PurchasePolicyManager.getInstance().removeAmountPolicyOnStore(storeId)); }
public virtual int removeNoCouponPolicyOnProductInStore(User session, int storeId, int productInStoreId) { if (StoreManagement.getInstance().getStore(storeId) == null) { return(-1); } return(PurchasePolicyManager.getInstance().removeNoCouponPolicyOnProductInStore(productInStoreId)); }
public virtual int removeNoCouponPolicyOnCountry(User session, int storeId, string country) { if (StoreManagement.getInstance().getStore(storeId) == null) { return(-1); } return(PurchasePolicyManager.getInstance().removeNoCouponPolicyOnCountry(storeId, country)); }
internal LinkedList <StoreRole> getAllStoreRolesOfAUser(string username) { if (username == this.userName || state is Admin) { return(StoreManagement.getInstance().getAllStoreRolesOfAUser(username)); } return(null); }
public virtual int setNoDiscountPolicyOnProductInStore(User session, int storeId, int productInStoreId) { if (StoreManagement.getInstance().getStore(storeId) == null) { return(-1); } return(PurchasePolicyManager.getInstance().setNoDiscountPolicyOnProductInStore(productInStoreId)); }
public static StoreRole getStoreRole(Store store, User user) { if (store == null || user == null) { return(null); } return(StoreManagement.getInstance().getStoreRole(store, user)); }
public virtual int setNoCouponsPolicyOnStore(User session, int storeId) { if (StoreManagement.getInstance().getStore(storeId) == null) { return(-1); } return(PurchasePolicyManager.getInstance().setNoCouponsPolicyOnStore(storeId)); }
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)); }
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)); }
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()); }
/* * 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); }
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; } }
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); }
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 }
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); }
public static Store createStore(String name, User session) { return(StoreManagement.getInstance().addStore(name, session)); }
public override LinkedList <Purchase> viewStoreHistory(Store store, User session) { StoreRole sR = StoreManagement.getInstance().getStoreRole(store, session); return(sR.viewPurchasesHistory(session, store)); }
public static LinkedList <Store> viewStores() { return(StoreManagement.getInstance().getAllStore()); }
public LinkedList <StoreManager> getManagers() { return(StoreManagement.getInstance().getAllManagers(storeId)); }