protected void lbSaveBrandCategory_Click(object sender, EventArgs e) { string urlKey = txtUrlKey.Text.Trim(); txtUrlKey.BackColor = Color.Empty; // If url key is empty, regenerate with given category name if (urlKey == string.Empty) { urlKey = AdminStoreUtility.GetFriendlyUrlKey(txtName.Text.Trim()); txtUrlKey.Text = urlKey; } // Make sure url key is unique if (((GetStringState(MODE) == NEW) && (BrandService.GetBrandCategoryByUrlKey(urlKey) != null)) || ((GetStringState(MODE) == EDIT) && (BrandService.GetBrandCategoryByUrlKey(urlKey) != null) && (BrandService.GetBrandCategoryByUrlKey(urlKey).Id != GetIntState(BRAND_CATEGORY_ID)))) { enbNotice.Message = "Url key is not unique."; } else { string thumbnailFilename = string.Empty; if (fuThumbnail.HasFile) { thumbnailFilename = txtUrlKey.Text.Trim() + Path.GetExtension(fuThumbnail.FileName).ToLower(); fuThumbnail.SaveAs(MediaSettings.BrandMediaLocalPath + thumbnailFilename); } else { if (!cbRemoveThumb.Checked) { BrandCategory category = BrandService.GetBrandCategoryByUrlKey(urlKey); if (category != null) { thumbnailFilename = category.ImageUrl; } } } BrandCategory brandCategory = new BrandCategory(); brandCategory.Name = Server.HtmlEncode(txtName.Text.Trim()); brandCategory.BrandId = QueryBrandId; brandCategory.Description = Server.HtmlEncode(txtDesc.Text.Trim()); brandCategory.ImageUrl = thumbnailFilename; brandCategory.UrlRewrite = txtUrlKey.Text.Trim(); brandCategory.Visible = cbVisible.Checked; if (!string.IsNullOrEmpty(hfParent.Value)) { brandCategory.ParentId = Convert.ToInt32(hfParent.Value); } if (GetStringState(MODE) == NEW) { if (string.IsNullOrEmpty(hfParent.Value)) { brandCategory.ParentId = AppConstant.DEFAULT_BRAND_CATEGORY; } brandCategory.Id = BrandService.InsertBrandCategory(brandCategory); } else // Edit mode { brandCategory.Id = GetIntState(LAST_CHOSEN_BRAND_CATEGORY); BrandService.UpdateBrandCategory(brandCategory); } ectBrandCategory.Repopulate(); var treeList = BrandService.GetBrandCategoryTreeList(brandCategory.Id); ectBrandCategory.FindSelectedNode(AppConstant.DEFAULT_BRAND_CATEGORY, treeList); PopulateBrandCategoryInfo(brandCategory.Id); enbNotice.Message = "Brand category was saved successfully."; } cbRemoveThumb.Checked = false; ChosenProducts.Clear(); NotChosenProducts.Clear(); LoadProducts(); }