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); }
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 createStoreBySubscribedUserTest() { UserService userService = UserService.getInstance(); session = userService.startSession(); userService.register(session, "anna", "banana"); userService.login(session, "anna", "banana"); SubscribedUser user = session.getSubscribedUser(); Store store = userService.createStore(session, "Apple", "apples"); List <StoreRole> roles = store.getRoles(); Assert.IsTrue(roles.Count == 1); StoreRole role = roles[0]; Assert.IsTrue(role is StoreOwner); Assert.IsTrue(Equals(role.getUser(), user)); List <StoreRole> userRoles = user.getStoreRoles(); Assert.IsTrue(userRoles.Contains(role)); Assert.AreEqual(userService.createStore(null, "", ""), null); }
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(); } } }