public void addManager(int storeid, string username, bool editProduct, bool editDiscount, bool editPolicy, Session session) { SubscribedUser toAdd = DBSubscribedUser.getInstance().getSubscribedUser(username); if (toAdd == null) { throw new DoesntExistException("no such username"); } Store store = DBStore.getInstance().getStore(storeid); if (store == null) { throw new DoesntExistException("no such store"); } StoreRole sr = store.getStoreRole(session.getSubscribedUser()); if (sr.getStore() != store) { throw new RoleException("this user can't appoint to this store"); } Permissions permissions = new Permissions(editProduct, editDiscount, editPolicy); sr.addManager(toAdd, permissions); }
public void removeStoreRole(StoreRole sr) { try { //SqlConnection connection = Connector.getInstance().getSQLConnection(); int storeId = sr.getStore().getStoreID(); string userName = sr.getUser().getUsername(); lock (connection) { connection.Open(); connection.Execute("DELETE FROM StoreRoles WHERE storeId=@storeId AND userName=@userName", new { storeId, userName }); storeRole.Remove(sr); connection.Close(); } } catch (Exception) { connection.Close(); SystemLogger.getErrorLog().Error("Connection error in function remove role in DB Store while removing " + sr.getUser().getUsername()); throw new ConnectionException(); } }
public void removeRole(int storeid, string username, Session session) { SubscribedUser toRemove = DBSubscribedUser.getInstance().getSubscribedUser(username); if (toRemove == null) { throw new DoesntExistException("no such username"); } Store store = DBStore.getInstance().getStore(storeid); if (store == null) { throw new DoesntExistException("no such store"); } StoreRole sr = store.getStoreRole(session.getSubscribedUser()); if (sr.getStore() != store) { throw new RoleException("this user can't remove roles from this store"); } sr.remove(toRemove); }
public void addOwner(int storeid, string username, Session session) { SubscribedUser toAdd = DBSubscribedUser.getInstance().getSubscribedUser(username); if (toAdd == null) { throw new DoesntExistException("no such username"); } Store store = DBStore.getInstance().getStore(storeid); if (store == null) { throw new DoesntExistException("no such store"); } StoreRole sr = store.getStoreRole(session.getSubscribedUser()); if (sr.getStore() != store) { throw new RoleException("this user can't appoint to this store"); } sr.addOwner(toAdd); }
public void addStoreRole(StoreRole sr) { //SqlConnection connection = Connector.getInstance().getSQLConnection(); lock (connection) { if (ownerTrans == null) { connection.Open(); } SqlTransaction transaction; if (ownerTrans != null) { transaction = ownerTrans; } else { transaction = connection.BeginTransaction(); } try { string sql = "INSERT INTO [dbo].[StoreRoles] (storeId, appointedBy,userName,isOwner,editProduct,editDiscount,editPolicy)" + " VALUES (@storeId, @appointedBy, @userName,@isOwner,@editProduct,@editDiscount,@editPolicy)"; int storeId = sr.getStore().getStoreID(); string appointedBy = null; if (sr.getAppointedBy() != null) { appointedBy = sr.getAppointedBy().getUsername(); } string userName = sr.getUser().getUsername(); int isOwner = sr.getIsOwner(); int editProduct = 1; int editDiscount = 1; int editPolicy = 1; if (isOwner == 0) { editProduct = sr.GetPermissions().getPermission("editProduct"); editDiscount = sr.GetPermissions().getPermission("editDiscount"); editPolicy = sr.GetPermissions().getPermission("editPolicy"); } connection.Execute(sql, new { storeId, appointedBy, userName, isOwner, editProduct, editDiscount, editPolicy }, transaction); storeRole.AddFirst(sr); if (ownerTrans == null) { transaction.Commit(); transaction.Dispose(); connection.Close(); } } catch (Exception e) { if (ownerTrans == null) { transaction.Dispose(); connection.Close(); } SystemLogger.getErrorLog().Error("Connection error in function add role in DB Store while adding " + sr.getUser().getUsername()); throw new ConnectionException(); } } }
public void removeFromCategory(StoreRole storeRole, NotificationCategories category) { if (!usersPreferences.ContainsKey(category)) { return; } foreach (StoreRole sR in usersPreferences[category]) { if (sR.user.getUserName() == storeRole.user.getUserName() && sR.store.getStoreId() == storeRole.store.getStoreId()) { UNPDB.Remove(new Tuple <int, string, int>((int)category, storeRole.getUser().getUserName(), storeRole.getStore().getStoreId())); usersPreferences[category].Remove(sR); return; } } }
public void signToCategory(StoreRole storeRole, NotificationCategories category) { if (!usersPreferences.ContainsKey(category)) { usersPreferences.Add(category, new LinkedList <StoreRole>()); } foreach (StoreRole sR in usersPreferences[category]) { if (sR.user.getUserName() == storeRole.user.getUserName() && sR.store.getStoreId() == storeRole.store.getStoreId()) { return; } } UNPDB.Add(new Tuple <int, string, int>((int)category, storeRole.getUser().getUserName(), storeRole.getStore().getStoreId())); usersPreferences[category].AddLast(storeRole); }