Exemplo n.º 1
0
        /// <summary>
        /// Refreshes the view.
        /// </summary>
        private void RefreshView()
        {
            Role selectedRole = lvwGroups.SelectedObject as Role;

            lvwGroups.BeginUpdate();
            lvwGroups.ClearObjects();
            IQueryable <Role> results = Role.All().OrderBy(r => r.Id);
            List <Role>       roles   = new List <Role>(results.AsEnumerable());

            lvwGroups.SetObjects(roles);
            if (roles.Count() == 0)
            {
                lvwGroups.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            }
            else
            {
                lvwGroups.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            }

            olvColDescription.FillsFreeSpace = true;

            lvwGroups.EndUpdate();

            if (selectedRole != null)
            {
                lvwGroups.SelectObject(selectedRole);
            }
        }
        /// <summary>
        /// Handles the Load event of the frmContactUser 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 frmContactUser_Load(object sender, EventArgs e)
        {
            List <Role> userRoles = new List <Role>();

            if (this.User != null)
            {
                this.txtName.Text          = this.User.CommonName;
                this.txtPhoneNumber.Text   = this.User.Mobtel;
                this.txtEmail.Text         = this.User.Email;
                this.txtLoginName.Text     = this.User.LoginName;
                this.txtPassword.Text      = this.User.Password;
                this.txtPasswordAgain.Text = this.User.Password;

                if (this.User.LoginName.Equals(GuiHelper.AdministratorName, StringComparison.OrdinalIgnoreCase))
                {
                    txtLoginName.Enabled = false;
                }

                // Load user roles
                IList <UserRoleMap> userMappings = UserRoleMap.Find(urm => urm.UserId == this.User.Id);
                foreach (UserRoleMap urm in userMappings)
                {
                    Role role = Role.SingleOrDefault(r => r.Id == urm.RoleId);
                    if (role != null)
                    {
                        lstBelongedGroups.Items.Add(BuildDisplayName(role));
                        userRoles.Add(role);
                    }
                }
            }

            List <Role> roles = new List <Role>(Role.All().OrderBy(r => r.Name).AsEnumerable());

            foreach (Role role in roles)
            {
                if (!userRoles.Exists(r => r.Id == role.Id))
                {
                    lstAvailableGroups.Items.Add(BuildDisplayName(role));
                }
            }
        }
Exemplo n.º 3
0
 public bool CheckRole(TRole role)
 {
     return(Role.All(r => r.Equals(role.ToString())));
 }