Ejemplo n.º 1
0
        /// <summary>
        /// Handles the Load event of the frmContactGroup control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void frmContactGroup_Load(object sender, EventArgs e)
        {
            List <User> usersInGroup = new List <User>();

            if (this.Group != null)
            {
                this.Text                = this.Group.Name;
                this.txtName.Text        = this.Group.Name;
                this.txtDescription.Text = this.Group.Desc;

                if (this.Group.Name.Equals(GuiHelper.AdministratorGroupName, StringComparison.OrdinalIgnoreCase))
                {
                    txtName.Enabled = false;
                }

                // Load users in those groups
                IList <UserRoleMap> userList = UserRoleMap.Find(urm => urm.RoleId == this.Group.Id);
                foreach (UserRoleMap urm in userList)
                {
                    User user = User.SingleOrDefault(u => u.Id == urm.UserId);
                    if (user != null)
                    {
                        lstUsersInGroup.Items.Add(BuildDisplayName(user));
                        usersInGroup.Add(user);
                    }
                }
            }

            List <User> users = new List <User>(User.All().OrderBy(u => u.CommonName).AsEnumerable());

            foreach (User user in users)
            {
                if (!usersInGroup.Exists(u => u.Id == user.Id))
                {
                    lstAvailableUsers.Items.Add(BuildDisplayName(user));
                }
            }
        }