/// <summary> /// Handles provider roles additing/deletetion. /// </summary> /// <param name="source"> /// The source. /// </param> /// <param name="e"> /// The e. /// </param> protected void RoleListNet_ItemCommand(object source, RepeaterCommandEventArgs e) { // detect which command are we handling switch (e.CommandName) { case "add": // save role and get its ID int _initialPMessages = 0; long groupID = DB.group_save( DBNull.Value, PageContext.PageBoardID, e.CommandArgument.ToString(), false, false, false, false, 1, _initialPMessages, null, 100, null, 0, null, null, 0, 0); // redirect to newly created role YafBuildLink.Redirect(ForumPages.admin_editgroup, "i={0}", groupID); break; case "delete": // delete role from provider data RoleMembershipHelper.DeleteRole(e.CommandArgument.ToString(), false); // re-bind data BindData(); break; } }
/// <summary> /// Handles provider roles adding/deleting. /// </summary> /// <param name="source"> /// The source. /// </param> /// <param name="e"> /// The e. /// </param> protected void RoleListNetItemCommand([NotNull] object source, [NotNull] RepeaterCommandEventArgs e) { // detect which command are we handling switch (e.CommandName) { case "add": // save role and get its ID const int InitialPMessages = 0; var groupId = this.GetRepository <Group>().Save( DBNull.Value, this.PageContext.PageBoardID, e.CommandArgument.ToString(), false, false, false, false, 1, InitialPMessages, null, 100, null, 0, null, null, 0, 0); // redirect to newly created role BuildLink.Redirect(ForumPages.Admin_EditGroup, "i={0}", groupId); break; case "delete": // delete role from provider data RoleMembershipHelper.DeleteRole(e.CommandArgument.ToString(), false); // re-bind data this.BindData(); break; } }
/// <summary> /// Handles click on save button. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Save_Click([NotNull] object sender, [NotNull] EventArgs e) { if (!ValidationHelper.IsValidInt(this.PMLimit.Text.Trim())) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_VALID_NUMBER")); return; } if (!ValidationHelper.IsValidInt(this.Priority.Text.Trim())) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_INTEGER")); return; } if (!ValidationHelper.IsValidInt(this.UsrAlbums.Text.Trim())) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_ALBUM_NUMBER")); return; } if (!ValidationHelper.IsValidInt(this.UsrSigChars.Text.Trim())) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_SIG_NUMBER")); return; } if (!ValidationHelper.IsValidInt(this.UsrAlbumImages.Text.Trim())) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_TOTAL_NUMBER")); return; } // Role long roleID = 0; // get role ID from page's parameter if (this.Request.QueryString.GetFirstOrDefault("i") != null) { roleID = long.Parse(this.Request.QueryString.GetFirstOrDefault("i")); } // get new and old name string roleName = this.Name.Text.Trim(); string oldRoleName = string.Empty; // if we are editing exising role, get it's original name if (roleID != 0) { // get the current role name in the DB using (DataTable dt = LegacyDb.group_list(YafContext.Current.PageBoardID, roleID)) { foreach (DataRow row in dt.Rows) { oldRoleName = row["Name"].ToString(); } } } // save role and get its ID if it's new (if it's old role, we get it anyway) roleID = LegacyDb.group_save( roleID, this.PageContext.PageBoardID, roleName, this.IsAdminX.Checked, this.IsGuestX.Checked, this.IsStartX.Checked, this.IsModeratorX.Checked, AccessMaskID.SelectedValue, this.PMLimit.Text.Trim(), this.StyleTextBox.Text.Trim(), this.Priority.Text.Trim(), this.Description.Text, this.UsrSigChars.Text, this.UsrSigBBCodes.Text, this.UsrSigHTMLTags.Text, this.UsrAlbums.Text.Trim(), this.UsrAlbumImages.Text.Trim()); // empty out access table this.GetRepository <ActiveAccess>().Reset(); // see if need to rename an existing role... if (oldRoleName.IsSet() && roleName != oldRoleName && RoleMembershipHelper.RoleExists(oldRoleName) && !RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked) { // transfer users in addition to changing the name of the role... var users = this.Get <RoleProvider>().GetUsersInRole(oldRoleName); // delete the old role... RoleMembershipHelper.DeleteRole(oldRoleName, false); // create new role... RoleMembershipHelper.CreateRole(roleName); if (users.Any()) { // put users into new role... this.Get <RoleProvider>().AddUsersToRoles(users, new[] { roleName }); } } else if (!RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked) { // if role doesn't exist in provider's data source, create it // simply create it RoleMembershipHelper.CreateRole(roleName); } // Access masks for a newly created or an existing role if (this.Request.QueryString.GetFirstOrDefault("i") != null) { // go trhough all forums for (int i = 0; i < this.AccessList.Items.Count; i++) { // get current repeater item RepeaterItem item = this.AccessList.Items[i]; // get forum ID int forumID = int.Parse(((Label)item.FindControl("ForumID")).Text); // save forum access maks for this role LegacyDb.forumaccess_save(forumID, roleID, ((DropDownList)item.FindControl("AccessmaskID")).SelectedValue); } YafBuildLink.Redirect(ForumPages.admin_groups); } // remove caching in case something got updated... this.Get <IDataCache>().Remove(Constants.Cache.ForumModerators); // Clearing cache with old permissions data... this.Get <IDataCache>().Remove(k => k.StartsWith(Constants.Cache.ActiveUserLazyData.FormatWith(String.Empty))); // Done, redirect to role editing page YafBuildLink.Redirect(ForumPages.admin_editgroup, "i={0}", roleID); }
/// <summary> /// Saves the click. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void SaveClick([NotNull] object sender, [NotNull] EventArgs e) { if (!ValidationHelper.IsValidInt(this.PMLimit.Text.Trim())) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_EDITGROUP", "MSG_VALID_NUMBER"), MessageTypes.warning); return; } if (!ValidationHelper.IsValidInt(this.Priority.Text.Trim())) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITGROUP", "MSG_INTEGER"), MessageTypes.warning); return; } if (!ValidationHelper.IsValidInt(this.UsrAlbums.Text.Trim())) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_EDITGROUP", "MSG_ALBUM_NUMBER"), MessageTypes.warning); return; } if (!ValidationHelper.IsValidInt(this.UsrSigChars.Text.Trim())) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_EDITGROUP", "MSG_SIG_NUMBER"), MessageTypes.warning); return; } if (!ValidationHelper.IsValidInt(this.UsrAlbumImages.Text.Trim())) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_EDITGROUP", "MSG_TOTAL_NUMBER"), MessageTypes.warning); return; } // Role long roleId = 0; // get role ID from page's parameter if (this.Get <HttpRequestBase>().QueryString.Exists("i")) { roleId = long.Parse(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("i")); } // get new and old name var roleName = this.Name.Text.Trim(); var oldRoleName = string.Empty; // if we are editing existing role, get it's original name if (roleId != 0) { // get the current role name in the DB var groups = this.GetRepository <Group>().List(boardId: this.PageContext.PageBoardID); groups.ForEach(group => oldRoleName = @group.Name); } // save role and get its ID if it's new (if it's old role, we get it anyway) roleId = this.GetRepository <Group>().Save( roleId, this.PageContext.PageBoardID, roleName, this.IsAdminX.Checked, this.IsGuestX.Checked, this.IsStartX.Checked, this.IsModeratorX.Checked, this.AccessMaskID.SelectedValue, this.PMLimit.Text.Trim(), this.StyleTextBox.Text.Trim(), this.Priority.Text.Trim(), this.Description.Text, this.UsrSigChars.Text, this.UsrSigBBCodes.Text, this.UsrSigHTMLTags.Text, this.UsrAlbums.Text.Trim(), this.UsrAlbumImages.Text.Trim()); // empty out access table(s) this.GetRepository <Active>().DeleteAll(); this.GetRepository <ActiveAccess>().DeleteAll(); // see if need to rename an existing role... if (oldRoleName.IsSet() && roleName != oldRoleName && RoleMembershipHelper.RoleExists(oldRoleName) && !RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked) { // transfer users in addition to changing the name of the role... var users = this.Get <RoleProvider>().GetUsersInRole(oldRoleName); // delete the old role... RoleMembershipHelper.DeleteRole(oldRoleName, false); // create new role... RoleMembershipHelper.CreateRole(roleName); if (users.Any()) { // put users into new role... this.Get <RoleProvider>().AddUsersToRoles(users, new[] { roleName }); } } else if (!RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked) { // if role doesn't exist in provider's data source, create it // simply create it RoleMembershipHelper.CreateRole(roleName); } // Access masks for a newly created or an existing role if (this.Get <HttpRequestBase>().QueryString.Exists("i")) { // go through all forums for (var i = 0; i < this.AccessList.Items.Count; i++) { // get current repeater item var item = this.AccessList.Items[i]; // get forum ID var forumId = int.Parse(item.FindControlAs <Label>("ForumID").Text); // save forum access masks for this role this.GetRepository <ForumAccess>().Save( forumId, roleId.ToType <int>(), item.FindControlAs <DropDownList>("AccessmaskID").SelectedValue.ToType <int>()); } YafBuildLink.Redirect(ForumPages.admin_groups); } // remove caching in case something got updated... this.Get <IDataCache>().Remove(Constants.Cache.ForumModerators); // Clearing cache with old permissions data... this.Get <IDataCache>().Remove( k => k.StartsWith(string.Format(Constants.Cache.ActiveUserLazyData, string.Empty))); // Clear Styling Caching this.Get <IDataCache>().Remove(Constants.Cache.GroupRankStyles); // Done, redirect to role editing page YafBuildLink.Redirect(ForumPages.admin_editgroup, "i={0}", roleId); }
/// <summary> /// Handles click on save button. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Save_Click(object sender, EventArgs e) { if (!ValidationHelper.IsValidInt(this.PMLimit.Text.Trim())) { PageContext.AddLoadMessage("You should enter integer value for pmessage number."); return; } if (!ValidationHelper.IsValidInt(this.Priority.Text.Trim())) { PageContext.AddLoadMessage("You should enter integer value for priority."); return; } if (!ValidationHelper.IsValidInt(this.UsrAlbums.Text.Trim())) { PageContext.AddLoadMessage("You should enter integer value for the number of user albums."); return; } if (!ValidationHelper.IsValidInt(this.UsrSigChars.Text.Trim())) { PageContext.AddLoadMessage("You should enter integer value for the number of chars in user signature."); return; } if (!ValidationHelper.IsValidInt(this.UsrAlbumImages.Text.Trim())) { PageContext.AddLoadMessage("You should enter integer value for the total number of images in all albums."); return; } // Role long roleID = 0; // get role ID from page's parameter if (Request.QueryString.GetFirstOrDefault("i") != null) { roleID = long.Parse(Request.QueryString.GetFirstOrDefault("i")); } // get new and old name string roleName = this.Name.Text.Trim(); string oldRoleName = string.Empty; // if we are editing exising role, get it's original name if (roleID != 0) { // get the current role name in the DB using (DataTable dt = DB.group_list(YafContext.Current.PageBoardID, roleID)) { foreach (DataRow row in dt.Rows) { oldRoleName = row["Name"].ToString(); } } } // save role and get its ID if it's new (if it's old role, we get it anyway) roleID = DB.group_save( roleID, PageContext.PageBoardID, roleName, this.IsAdminX.Checked, this.IsGuestX.Checked, this.IsStartX.Checked, this.IsModeratorX.Checked, this.AccessMaskID.SelectedValue, this.PMLimit.Text.Trim(), this.StyleTextBox.Text.Trim(), this.Priority.Text.Trim(), this.Description.Text, this.UsrSigChars.Text, this.UsrSigBBCodes.Text, this.UsrSigHTMLTags.Text, this.UsrAlbums.Text.Trim(), this.UsrAlbumImages.Text.Trim() ); // see if need to rename an existing role... if (roleName != oldRoleName && RoleMembershipHelper.RoleExists(oldRoleName) && !RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked) { // transfer users in addition to changing the name of the role... string[] users = PageContext.CurrentRoles.GetUsersInRole(oldRoleName); // delete the old role... RoleMembershipHelper.DeleteRole(oldRoleName, false); // create new role... RoleMembershipHelper.CreateRole(roleName); if (users.Length > 0) { // put users into new role... PageContext.CurrentRoles.AddUsersToRoles(users, new[] { roleName }); } } // if role doesn't exist in provider's data source, create it else if (!RoleMembershipHelper.RoleExists(roleName) && !this.IsGuestX.Checked) { // simply create it RoleMembershipHelper.CreateRole(roleName); } // Access masks for a newly created or an existing role if (Request.QueryString.GetFirstOrDefault("i") != null) { // go trhough all forums for (int i = 0; i < this.AccessList.Items.Count; i++) { // get current repeater item RepeaterItem item = this.AccessList.Items[i]; // get forum ID int forumID = int.Parse(((Label)item.FindControl("ForumID")).Text); // save forum access maks for this role DB.forumaccess_save(forumID, roleID, ((DropDownList)item.FindControl("AccessmaskID")).SelectedValue); } YafBuildLink.Redirect(ForumPages.admin_groups); } // remove caching in case something got updated... PageContext.Cache.Remove(YafCache.GetBoardCacheKey(Constants.Cache.ForumModerators)); // Clearing cache with old permissions data... this.PageContext.Cache.RemoveAllStartsWith(Constants.Cache.ActiveUserLazyData.FormatWith(String.Empty)); // Done, redirect to role editing page YafBuildLink.Redirect(ForumPages.admin_editgroup, "i={0}", roleID); }