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 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 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 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 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()); }
private void CheckFinishedRaffelSales(object source, ElapsedEventArgs e) { LinkedList <RaffleSale> raffleSalesToRemove = new LinkedList <RaffleSale>(); foreach (RaffleSale rs in raffleSales) { if (DateTime.Now.CompareTo(DateTime.Parse(rs.DueDate)) > 0) { string message = "the Raffle sale " + rs.SaleId + " has been canceled"; NotificationPublisher.getInstance().publish(NotificationPublisher.NotificationCategories.RaffleSale, message, rs.SaleId); //NotificationManager.getInstance().notifyUser(rs.UserName, message); raffleSalesToRemove.AddLast(rs); } } foreach (RaffleSale rs in raffleSalesToRemove) { RSDB.Remove(rs); raffleSales.Remove(rs); } }
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 }