/// <summary> /// Creates subcategory. Called when the "Create subcategory" button is pressed. /// </summary> private bool CreateSubcategory() { // Get the parent category CategoryInfo parentCategory = CategoryInfoProvider.GetCategoryInfo("MyNewCategory", SiteContext.CurrentSiteName); if (parentCategory != null) { // Create new category object CategoryInfo newSubcategory = new CategoryInfo(); // Set the properties newSubcategory.CategoryDisplayName = "My new subcategory"; newSubcategory.CategoryName = "MyNewSubcategory"; newSubcategory.CategoryDescription = "My new subcategory description"; newSubcategory.CategorySiteID = SiteContext.CurrentSiteID; newSubcategory.CategoryCount = 0; newSubcategory.CategoryEnabled = true; newSubcategory.CategoryParentID = parentCategory.CategoryID; // Save the category CategoryInfoProvider.SetCategoryInfo(newSubcategory); return(true); } return(false); }
/// <summary> /// Gets and bulk updates categories. Called when the "Get and bulk update categories" button is pressed. /// Expects the CreateCategory method to be run first. /// </summary> private bool GetAndBulkUpdateCategories() { // Prepare the parameters string where = "CategoryName LIKE N'MyNewCategory%'"; // Get the data DataSet categories = CategoryInfoProvider.GetCategories(where, null); if (!DataHelper.DataSourceIsEmpty(categories)) { // Loop through the individual items foreach (DataRow categoryDr in categories.Tables[0].Rows) { // Create object from DataRow CategoryInfo modifyCategory = new CategoryInfo(categoryDr); // Update the properties modifyCategory.CategoryDisplayName = modifyCategory.CategoryDisplayName.ToUpper(); // Save the changes CategoryInfoProvider.SetCategoryInfo(modifyCategory); } return(true); } return(false); }
/// <summary> /// Gets and updates category. Called when the "Get and update category" button is pressed. /// Expects the CreateCategory method to be run first. /// </summary> private bool GetAndUpdateCategory() { // Get the category CategoryInfo updateCategory = CategoryInfoProvider.GetCategoryInfo("MyNewCategory", CMSContext.CurrentSiteName); if (updateCategory != null) { // Update the properties updateCategory.CategoryDisplayName = updateCategory.CategoryDisplayName.ToLower(); // Save the changes CategoryInfoProvider.SetCategoryInfo(updateCategory); return(true); } return(false); }
/// <summary> /// Creates category. Called when the "Create category" button is pressed. /// </summary> private bool CreateCategory() { // Create new category object CategoryInfo newCategory = new CategoryInfo(); // Set the properties newCategory.CategoryDisplayName = "My new category"; newCategory.CategoryName = "MyNewCategory"; newCategory.CategoryDescription = "My new category description"; newCategory.CategorySiteID = CMSContext.CurrentSiteID; newCategory.CategoryCount = 0; newCategory.CategoryEnabled = true; // Save the category CategoryInfoProvider.SetCategoryInfo(newCategory); return(true); }
public void btnSaveCategory_Click(object sender, EventArgs e) { // Validate form entries string errorMessage = ""; // Check "modify" permission if (!this.RaiseOnCheckPermissions("Modify", this)) { if ((this.UserID > 0) && (this.UserID != CMSContext.CurrentUser.UserID) && (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Users", "Modify"))) { string.Format(GetString("general.permissionresource"), "Modify", "CMS.Users"); } } // Prepare ID of the site for new category int newSiteId = SiteID; if (canModifyGlobal && (AllowCreateOnlyGlobal || radGlobal.Checked)) { // Create global categories only under global categories or root if ((ParentCategory == null) || (ParentCategory.CategoryIsGlobal && !ParentCategory.CategoryIsPersonal)) { newSiteId = 0; } } bool personal = false; bool global = false; if (Category != null) { // Prepare personal and global flag for existing category personal = Category.CategoryIsPersonal; global = Category.CategoryIsGlobal; } else { // Prepare personal and global flag for new category personal = UserID > 0; global = newSiteId == 0; } errorMessage = ValidateForm(personal, global); if (errorMessage == "") { // Need Modify or GlobalModify permission to edit non-personal categories string permission = global ? "GlobalModify" : "Modify"; if (!personal && !CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Categories", permission)) { errorMessage = string.Format(GetString("general.permissionresource"), permission, "CMS.Categories"); } } if (errorMessage == "") { try { CategoryInfo category = null; // Update existing item if (Category != null) { category = Category; if (!category.CategoryIsPersonal) { CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Categories", category.CategoryIsGlobal ? "GlobalModify" : "Modify"); // Update code name only if not personal category category.CategoryName = GetCodeName(); } // Update parent category ID category.CategoryParentID = this.selectParentCategory.CategoryID; EditedObject = category; } else { // Create a new category info category = new CategoryInfo(); // Initialize the default count when creating new category category.CategoryCount = 0; category.CategoryParentID = ParentCategoryID; category.CategoryName = GetCodeName(); if (UserID > 0) { category.CategoryUserID = UserID; } else { category.CategorySiteID = newSiteId; } } if (category != null) { // Update category fields txtDisplayName.Save(); category.CategoryDisplayName = this.txtDisplayName.Text.Trim(); category.CategoryDescription = this.txtDescription.Text; category.CategoryEnabled = this.chkEnabled.Checked; // Save category in the database CategoryInfoProvider.SetCategoryInfo(category); Category = category; if (!string.IsNullOrEmpty(this.RefreshPageURL)) { URLHelper.Redirect(this.RefreshPageURL + "?categoryid=" + Category.CategoryID.ToString() + "&saved=1"); } RaiseOnSaved(); // Display information on success this.lblInfo.Text = GetString("general.changessaved"); this.lblInfo.Visible = true; this.lblError.Visible = false; } } catch (Exception ex) { // Display error message this.lblError.Text = GetString("general.erroroccurred") + " " + ex.Message; this.lblError.Visible = true; } } else { // Display error message this.lblError.Text = errorMessage; this.lblError.Visible = true; } }