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 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 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 Store getStore(int storeId) { foreach (Store s in stores) { if (s.getStoreID() == storeId) { return(s); } } ///////////////////////////////////////////////////// try { // SqlConnection connection = Connector.getInstance().getSQLConnection(); lock (connection) { connection.Open(); LinkedList <Store> newStores = new LinkedList <Store>(); var StoreResult = connection.Query <StoreEntry>("SELECT * FROM [dbo].[Stores] WHERE storeId=@storeId ", new { storeId = storeId }); var StoreRoleResult = connection.Query <StoreRoleEntry>("SELECT * FROM [dbo].[StoreRoles] WHERE storeId=@storeId ", new { storeId = storeId }); var ContractResult = connection.Query <Contract>("SELECT * FROM [dbo].[Contracts] WHERE storeId = @storeId", new { storeId = storeId }); var pendingResult = connection.Query <string>("SELECT userName FROM [dbo].[PendingOwners] WHERE storeId = @storeId", new { storeId = storeId }).AsList(); var policyEntries = connection.Query <PolicyEntry>("SELECT * FROM [dbo].[PurchasePolicy] WHERE storeID=@storeId", new { storeID = storeId }); connection.Close(); StoreEntry se = StoreResult.ElementAt(0); Store s = new Store(se.getStoreId(), se.getName(), se.getDescription()); foreach (Contract c in ContractResult) { s.getContracts().AddFirst(c); } foreach (string pending in pendingResult) { s.getPending().AddFirst(pending); } LinkedList <Product> lst = DBProduct.getInstance().getAllProducts(); foreach (Product p in lst) { if (p.getStoreID() == s.getStoreID()) { s.addProduct(p); } } s.setPolicyList(parsePolicy(policyEntries)); foreach (StoreRoleEntry element in StoreRoleResult) { if (element.getStoreId() == s.getStoreID() && element.getIsOwner() == 1) { SubscribedUser appointedBy = null; try { appointedBy = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getAppointedBy()); } catch (Exception) { } SubscribedUser user = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getUserName()); StoreOwner so = new StoreOwner(appointedBy, user, s); s.addStoreRoleFromInitOwner(so); storeRole.AddLast(so); } else if (element.getStoreId() == s.getStoreID() && element.getIsOwner() == 0) { SubscribedUser appointedBy = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getAppointedBy()); SubscribedUser user = DBSubscribedUser.getInstance().getSubscribedUserForInitStore(element.getUserName()); Permissions p = new Permissions(false, false, false); if (element.getEditDiscount() == 1) { p.setEditDiscount(true); } if (element.getEditPolicy() == 1) { p.setEditPolicy(true); } if (element.getEditProduct() == 1) { p.setEditProduct(true); } StoreManager sm = new StoreManager(appointedBy, s, user, p); s.addStoreRoleFromInitManager(sm); storeRole.AddLast(sm); } } stores.AddLast(s); LinkedList <DiscountComponent> discountList = DBDiscount.getInstance().getStoreDiscountsList(storeId); s.setDiscountList(discountList); return(s); } } catch (Exception e) { connection.Close(); SystemLogger.getErrorLog().Error("Connection error in function getStore in DB Store store id " + storeId); throw new ConnectionException(); } /////////////////////////////////////////////////// }
public void addStoreRoleFromInitOwner(StoreOwner so) { roles.Add(so); numOfOwners++; }