/// <summary> /// Handles the OptionCategoryGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void OptionCategoryGrid_OnAction(string actionName, object actionArgument) { int categoryId = ValidationHelper.GetInteger(actionArgument, 0); // Set actions if (actionName == "edit") { URLHelper.Redirect("OptionCategory_Edit.aspx?CategoryID=" + categoryId + "&siteId=" + SelectSite.SiteID); } else if (actionName == "delete") { OptionCategoryInfo categoryObj = OptionCategoryInfoProvider.GetOptionCategoryInfo(categoryId); if (!ECommerceContext.IsUserAuthorizedToModifyOptionCategory(categoryObj)) { // Check module permissions if (categoryObj.CategoryIsGlobal) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify"); } else { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyProducts"); } } // Check dependencies if (OptionCategoryInfoProvider.CheckDependencies(categoryId)) { // Show error message ShowError(GetString("Ecommerce.DeleteDisabled")); return; } // Delete option category from database OptionCategoryInfoProvider.DeleteOptionCategoryInfo(categoryObj); } }
/// <summary> /// Handles the OptionCategoryGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void OptionCategoryGrid_OnAction(string actionName, object actionArgument) { int categoryId = ValidationHelper.GetInteger(actionArgument, 0); switch (actionName.ToLowerCSafe()) { case "edit": URLHelper.Redirect(UIContextHelper.GetElementUrl(ModuleName.ECOMMERCE, "EditOptionCategory", false, categoryId)); break; case "delete": OptionCategoryInfo categoryObj = OptionCategoryInfoProvider.GetOptionCategoryInfo(categoryId); if (categoryObj == null) { break; } // Check permissions if (!ECommerceContext.IsUserAuthorizedToModifyOptionCategory(categoryObj)) { // Check module permissions if (categoryObj.CategoryIsGlobal) { RedirectToAccessDenied(ModuleName.ECOMMERCE, EcommercePermissions.ECOMMERCE_MODIFYGLOBAL); } else { RedirectToAccessDenied(ModuleName.ECOMMERCE, "EcommerceModify OR ModifyProducts"); } } // Check category dependencies if (categoryObj.Generalized.CheckDependencies()) { // Show error message ShowError(EcommerceUIHelper.GetDependencyMessage(categoryObj)); return; } DataSet options = SKUInfoProvider.GetSKUOptions(categoryId, false); // Check option category options dependencies if (!DataHelper.DataSourceIsEmpty(options)) { // Check if some attribute option is not used in variant if (categoryObj.CategoryType == OptionCategoryTypeEnum.Attribute) { var optionIds = DataHelper.GetIntegerValues(options.Tables[0], "SKUID"); // Check if some variant is defined by this option DataSet variants = VariantOptionInfoProvider.GetVariantOptions() .TopN(1) .Column("VariantSKUID") .WhereIn("OptionSKUID", optionIds); if (!DataHelper.DataSourceIsEmpty(variants)) { // Option is used in some variant ShowError(GetString("com.option.categoryoptiosusedinvariant")); return; } } // Check other dependencies (shopping cart, order) foreach (DataRow option in options.Tables[0].Rows) { var skuid = ValidationHelper.GetInteger(option["SKUID"], 0); var sku = SKUInfoProvider.GetSKUInfo(skuid); if (SKUInfoProvider.CheckDependencies(skuid)) { // Show error message ShowError(EcommerceUIHelper.GetDependencyMessage(sku)); return; } } } // Delete option category from database OptionCategoryInfoProvider.DeleteOptionCategoryInfo(categoryObj); break; } }