Exemplo n.º 1
0
        public bool ChangeUserToGroupAssociation(MGGroup group, List <int> usersIDs, AssociationTypes associationType)
        {
            bool ISChanged = true;

            DbInfo = new DatabaseWrapper(Lcf);
            string sql     = "";
            string partMSG = "'" + associationType + "ing' (" + usersIDs.Count + ") users to Group '" + group.Name + "'";

            try {
                Logger.Log("Start " + partMSG);
                DbInfo.Connect();
                foreach (int userID in usersIDs)
                {
                    if (associationType == AssociationTypes.Assign)
                    {
                        sql = GroupQB.GetAssignGroupForUserSql(userID, group.ID);
                    }
                    else
                    {
                        sql = GroupQB.GetUnAssignGroupForUserSql(userID, group.ID);
                    }
                    bool success    = false;
                    int  numChanged = DbInfo.ExecuteSQL(sql, ref success);
                    if (numChanged == 0)
                    {
                        ISChanged = false;
                    }
                }
            } catch (Exception ex) {
                Logger.LogError(5, "Error " + partMSG + " at: " + ex);
                return(false);
            } finally {
                if (ISChanged)
                {
                    SecureContentWrapper.SecurityHasBeenModifiedThisSession = true;
                }

                if (DbInfo != null)
                {
                    DbInfo.Disconnect();
                }
            }
            return(ISChanged);
        }
Exemplo n.º 2
0
        //---------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Change the group association for a given user.
        ///     It can assign the groups to a user and also can un assign groups linked to a user.
        ///     30-Jan-2015 - added the bool toggle on whether or not to use the session wrapper.  This causes an issue with threaded applications as in the
        ///     worker thread the session wrappers are not available.
        /// </summary>
        /// <param name="groupsIDs">Group Ids to Assign or UnAssign</param>
        /// <param name="associationType">Assign or UnAssign</param>
        /// <returns>True if successfull, false other wise</returns>
        public bool ChangeGroupToUserAssociation(int userID, List <int> groupsIDs, AssociationTypes associationType, bool recordModificationInSessionWrapper)
        {
            bool isChangeSuccess = true;

            DbInfo = new DatabaseWrapper(Lcf);
            string sql = "";

            try {
                DbInfo.Connect();
                foreach (int groupID in groupsIDs)
                {
                    if (associationType == AssociationTypes.Assign)
                    {
                        sql = GroupQB.GetAssignGroupForUserSql(userID, groupID);
                    }
                    else
                    {
                        sql = GroupQB.GetUnAssignGroupForUserSql(userID, groupID);
                    }
                    bool success    = false;
                    int  numChanged = DbInfo.ExecuteSQL(sql, ref success);
                    if (numChanged == 0)
                    {
                        isChangeSuccess = false;
                    }
                }
            } catch (Exception ex) {
                Logger.LogError(5, "Error in changing group association at: " + ex);
                isChangeSuccess = false;
            } finally {
                if (isChangeSuccess && recordModificationInSessionWrapper)
                {
                    SecureContentWrapper.SecurityHasBeenModifiedThisSession = true;

                    if (DbInfo != null)
                    {
                        DbInfo.Disconnect();
                    }
                }
            }

            return(isChangeSuccess);
        }