public Admin() { dbStore = DBStore.getInstance(); dbSubscribedUser = DBSubscribedUser.getInstance(); dbSession = DBSession.getInstance(); dbComplaint = DBComplaint.getInstance(); }
public void removePolicyByID(int policyID) { PurchasePolicy p = findPolicyByID(policyID); policies.Remove(p); DBStore.getInstance().removePolicy(p, storeId); }
public void addStoreRoleFromInitOwner(StoreRole toAdd) { if (toAdd is StoreOwner) { numOfOwners++; DBStore.getInstance().addownerNumerByOne(storeId, numOfOwners); } roles.Add(toAdd); }
public ShoppingCart(int storeID) { productList = new Dictionary <Product, int>(); productsActualPrice = new Dictionary <Product, double>(); this.storeID = storeID; store = DBStore.getInstance().getStore(storeID); coupon = ""; }
public void updateStoreRole(SubscribedUser user) { string username = user.getUsername(); foreach (StoreRole sr in DBStore.getInstance().getAllStoreRoles(username)) { user.addStoreRole(sr); } }
private void setTotalPolicy(int newAmount, PurchasePolicy p) { if (newAmount < 0) { throw new ILLArgumentException("Total cart price can not be a negative number."); } p.setAmount(newAmount); DBStore.getInstance().setPolicy(p, storeId, newAmount); }
public void removeStoreRole(StoreRole toRemove) { if (toRemove is StoreOwner) { numOfOwners--; DBStore.getInstance().removeOwnerNumerByOne(storeId, numOfOwners); } roles.Remove(toRemove); DBStore.getInstance().removeStoreRole(toRemove); }
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); }
public void addComplexPurchasePolicy(int index1, int index2, string type) { PurchasePolicy p1 = policies.ElementAt(index1); PurchasePolicy p2 = policies.ElementAt(index2); ComplexPurchasePolicy complexPurchase = new ComplexPurchasePolicy(type, p1, p2); policies.Remove(p1); policies.Remove(p2); policies.AddLast(complexPurchase); DBStore.getInstance().addComplexPolicy(complexPurchase, storeId); }
public void updateShoppingBasket() { try { //SqlConnection connection = Connector.getInstance().getSQLConnection(); lock (connection) { connection.Open(); foreach (KeyValuePair <string, SubscribedUser> pair in users) { string username = pair.Key; SubscribedUser su = pair.Value; string sql = "SELECT * FROM BasketCart WHERE username=@username;"; var c2 = connection.Query <BasketCartEntry>(sql, new { username = username }); ShoppingBasket sb = su.getShoppingBasket(); if (Enumerable.Count(c2) > 0) { for (int i = 0; i < Enumerable.Count(c2); i++) { BasketCartEntry bc = c2.ElementAt(i); int storeID = bc.getStoreID(); sql = "SELECT * FROM CartProduct WHERE storeID=@storeID AND username=@username;"; var c3 = connection.Query <CartProductEntry>(sql, new { storeID, username }); for (int j = 0; j < Enumerable.Count(c3); j++) { CartProductEntry cp = c3.ElementAt(j); int productID = cp.getProductID(); int amount = cp.getAmount(); Product p = DBProduct.getInstance().getProductByID(productID); sb.addToCartNoDBUpdate(p, amount, storeID); } } } List <StoreRole> storeRoles = su.getStoreRoles(); foreach (StoreRole sr in DBStore.getInstance().getAllStoreRoles(username)) { if (sr.getUser().getUsername() == username) { storeRoles.Add(sr); } } } connection.Close(); } } catch (Exception e) { connection.Close(); } }
public void addTotalAmountPolicy(int minPrice) { if (hasTotalPricePolicy()) { throw new AlreadyExistException("Store can not have 2 total cart price - purchase policy."); } TotalPricePolicy p = new TotalPricePolicy(minPrice); policies.AddLast(p); DBStore.getInstance().addTotalPrice(p, storeId); }
public static void initWitOutRead() { DBProduct.getInstance().init(); DBSession.getInstance().init(); DBDiscount.getInstance().init(); DBSubscribedUser.getInstance().init(); DBStore.getInstance().init(); DBSubscribedUser.getInstance().updateShoppingBasket(); DBNotifications.getInstance().init(); PaymentService.getInstance().connectToSystem(); DeliveryService.getInstance().connectToSystem(); ConsistencySystem.getInstance().connectToSystem(); NotificationsBridge.getInstance().setObserver(DomainBridge.getInstance()); }
public void addOwner(SubscribedUser owner) { StoreRole newOwner = new StoreOwner(this.user, owner, store); if (store.getStoreRole(owner) != null) { throw new RoleException("user " + owner.getUsername() + " already have a role in store " + store.getStoreName()); } store.addStoreRole(newOwner); owner.addStoreRole(newOwner); appointedByMe.Add(newOwner); DBStore.getInstance().addStoreRole(newOwner); }
public void addManager(SubscribedUser manager, Permissions permissions) { StoreRole newManager = new StoreManager(this.user, store, manager, permissions); DBStore.getInstance().addStoreRole(newManager); if (store.getStoreRole(manager) != null) { throw new RoleException("user " + manager.getUsername() + " already have a role in store " + store.getStoreName()); } store.addStoreRole(newManager); manager.addStoreRole(newManager); appointedByMe.Add(newManager); }
public Store createStore(String storeName, String description, SubscribedUser sub) { if (storeName == "") { throw new IllegalNameException(); } Store store = new Store(storeName, description); StoreOwner owner = new StoreOwner(null, sub, store); store.addStoreRole(owner); sub.addStoreRole(owner); DBStore.getInstance().addStore(store); DBStore.getInstance().addStoreRole(owner); return(store); }
public Store(string storeName, string description) { this.storeId = DBStore.getInstance().getNextStoreID(); this.name = storeName; this.description = description; productList = new LinkedList <Product>(); roles = new List <StoreRole>(); numOfOwners = 0; active = true; discountList = new LinkedList <DiscountComponent>(); // invisibleDiscountList = new LinkedList<InvisibleDiscount>(); policies = new LinkedList <PurchasePolicy>(); contracts = new LinkedList <Contract>(); pendingOwners = new LinkedList <string>(); }
public static void initTestWitOutRead() { testsMode = true; SystemLogger.configureLogs(); DBProduct.getInstance().initTests(); DBSession.getInstance().initTests(); DBDiscount.getInstance().initTests(); DBSubscribedUser.getInstance().initTests(); DBStore.getInstance().initTests(); DBNotifications.getInstance().initTests(); PaymentService.getInstance().connectToSystem(); DeliveryService.getInstance().connectToSystem(); ConsistencySystem.getInstance().connectToSystem(); NotificationsBridge.getInstance().setObserver(DomainBridge.getInstance()); DomainBridge.getInstance().addAdmin("u1", "123"); }
public void checkBasket() { int numOfProducts = 0; Product productToRemove = null; foreach (KeyValuePair <int, ShoppingCart> pair1 in shoppingCarts) { ShoppingCart cart = pair1.Value; if (!cart.checkStorePolicy()) { throw new IllegalAmountException("The cart does not stand with store policies."); } Store store = DBStore.getInstance().getStore(cart.getStoreID()); Dictionary <Product, int> productsInCart = cart.getProductsInCarts(); foreach (KeyValuePair <Product, int> pair2 in productsInCart) { numOfProducts++; Product product = pair2.Key; int amount = pair2.Value; // store.checkPolicy(product, amount); if (product.getQuantityLeft() == 0) { productToRemove = product; break; } if (product.getQuantityLeft() < amount) { cart.changeQuantityOfProduct(product, product.getQuantityLeft()); throw new IllegalAmountException("Total quantity of product: " + product.getProductName() + " ID: " + product.getProductID() + "\n is larger than the quantity left in the store\nquantity has been set to maximum quantity left in store\nPlease checkout again"); } //product.decQuantityLeft(amount); } if (productToRemove != null) { removeFromCart(productToRemove.getProductID()); throw new IllegalAmountException("Prodcut: " + productToRemove.getProductName() + " ID: " + productToRemove.getProductID() + " has ZERO quantity left\n Product has been removed from cart\nPlease checkout again"); } } if (numOfProducts == 0) { throw new DoesntExistException("Checkout failed. there are no items in the basket for purchase."); } }
public void remove(SubscribedUser role) { StoreRole sr = role.getStoreRole(store); if (sr == null) { throw new RoleException("user " + role.getUsername() + " doesn't have a role in store " + store.getStoreName()); } if (sr.getAppointedBy() != this.userName) { throw new RoleException("Error: User " + userName.getUsername() + " didn't appoint " + role.getUsername()); } DBStore.getInstance().removeStoreRole(sr); role.removeStoreRole(sr); store.removeStoreRole(sr); }
public void addMaxAmountPolicy(int minAmount) { if (hasMaxPurchasePolicy()) { throw new AlreadyExistException("Store can not have 2 maximum amount purchase policy."); } MinAmountPurchase minPolicy = getMinPolicy(); if (minPolicy != null) { if (minPolicy.getAmount() < minAmount) { throw new AlreadyExistException("Max purchase policy can not be smaller than Min purchase policy."); } } MaxAmountPurchase p = new MaxAmountPurchase(minAmount); policies.AddLast(p); DBStore.getInstance().addMaxPolicy(p, storeId); }
public void removeUser(String user) { if (Equals(user, "admin")) { 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"); } Session session = dbSession.getSessionOfSubscribedUser(subscribedUser); if (session != null) { if (session.getState() is LoggedIn) { session.logout(); } } foreach (StoreRole role in subscribedUser.getStoreRoles()) { role.removeAllAppointedBy(); Store store = role.getStore(); SubscribedUser appointedBySubscribedUser = role.getAppointedBy(); if (appointedBySubscribedUser != null) { StoreRole appointedByStoreRole = store.getStoreRole(role.getAppointedBy()); store.removeStoreRole(appointedByStoreRole); appointedByStoreRole.removeRoleAppointedByMe(role); } if (role is StoreOwner && role.getStore().getNumberOfOwners() == 0) { closeStore(role.getStore()); } DBStore.getInstance().removeStoreRole(role); } session.setSubscribedUser(null); dbSubscribedUser.remove(subscribedUser); }
public void setMaxPurchasePolicy(int maxAmount, PurchasePolicy p) { PurchasePolicy min = getMinPolicy(); if (min == null) { p.setAmount(maxAmount); DBStore.getInstance().setPolicy(p, storeId, maxAmount); } else { if (min.getAmount() > maxAmount) { throw new ILLArgumentException("contradiction! maximum amount can not be smaller than minimum amount Purchase Policy"); } else { p.setAmount(maxAmount); DBStore.getInstance().setPolicy(p, storeId, maxAmount); } } }
public void signContract(SubscribedUser pending) { if (DBStore.getInstance().hasContract(store.getStoreID(), pending.getUsername(), userName.getUsername())) { throw new AlreadyExistException("You have already signed a contract with " + pending.getUsername()); } int approvedOwners = DBStore.getInstance().getContractNum(store.getStoreID(), pending.getUsername()); if (approvedOwners == store.getNumberOfOwners() - 1) { StoreRole newOwner = new StoreOwner(this.userName, pending, store); //DBStore.getInstance().signContract(store.getStoreID(), userName.getUsername(), pending.getUsername(),true); //DBStore.getInstance().removePendingOwner(store.getStoreID(),pending.getUsername()); //DBStore.getInstance().addStoreRole(newOwner); store.addStoreRoleFromInitOwner(newOwner); pending.addStoreRole(newOwner); appointedByMe.Add(newOwner); DBStore.getInstance().signAndAddOwner(store.getStoreID(), userName.getUsername(), pending.getUsername(), newOwner); } else { DBStore.getInstance().signContract(store.getStoreID(), userName.getUsername(), pending.getUsername(), false); } }
public void closeStore() { DBStore storeDB = DBStore.getInstance(); storeDB.closeStore(store); }
//public void removeCouponFromStore(string couponCode) //{ // store.removeCoupon(couponCode); //} /* public void addCouponToStore(string couponCode, int percentage, string duration) * { * store.addCoupon(couponCode, percentage, duration); * } */ //public void addCouponToStore(string couponCode, double percentage, string duration) //{ // store.addCoupon(couponCode, percentage, duration); //} public void addPendingOwner(SubscribedUser pending) { DBStore.getInstance().addPendingOwner(store.getStoreID(), userName.getUsername(), pending.getUsername()); }
public void declineContract(SubscribedUser pending) { DBStore.getInstance().declineContract(store.getStoreID(), pending.getUsername()); //DBStore.getInstance().removeAllUserContracts(store.getStoreID(), pending.getUsername()); //DBStore.getInstance().removePendingOwner(store.getStoreID(), pending.getUsername()); }
public MaxAmountPurchase(int maxAmount) { this.maxAmount = maxAmount; this.policyID = DBStore.getInstance().getNextPolicyID(); }
internal Store getStore() { return(DBStore.getInstance().getStore(storeID)); }
public SubscribedUser getSubscribedUser(string username) { if (users.ContainsKey(username)) { return(users[username]); } try { //SqlConnection connection = Connector.getInstance().getSQLConnection(); lock (connection) { connection.Open(); var c1 = connection.Query <RegisterEntry>("SELECT username, password FROM [dbo].[Register] WHERE username=@username ", new { username = username }); if (Enumerable.Count(c1) == 1) { RegisterEntry re = c1.ElementAt(0); string password = re.getPassword(); string sql = "SELECT * FROM BasketCart WHERE username=@username;"; var c2 = connection.Query <BasketCartEntry>(sql, new { username = username }); ShoppingBasket sb = new ShoppingBasket(username); SubscribedUser su = new SubscribedUser(username, password, sb); List <StoreRole> storeRoles = su.getStoreRoles(); users.Add(username, su); DBStore.getInstance().getAllStoreRoles(username); if (Enumerable.Count(c2) > 0) { for (int i = 0; i < Enumerable.Count(c2); i++) { BasketCartEntry bc = c2.ElementAt(i); int storeID = bc.getStoreID(); sql = "SELECT * FROM CartProduct WHERE storeID=@storeID AND username=@username;"; var c3 = connection.Query <CartProductEntry>(sql, new { storeID, username }); for (int j = 0; j < Enumerable.Count(c3); j++) { CartProductEntry cp = c3.ElementAt(j); int productID = cp.getProductID(); int amount = cp.getAmount(); Product p = DBProduct.getInstance().getProductByID(productID); sb.addToCartNoDBUpdate(p, amount, storeID); } } } //foreach (StoreRole sr in DBStore.getInstance().getAllStoreRoles(username)) //{ // if(sr.getUser().getUsername()==username) // { // storeRoles.Add(sr); // } //} //users.Add(username, su); connection.Close(); return(su); } else { connection.Close(); return(null); } } } catch (Exception e) { connection.Close(); return(null); } }
public ShoppingCart(int storeID) { productList = new Dictionary <Product, int>(); this.storeID = storeID; store = DBStore.getInstance().getStore(storeID); }