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 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 }