AddToRole() public method

public AddToRole ( string roleName ) : bool
roleName string
return bool
		protected void btnAddUsers_Click(object sender, EventArgs e) {
			if (!String.IsNullOrEmpty(hdnUserID.Value)) {
				MembershipRole role = getCurrentGroup();

				ExtendedUserData exUsr = new ExtendedUserData(hdnUserID.Value);
				exUsr.AddToRole(role.RoleName);
			}

			Response.Redirect(SiteData.CurrentScriptName + "?id=" + groupID.ToString());
		}
		protected void btnAddUsers_Click(object sender, EventArgs e) {
			if (!String.IsNullOrEmpty(hdnUserID.Value)) {
				ExtendedUserData exUsr = new ExtendedUserData(hdnUserID.Value);
				exUsr.AddToSite(guidSiteID);

				if (chkAddToEditor.Checked) {
					exUsr.AddToRole(SecurityData.CMSGroup_Editors);
				}
			}

			Response.Redirect(SiteData.CurrentScriptName + "?id=" + guidSiteID.ToString());
		}
		public ActionResult SiteAddUser(SiteModel model) {
			ModelState.Clear();

			if (String.IsNullOrEmpty(model.NewUserId)) {
				ModelState.AddModelError("NewUserId", "The New User field is required.");
			}

			SiteData site = model.Site;
			Helper.ForceValidation(ModelState, model);

			if (ModelState.IsValid) {
				if (!String.IsNullOrEmpty(model.NewUserId)) {
					ExtendedUserData exUsr = new ExtendedUserData(new Guid(model.NewUserId));
					exUsr.AddToSite(site.SiteID);

					if (model.NewUserAsEditor) {
						exUsr.AddToRole(SecurityData.CMSGroup_Editors);
					}
				}

				return RedirectToAction("SiteDetail", new { @id = site.SiteID });
			}

			Helper.HandleErrorDict(ModelState);

			model.LoadUsers();

			return View("SiteDetail", model);
		}
Example #4
0
        protected void btnApply_Click(object sender, EventArgs e)
        {
            if (userID != Guid.Empty) {

                MembershipUser usr = Membership.GetUser(userID);
                usr.Email = Email.Text;
                Membership.UpdateUser(usr);

                ExtendedUserData exUsr = new ExtendedUserData(userID);
                exUsr.UserNickName = txtNickName.Text;
                exUsr.FirstName = txtFirstName.Text;
                exUsr.LastName = txtLastName.Text;
                exUsr.UserBio = reBody.Text;

                exUsr.Save();

                if (!chkLocked.Checked) {
                    usr.UnlockUser();
                    Membership.UpdateUser(usr);
                } else {
                    if (!usr.IsLockedOut) {
                        int iCount = 0;
                        while (iCount < 10) {
                            Membership.ValidateUser(usr.UserName, "zzBadPassWord123a" + iCount.ToString());
                            Membership.ValidateUser(usr.UserName, "zzBadPassWord123b" + iCount.ToString());
                            iCount++;
                        }
                    }
                }

                exUsr.AddToRole(SecurityData.CMSGroup_Users);

                CheckBox chkSelected = null;
                HiddenField hdnSiteID = null;

                foreach (GridViewRow dgItem in gvSites.Rows) {
                    hdnSiteID = (HiddenField)dgItem.FindControl("hdnSiteID");

                    if (hdnSiteID != null) {
                        Guid guidSiteID = new Guid(hdnSiteID.Value);
                        chkSelected = (CheckBox)dgItem.FindControl("chkSelected");

                        if (chkSelected.Checked) {
                            exUsr.AddToSite(guidSiteID);
                        } else {
                            exUsr.RemoveFromSite(guidSiteID);
                        }
                    }
                }

                HiddenField hdnRoleId = null;

                foreach (GridViewRow dgItem in gvRoles.Rows) {
                    hdnRoleId = (HiddenField)dgItem.FindControl("hdnRoleId");
                    if (hdnRoleId != null) {
                        chkSelected = (CheckBox)dgItem.FindControl("chkSelected");

                        if (chkSelected.Checked) {
                            exUsr.AddToRole(hdnRoleId.Value);
                        } else {
                            exUsr.RemoveFromRole(hdnRoleId.Value);
                        }
                    }
                }
            }
        }