예제 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         ApplicationUtilities.updateListControl(roleDDL, new IdentityManager().GetRoles(), "id", "name");
     }
 }
예제 #2
0
    private void updatePermissionBox()
    {
        try
        {
            allpermissionBox.Items.Clear();
            permissionForRole.Items.Clear();
            IdentityManager manager = new IdentityManager(localization);
            // Load all permissions on the allPermissionbox if it can't find the role.
            if (String.IsNullOrEmpty(roleList.SelectedValue))
            {
                ApplicationUtilities.updateListControl(allpermissionBox, manager.GetPermissions().OrderBy(i => i.localizedName).ToList(), "id", "localizedName");
            }
            else
            {
                List <Permission> allPermissions    = manager.GetPermissions().OrderBy(i => i.localizedName).ToList();
                List <Permission> permissionForRole = manager.GetPermissions(roleList.SelectedValue).OrderBy(i => i.localizedName).ToList();

                foreach (Permission p in permissionForRole)
                {
                    allPermissions.RemoveAll(i => i.id == p.id);
                }
                ApplicationUtilities.updateListControl(allpermissionBox, allPermissions, "id", "localizedName");
                ApplicationUtilities.updateListControl(this.permissionForRole, permissionForRole, "id", "localizedName");
            }
        }catch (Exception ex)
        {
            errorMessage.Text    = Resources.General.AnErrorHasOccured + ex.ToString();
            errorMessage.Visible = true;
        }
    }
예제 #3
0
    private void refreshFields(string userId)
    {
        try
        {
            userDDList.Items.Clear();
            IdentityManager manager = new IdentityManager();
            // Append a please select a user item at the beginning of the list
            User plzSelectItem = new User();
            plzSelectItem.name = Resources.General.PleaseSelectAUser;
            List <User> orderedUsers = manager.GetUsers().OrderBy(i => i.name).ToList();
            orderedUsers.Insert(0, plzSelectItem);

            ApplicationUtilities.updateListControl(userDDList, orderedUsers, "id", "name");
            ApplicationUtilities.updateListControl(roleDDL, manager.GetRoles().OrderBy(i => i.name).ToList(), "id", "name");

            if (!String.IsNullOrEmpty(userId))
            {
                userDDList.SelectedIndex = userDDList.Items.IndexOf(userDDList.Items.FindByValue(userId));
                userName.Text            = userDDList.SelectedItem.Text;
                Role role = manager.GetUser(userDDList.SelectedItem.Text).role;
                if (role != null)
                {
                    roleDDL.SelectedIndex = roleDDL.Items.IndexOf(roleDDL.Items.FindByValue(role.id));
                }
                userDiv.Visible          = true;
                passwordResetDiv.Visible = true;
            }
            else
            {
                userDiv.Visible          = false;
                passwordResetDiv.Visible = false;
            }
        }catch (Exception ex)
        {
            userModificationError.Visible      = true;
            userModificationErrorAlert.Visible = true;
            userModificationError.Text         = Resources.General.AnErrorHasOccured + ex.ToString();
        }
    }
예제 #4
0
    /// <summary>
    /// Update the role drop down list from the database
    /// </summary>
    /// <param name="role">the role to have selectionned or null if no role are selectionned</param>
    private void updateRoleList(Role role)
    {
        try
        {
            roleList.Items.Clear();
            List <Role> orderedRoles  = new IdentityManager().GetRoles().OrderBy(i => i.name).ToList();
            Role        plzSelectItem = new Role();
            plzSelectItem.name = Resources.General.PleaseSelectARole;
            orderedRoles.Insert(0, plzSelectItem);
            ApplicationUtilities.updateListControl(roleList, orderedRoles, "id", "name");

            if (role != null && role.id != null)
            {
                roleList.SelectedIndex = roleList.Items.IndexOf(roleList.Items.FindByValue(role.id));
            }
            updatePermissionBox();
        } catch (Exception ex)
        {
            errorMessage.Text    = Resources.General.AnErrorHasOccured + ex.ToString();
            errorMessage.Visible = true;
        }
    }