protected void lbSaveBrand_Click(object sender, EventArgs e) { string urlKey = txtUrlKey.Text.Trim(); txtUrlKey.BackColor = Color.Empty; // If urlKey is empty, regenerate with given category name if (urlKey == string.Empty) { urlKey = AdminStoreUtility.GetFriendlyUrlKey(txtName.Text.Trim()); txtUrlKey.Text = urlKey; } // Make sure urlKey is unique if (((GetStringState(MODE) == NEW) && (BrandService.GetBrandByUrlKey(urlKey) != null)) || ((GetStringState(MODE) == EDIT) && (BrandService.GetBrandByUrlKey(urlKey) != null) && (BrandService.GetBrandByUrlKey(urlKey).Id != GetIntState(BRAND_ID)))) { enbNotice.Message = "Url Key is not unique."; } else { SaveLastViewedProduct(); Brand brand = new Brand(); brand.Name = Server.HtmlEncode(txtName.Text.Trim()); brand.FlashImageHeight = -1; brand.FlashImageWidth = -1; brand.UrlRewrite = urlKey; string logoFilename = string.Empty; //added string empty to avoid the exception brand.FlashImage = string.Empty; if (fuLogo.HasFile) { logoFilename = brand.UrlRewrite.Trim().ToLower() + "-logo" + Path.GetExtension(fuLogo.FileName).ToLower(); fuLogo.SaveAs(MediaSettings.BrandMediaLocalPath + logoFilename); brand.FlashImage = logoFilename; } // Get old logo filename if (!fuLogo.HasFile && imgLogo.Alt != string.Empty) { brand.FlashImage = imgLogo.Alt; } // Remove logo file if (cbRemoveLogo.Checked && imgLogo.Alt != string.Empty) { File.Delete(MediaSettings.BrandMediaLocalPath + imgLogo.Alt); brand.FlashImage = string.Empty; cbRemoveLogo.Checked = false; } brand.Description = txtDesc.Text.Trim(); brand.HasMicrosite = cbMicrosite.Checked; brand.MetaDescription = txtMetaDesc.Text.Trim(); brand.MetaTitle = txtMetaTitle.Text.Trim(); brand.MetaKeywords = txtMetaKeywords.Text.Trim(); brand.EnforceStockCount = cbEnforceStockCount.Checked; brand.DeliveryId = Convert.ToInt32(ddlDelivery.SelectedValue); brand.Enabled = cbEnabled.Checked; if (GetStringState(MODE) == NEW) { int brandId = BrandService.InsertBrand(brand); brand.Id = brandId; SetState(BRAND_ID, brand.Id); enbNotice.Message = "Brand was created successfully."; } else // Edit mode { brand.Id = GetIntState(BRAND_ID); BrandService.UpdateBrand(brand); if (NotChosenProducts.Count > 0) { BrandService.UpdateProductWithBrand(AppConstant.DEFAULT_BRAND, NotChosenProducts); } enbNotice.Message = "Brand was updated successfully."; } if (ChosenProducts.Count > 0) { BrandService.UpdateProductWithBrand(brand.Id, ChosenProducts); } } ChosenProducts.Clear(); NotChosenProducts.Clear(); LoadProducts(); hfCurrentPanel.Value = "general"; }