public bool AddUsersToGroups(int[] userIds, UserGroup[] groups)
        {
            if (ArrayIsNullOrEmpty(userIds) || ArrayIsNullOrEmpty(groups))
            {
                throw new ArgumentNullException("userIds,groupIds", "Users or UserGroups can not be null or empty!");
            }
            bool flag = false;

            _session.BeginTransaction();
            try
            {
                foreach (int uid in userIds)
                {
                    User user = User.Retrieve(_session, uid);
                    foreach (UserGroup grp in groups)
                    {
                        if (!grp.UserIsInGroup(user, _session))
                        {
                            grp.AddUser(user, _session);
                        }
                    }
                }
                _session.Commit();
            }
            catch
            {
                _session.Rollback();
                throw;
            }

            return flag;
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  Map a DataRow to a UserGroup Entity.
        /// </summary>
        /// <returns></returns>
        public static UserGroup Row2Entity(System.Data.DataRow row)
        {
            if (row == null) return null;

            UserGroup entity = new UserGroup();

            if (!row.IsNull("Group_ID"))
                entity._groupId = (int)(row["Group_ID"]);
            if (!row.IsNull("Parent_ID"))
                entity._parentId = (int)(row["Parent_ID"]);
            if (!row.IsNull("Name"))
                entity._name = (string)(row["Name"]);
            if (!row.IsNull("Description"))
                entity._description = (string)(row["Description"]);
            if (!row.IsNull("Group_Type"))
                entity._groupType = (UserGroupType)Enum.Parse(typeof(UserGroupType),(row["Group_Type"]).ToString());
            if (!row.IsNull("Group_Level"))
                entity._groupLevel = (short)(row["Group_Level"]);
            if (!row.IsNull("Create_Time"))
                entity._createTime = (DateTime)(row["Create_Time"]);
            if (!row.IsNull("Modify_Time"))
                entity._modifyTime = (DateTime)(row["Modify_Time"]);
            if (!row.IsNull("Create_By"))
                entity._createBy = (int)(row["Create_By"]);
            if (!row.IsNull("Modify_By"))
                entity._modifyBy = (int)(row["Modify_By"]);

            return entity;
        }
        private bool AddUsersToGroup(UserBase[] users, UserGroup grp)
        {
            bool flag = false;

            if (grp != null)
            {
                foreach (UserBase user in users)
                {
                    if (!grp.UserIsInGroup(user, this._session))
                    {
                        if (user != null)
                        {
                            flag = grp.AddUser(user, this._session);
                        }
                    }
                }
            }
            return flag;
        }
 public bool DeleteUserGroup(UserGroup userGroup, bool throwOnPopulatedGroup)
 {
     bool flag = true;
     if (userGroup != null)
     {
         IList<User> users = userGroup.FindUsersInGroup(_session);
         flag = !(users != null && users.Count > 0);
         if (flag)
         {
             IList<UserGroup> grps = userGroup.FindChildGroups(this._session);
             flag = !(grps != null && grps.Count > 0);
         }
         if (flag)
         {
             flag = userGroup.Delete(_session);
         }
     }
     return flag;
 }
        /// <summary>
        /// 创建子用户组
        /// </summary>
        /// <param name="parentGroupName"></param>
        /// <param name="childGroup"></param>
        /// <returns></returns>
        public bool CreateChildGroup(string parentGroupName, IUserGroup childGroup)
        {
            UserGroup parent = FindGroupByName(parentGroupName) as UserGroup;

            return(CreateChildGroup(parent, childGroup));
        }