Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Feedback.Visible = false;

            Guid userId;

            if (!Request.QueryString["id"].TryParseGuid(out userId))
            {
                ShowError(Feedback, "The parameter for id is not in the correct format!");
                SaveButton.Visible = false;
                FormFields.Visible = false;
                return;
            }

            _userManager = IdentityUserManager.GetManager();
            _user        = _userManager.FindById(userId);

            if (_user == null)
            {
                ShowError(Feedback, "No user was found for the given id!");
                SaveButton.Visible = false;
                FormFields.Visible = false;
                return;
            }

            SaveButton.Click += SaveButton_Click;

            UserId.Value  = userId.ToString();
            UserName.Text = _user.UserName;

            UserName.Attributes.Add("autocomplete", "off");
            Password.Attributes.Add("autocomplete", "off");

            if (!IsPostBack)
            {
                Email.Text       = _user.Email;
                FirstName.Text   = _user.FirstName;
                SurName.Text     = _user.SurName;
                PhoneNumber.Text = _user.PhoneNumber;
                Password.Attributes.Add("value", PasswordMask);
                ConfirmPassword.Attributes.Add("value", PasswordMask);

                if (Request.QueryString["message"] == "created")
                {
                    ShowMessage(Feedback, "User has been created!");
                }
            }

            _roleManager = IdentityRoleManager.GetManager();
            _roles       = _roleManager.Roles.OrderBy(r => r.Name).ToList();

            RenderRoles();
        }
        private void RenderRoles()
        {
            var stringBuilder = new StringBuilder();
            var roleManager   = IdentityRoleManager.GetManager();
            var roles         = roleManager.Roles.OrderBy(r => r.Name).ToList();

            foreach (var role in roles)
            {
                stringBuilder.AppendFormat("<li><input type=\"checkbox\" Value=\"{0}\" Name=\"Roles\" /> {0}</li>", role.Name);
            }

            Roles.Text = stringBuilder.ToString();
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var roleManager   = IdentityRoleManager.GetManager();
            var roles         = roleManager.Roles.ToList();
            var stringBuilder = new StringBuilder();

            foreach (var role in roles)
            {
                stringBuilder.Append("<tr><td><a href=\"Identity/EditRole.aspx?id=" + role.Id + "\">" + role.Name + "</a></td></tr>");
            }

            RoleList.Text = stringBuilder.ToString();
        }
        void SaveButton_Click(object sender, EventArgs e)
        {
            var role        = new IdentityRole(RoleName.Text);
            var roleManager = IdentityRoleManager.GetManager();
            var result      = roleManager.Create(role);

            if (result.Succeeded)
            {
                Response.Redirect("EditRole.aspx?id=" + role.Id + "&message=created");
            }
            else
            {
                ShowError(Feedback, "Couldn't save role: " + string.Join(", ", result.Errors));
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Guid roleId;

            if (!Request.QueryString["id"].TryParseGuid(out roleId))
            {
                throw new ArgumentException("Id not valid");
            }

            var roleManager = IdentityRoleManager.GetManager();
            var role        = roleManager.FindById(roleId);

            if (role == null)
            {
                throw new Exception("No role with submitted id");
            }

            roleManager.Delete(role);
            Response.Redirect("Roles.aspx");
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Feedback.Visible = false;

            Guid roleId;

            if (!Request.QueryString["id"].TryParseGuid(out roleId))
            {
                ShowError(Feedback, "The parameter for id is not in the correct format!");
                SaveButton.Visible = false;
                FormFields.Visible = false;
                return;
            }

            _roleManager = IdentityRoleManager.GetManager();
            _role        = _roleManager.FindById(roleId);

            if (_role == null)
            {
                ShowError(Feedback, "No role was found for the given id!");
                SaveButton.Visible = false;
                FormFields.Visible = false;
                return;
            }

            SaveButton.Click += SaveButton_Click;

            if (!IsPostBack)
            {
                RoleId.Value  = roleId.ToString();
                RoleName.Text = _role.Name;

                if (Request.QueryString["message"] == "created")
                {
                    ShowMessage(Feedback, "Role has been created!");
                }
            }

            RenderUsersInRole();
        }