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 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); }
private StoreManagement() { SDB = new StoreDB(configuration.DB_MODE); SRDDB = new StoreRoleDictionaryDB(configuration.DB_MODE); stores = SDB.Get(); archive = new Dictionary <int, Dictionary <String, StoreRole> >(); LinkedList <Tuple <int, String, String, String, String> > temp = SRDDB.Get(); foreach (Tuple <int, String, String, String, String> t in temp) { StoreRole sr = null; if (t.Item3 == "Manager") { sr = new StoreManager(UserManager.getInstance().getUser(t.Item2), getStore(t.Item1), t.Item4, t.Item5); } else if (t.Item3 == "Owner") { sr = new StoreOwner(UserManager.getInstance().getUser(t.Item2), getStore(t.Item1), t.Item4, t.Item5); } else if (t.Item3 == "Customer") { sr = new Customer(UserManager.getInstance().getUser(t.Item2), getStore(t.Item1), "customer"); } try { archive.Add(t.Item1, new Dictionary <String, StoreRole>()); archive[t.Item1].Add(t.Item2, sr); } catch (Exception) { archive[t.Item1].Add(t.Item2, sr); }; } storeIndex = currIndex(); }
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 void sendMessageTORaffleWinner(int saleId) { Sale s = SalesManager.getInstance().getSale(saleId); ProductInStore p = ProductManager.getInstance().getProductInStore(s.ProductInStoreId); LinkedList <RaffleSale> relevant = new LinkedList <RaffleSale>(); double realPrice = p.price; double acc = 0; foreach (RaffleSale rs in raffleSales) { if (rs.SaleId == saleId) { acc += rs.Offer; relevant.AddLast(rs); } } if (acc == realPrice) { int index = 1; Random rand = new Random(); int winner = rand.Next(1, (int)realPrice); RaffleSale winnerS = null; foreach (RaffleSale r in relevant) { if (winner <= r.Offer + index && winner >= index) { string message = r.UserName + " WON THE RAFFLE SALE ON PRODUCT: " + getProductNameFromSaleId(r.SaleId); NotificationPublisher.getInstance().publish(NotificationPublisher.NotificationCategories.RaffleSale, message, p.getStore().storeId); StoreRole sR = StoreRole.getStoreRole(p.getStore(), UserManager.getInstance().getUser(r.UserName)); NotificationPublisher.getInstance().removeAllNotificationSubscriptionsOfAStoreRole(sR); //NotificationManager.getInstance().notifyUser(r.UserName, message); winnerS = r; break; } else { index += (int)r.Offer; } } if (winnerS != null) { RSDB.Remove(winnerS); raffleSales.Remove(winnerS); relevant.Remove(winnerS); } foreach (RaffleSale r in relevant) { string message = r.UserName + " LOST THE RAFFLE SALE ON PRODUCT: " + getProductNameFromSaleId(r.SaleId); NotificationPublisher.getInstance().publish(NotificationPublisher.NotificationCategories.RaffleSale, message, p.getStore().storeId); StoreRole sR = StoreRole.getStoreRole(p.getStore(), UserManager.getInstance().getUser(r.UserName)); NotificationPublisher.getInstance().removeAllNotificationSubscriptionsOfAStoreRole(sR); //NotificationManager.getInstance().notifyUser(r.UserName, message); RSDB.Remove(winnerS); raffleSales.Remove(r); } } }
public virtual Premissions getPremissions(User manager, Store s) { StoreRole sR = StoreRole.getStoreRole(s, manager); if (sR != null) { return(sR.getPremissions(manager, s)); } return(null); }
public Boolean addRaffleSale(int saleId, String userName, double offer, String dueDate) { RaffleSale toAdd = new RaffleSale(saleId, userName, offer, dueDate); ProductInStore pis = ProductManager.getInstance().getProductInStore(SalesManager.getInstance().getSale(saleId).ProductInStoreId); StoreRole sR = StoreRole.getStoreRole(pis.store, UserManager.getInstance().getUser(userName)); NotificationPublisher.getInstance().signToCategory(sR, NotificationPublisher.NotificationCategories.RaffleSale); RSDB.Add(toAdd); raffleSales.AddLast(toAdd); return(true); }
public Boolean addStoreRole(StoreRole newPremissions, int storeId, string userName) { if (!archive.ContainsKey(storeId)) { archive.Add(storeId, new Dictionary <string, StoreRole>()); } if (archive[storeId].ContainsKey(userName)) { return(false); } Tuple <int, String, String, String, String> t = new Tuple <int, String, String, String, String>(storeId, userName, newPremissions.type, newPremissions.addedby, newPremissions.dateAdded); SRDDB.Add(t); archive[storeId].Add(userName, newPremissions); return(true); }
public Boolean updateStoreRole(StoreRole newPremissions, int storeId, string userName) { if (!archive.ContainsKey(storeId)) { return(false); } if (archive[storeId].ContainsKey(userName)) { Tuple <int, String, String, String, String> t = new Tuple <int, String, String, String, String>(storeId, userName, "", "", ""); SRDDB.Remove(t); archive[storeId].Remove(userName); t = new Tuple <int, String, String, String, String>(storeId, userName, newPremissions.type, newPremissions.addedby, newPremissions.dateAdded); SRDDB.Add(t); archive[storeId].Add(userName, newPremissions); return(true); } return(false); }
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; } }
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 override LinkedList <Purchase> viewStoreHistory(Store store, User session) { StoreRole sR = StoreManagement.getInstance().getStoreRole(store, session); return(sR.viewPurchasesHistory(session, store)); }
public Boolean correlate(User session, Store s, String permission, StoreRole sR, Boolean allow) { String userName = session.getUserName(); switch (permission) { case "addProductInStore": getStorePremissions(s).addProductInStore(userName, allow); //sR.getPremissions(session,s).addProductInStore(allow); return(true); case "editProductInStore": getStorePremissions(s).editProductInStore(userName, allow); //sR.getPremissions(session, s).editProductInStore(allow); return(true); case "removeProductFromStore": getStorePremissions(s).removeProductFromStore(userName, allow); //sR.getPremissions(session, s).removeProductFromStore(allow); return(true); case "addStoreManager": getStorePremissions(s).addStoreManager(userName, allow); //sR.getPremissions(session, s).addStoreManager(allow); return(true); case "removeStoreManager": getStorePremissions(s).removeStoreManager(userName, allow); //sR.getPremissions(session, s).removeStoreManager(allow); return(true); case "addManagerPermission": getStorePremissions(s).addManagerPermission(userName, allow); //sR.getPremissions(session, s).addManagerPermission(allow); return(true); case "removeManagerPermission": getStorePremissions(s).removeManagerPermission(userName, allow); //sR.getPremissions(session, s).removeManagerPermission(allow); return(true); case "viewPurchasesHistory": getStorePremissions(s).viewPurchasesHistory(userName, allow); //sR.getPremissions(session, s).viewPurchasesHistory(allow); return(true); case "removeSaleFromStore": getStorePremissions(s).removeSaleFromStore(userName, allow); ///sR.getPremissions(session, s).removeSaleFromStore(allow); return(true); case "editSale": getStorePremissions(s).editSale(userName, allow); //sR.getPremissions(session, s).editSale(allow); return(true); case "addSaleToStore": getStorePremissions(s).addSaleToStore(userName, allow); //sR.getPremissions(session, s).addSaleToStore(allow); return(true); case "addDiscount": getStorePremissions(s).addDiscount(userName, allow); //sR.getPremissions(session, s).addDiscount(allow); return(true); case "addNewCoupon": getStorePremissions(s).addNewCoupon(userName, allow); //sR.getPremissions(session, s).addNewCoupon(allow); return(true); case "removeDiscount": getStorePremissions(s).removeDiscount(userName, allow); //sR.getPremissions(session, s).removeDiscount(allow); return(true); case "removeCoupon": getStorePremissions(s).removeCoupon(userName, allow); //sR.getPremissions(session, s).removeCoupon(allow); return(true); case "changePolicy": getStorePremissions(s).changePolicy(userName, allow); //sR.getPremissions(session, s).changePolicy(allow); return(true); case "getPremissions": return(true); case "addStoreOwner": return(false); case "removeStoreOwner": return(false); default: return(false); } }