/// <summary> /// Bind grid /// </summary> protected void Bind() { UrlRedirectAdmin adminAccess = new UrlRedirectAdmin(); uxGrid.DataSource = adminAccess.Search(txtOldUrl.Text.Trim(), txtNewUrl.Text.Trim(),ddlURLStatus.SelectedValue); uxGrid.DataBind(); }
/// <summary> /// Bind data to the fields /// </summary> protected void BindData() { UrlRedirectAdmin urlRedirectAdmin = new UrlRedirectAdmin(); UrlRedirect urlRedirectEntity = null; if (ItemId > 0) { urlRedirectEntity = urlRedirectAdmin.GetById(ItemId); if (urlRedirectEntity != null) { txtNewUrl.Text = FormattedUrl(urlRedirectEntity.NewUrl); txtOldUrl.Text = FormattedUrl(urlRedirectEntity.OldUrl); chkIsActive.Checked = urlRedirectEntity.IsActive; } } else { // nothing to do here } }
/// <summary> /// Submit Button Click Event - Fires when Submit button is triggered /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { ProductAdmin productAdmin = new ProductAdmin(); Product product = new Product(); string mappedSEOUrl = ""; // If edit mode then get all the values first if (ItemID > 0) { product = productAdmin.GetByProductId(ItemID); if (product.SEOURL != null) mappedSEOUrl = product.SEOURL; } // Set properties product.SEOTitle = txtSEOTitle.Text.Trim(); product.SEOKeywords = txtSEOMetaKeywords.Text.Trim(); product.SEODescription = txtSEOMetaDescription.Text.Trim(); product.SEOURL = null; if (txtSEOUrl.Text.Trim().Length > 0) { product.SEOURL = txtSEOUrl.Text.Trim().Replace(" ", "-"); } bool status = false; // create transaction TransactionManager tranManager = ConnectionScope.CreateTransaction(); try { if (ItemID > 0) //PRODUCT UPDATE { status = productAdmin.Update(product); } } catch (Exception) { //error occurred so rollback transaction tranManager.Rollback(); lblError.Text = "Unable to update product SEO settings. Please try again."; return; } if (status) { UrlRedirectAdmin urlRedirectAdmin = new UrlRedirectAdmin(); bool retval = false; try { retval = urlRedirectAdmin.UpdateUrlRedirectTable(SEOUrlType.Product, mappedSEOUrl, product.SEOURL, ItemID.ToString(), chkAddURLRedirect.Checked); } catch { // error occurred so rollback transaction tranManager.Rollback(); lblError.Text = "The SEO Friendly URL you entered is already in use on another page. Please select another name for your URL"; return; } if (retval) { //Commit transaction tranManager.Commit(); Response.Redirect(ManagePageLink + ItemID); } else { lblError.Text = "Could not update the product SEO Url. Please try again."; } } else { lblError.Text = "Unable to update product SEO settings. Please try again."; } }
/// <summary> /// Event triggered when a command button is clicked on the grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void uxGrid_RowCommand(object sender, GridViewCommandEventArgs e) { // Convert the row index stored in the CommandArgument // property to an Integer. int index = Convert.ToInt32(e.CommandArgument); // Get the values from the appropriate // cell in the GridView control. GridViewRow selectedRow = uxGrid.Rows[index]; TableCell Idcell = selectedRow.Cells[0]; string Id = Idcell.Text; if (e.CommandName == "Edit") { Response.Redirect(EditPageLink + Id); } else if (e.CommandName == "Delete") { UrlRedirectAdmin urlRedirectAdmin = new UrlRedirectAdmin(); UrlRedirect urlRedirect = urlRedirectAdmin.GetById(int.Parse(Id)); bool status = urlRedirectAdmin.Delete(int.Parse(Id)); if (status) { if (urlRedirect != null) { ZNodeSEOUrl seoUrl = new ZNodeSEOUrl(); seoUrl.RemoveRedirectURL(urlRedirect.OldUrl); } Bind(); } } }
/// <summary> /// Submit button click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { System.IO.FileInfo fileInfo = null; CategoryAdmin categoryAdmin = new CategoryAdmin(); Category category = new Category(); string mappedSEOUrl = ""; if (ItemId > 0) { category = categoryAdmin.GetByCategoryId(ItemId); if (category.SEOURL != null) mappedSEOUrl = category.SEOURL; } category.CategoryID = ItemId; category.PortalID = ZNodeConfigManager.SiteConfig.PortalID ; category.Name = txtName.Text; category.ShortDescription = txtshortdescription.Text; category.Description = ctrlHtmlText.Html; category.Title = txtTitle.Text; category.SubCategoryGridVisibleInd = chkSubCategoryGridVisibleInd.Checked; category.SEOTitle = txtSEOTitle.Text; category.SEOKeywords = txtSEOMetaKeywords.Text; category.SEODescription = txtSEOMetaDescription.Text; category.SEOURL = null; if(txtSEOURL.Text.Trim().Length > 0) category.SEOURL = txtSEOURL.Text.Trim().Replace(" ","-"); if (int.Parse(ParentCategoryID.SelectedValue) > 0) { category.ParentCategoryID = int.Parse(ParentCategoryID.SelectedValue); } else { category.ParentCategoryID = null; } category.ImageAltTag = txtImageAltTag.Text.Trim(); category.MasterPage = ddlPageTemplateList.SelectedItem.Text; category.DisplayOrder = int.Parse(DisplayOrder.Text); category.VisibleInd = VisibleInd.Checked; category.Custom1 = RowDropDown.SelectedItem.ToString(); category.Custom2 = ColumnDropDown.SelectedIndex.ToString(); #region Image Validation //Validate image if ((ItemId == 0) || (RadioCategoryNewImage.Checked == true)) { if(UploadCategoryImage.PostedFile.FileName != "") { //Check for Product Image fileInfo = new System.IO.FileInfo(UploadCategoryImage.PostedFile.FileName); if (fileInfo != null) { category.ImageFile = fileInfo.Name; } } } else { category.ImageFile = category.ImageFile; } #endregion //Upload File if this is a new product or the New Image option was selected for an existing product if (RadioCategoryNewImage.Checked || ItemId == 0) { if (fileInfo != null) { UploadCategoryImage.SaveAs(Server.MapPath(ZNodeConfigManager.EnvironmentConfig.OriginalImagePath + fileInfo.Name)); ZNodeImage image = new ZNodeImage(); ZNodeImage.ResizeImage(fileInfo, ZNode.Libraries.Framework.Business.ZNodeConfigManager.SiteConfig.MaxCatalogItemLargeWidth, Server.MapPath(ZNodeConfigManager.EnvironmentConfig.LargeImagePath)); ZNodeImage.ResizeImage(fileInfo, ZNode.Libraries.Framework.Business.ZNodeConfigManager.SiteConfig.MaxCatalogItemThumbnailWidth, Server.MapPath(ZNodeConfigManager.EnvironmentConfig.ThumbnailImagePath)); ZNodeImage.ResizeImage(fileInfo, ZNode.Libraries.Framework.Business.ZNodeConfigManager.SiteConfig.MaxCatalogItemMediumWidth, Server.MapPath(ZNodeConfigManager.EnvironmentConfig.MediumImagePath)); ZNodeImage.ResizeImage(fileInfo, ZNode.Libraries.Framework.Business.ZNodeConfigManager.SiteConfig.MaxCatalogItemSmallWidth, Server.MapPath(ZNodeConfigManager.EnvironmentConfig.SmallImagePath)); ZNodeImage.ResizeImage(fileInfo, ZNode.Libraries.Framework.Business.ZNodeConfigManager.SiteConfig.MaxCatalogItemSwatchWidth, Server.MapPath(ZNodeConfigManager.EnvironmentConfig.SwatchImagePath)); ZNodeImage.ResizeImage(fileInfo, ZNode.Libraries.Framework.Business.ZNodeConfigManager.SiteConfig.MaxCatalogItemCrossSellWidth, Server.MapPath(ZNodeConfigManager.EnvironmentConfig.CrossSellImagePath)); } } bool retval = false; // create transaction TransactionManager tranManager = ConnectionScope.CreateTransaction(); if (ItemId > 0) { retval = categoryAdmin.Update(category); } else { retval = categoryAdmin.Add(category); } if (retval) { UrlRedirectAdmin urlRedirectAdmin = new UrlRedirectAdmin(); bool status = false; try { status = urlRedirectAdmin.UpdateUrlRedirectTable(SEOUrlType.Category, mappedSEOUrl, category.SEOURL, category.CategoryID.ToString(), chkAddURLRedirect.Checked); } catch { //error occurred so rollback transaction tranManager.Rollback(); lblMsg.Text = "The SEO Friendly URL you entered is already in use on another page. Please select another name for your URL."; return; } if (status) //check status whether urlmapping table updated successfully { //Commit transaction tranManager.Commit(); if (ItemId > 0) Response.Redirect("~/admin/secure/catalog/product_category/list.aspx"); else Response.Redirect("~/admin/secure/catalog/product_category/add_next.aspx"); } else { //error occurred so rollback transaction tranManager.Rollback(); lblMsg.Text = "Could not update the product category SEO Url. Please try again."; } } else { if (ItemId > 0) lblMsg.Text = "Could not update the product category. Please try again."; else lblMsg.Text = "Could not add the product category. Please try again."; return; } }
/// <summary> /// Submit button click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { CategoryAdmin categoryAdmin = new CategoryAdmin(); Category category = new Category(); string mappedSEOUrl = ""; if (ItemId > 0) { category = categoryAdmin.GetByCategoryId(ItemId); if (category.SEOURL != null) mappedSEOUrl = category.SEOURL; } category.CategoryID = ItemId; category.PortalID = ZNodeConfigManager.SiteConfig.PortalID; category.ShortDescription = txtshortdescription.Text; category.Description = ctrlHtmlText.Html; category.Title = txtTitle.Text; category.SEOTitle = txtSEOTitle.Text; category.SEOKeywords = txtSEOMetaKeywords.Text; category.SEODescription = txtSEOMetaDescription.Text; category.SEOURL = null; if (txtSEOURL.Text.Trim().Length > 0) category.SEOURL = txtSEOURL.Text.Trim().Replace(" ", "-"); bool retval = false; //create transaction TransactionManager tranManager = ConnectionScope.CreateTransaction(); if (ItemId > 0) { retval = categoryAdmin.Update(category); } if (retval) { UrlRedirectAdmin urlRedirectAdmin = new UrlRedirectAdmin(); bool status = false; try { status = urlRedirectAdmin.UpdateUrlRedirectTable(SEOUrlType.Category, mappedSEOUrl, category.SEOURL, ItemId.ToString(), chkAddURLRedirect.Checked); } catch { //error occurred so rollback transaction tranManager.Rollback(); lblError.Text = "The SEO Friendly URL you entered is already in use on another page. Please select another name for your URL."; return; } if (status) // check status whether urlmapping table updated successfully { // Commit transaction tranManager.Commit(); Response.Redirect(ManagePageLink); } else { //error occurred so rollback transaction tranManager.Rollback(); lblError.Text = "Could not update the product category SEO Url. Please try again."; } } else { if (ItemId > 0) lblError.Text = "Could not update the product category. Please try again."; return; } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { UrlRedirectAdmin urlRedirectAdmin = new UrlRedirectAdmin(); UrlRedirect urlRedirectEntity = new UrlRedirect(); bool status = false; string oldSeoURL = ""; bool activeInd = false; if (ItemId > 0) { urlRedirectEntity = urlRedirectAdmin.GetById(ItemId); oldSeoURL = urlRedirectEntity.OldUrl; activeInd = urlRedirectEntity.IsActive; } urlRedirectEntity.IsActive = chkIsActive.Checked; urlRedirectEntity.OldUrl = MakeUrl(txtOldUrl.Text.Trim()); urlRedirectEntity.NewUrl = MakeUrl(txtNewUrl.Text.Trim()); // create transaction TransactionManager tranManager = ConnectionScope.CreateTransaction(); if (ItemId > 0) { status = urlRedirectAdmin.Update(urlRedirectEntity); } else { status = urlRedirectAdmin.Add(urlRedirectEntity); } if (status) { try { ZNodeSEOUrl seoUrl = new ZNodeSEOUrl(); bool urlRedirectExists = urlRedirectAdmin.Exists(urlRedirectEntity.OldUrl, urlRedirectEntity.NewUrl, urlRedirectEntity.UrlRedirectID); if (ItemId > 0 && activeInd && !chkIsActive.Checked) { status &= seoUrl.RemoveRedirectURL(oldSeoURL); } else if(chkIsActive.Checked && !urlRedirectExists) { status &= seoUrl.AddRedirectUrl(oldSeoURL, urlRedirectEntity.OldUrl, urlRedirectEntity.NewUrl, chkIsActive.Checked); } else if(urlRedirectExists) { status &= false; // error occurred so rollback transaction tranManager.Rollback(); lblMsg.Text = "Unable to update SEO Friendly URL. Please try again."; return; } } catch { status = false; // error occurred so rollback transaction tranManager.Rollback(); lblMsg.Text = "Unable to update SEO Friendly URL. Please try again."; return; } } if (status) { // Commit transaction tranManager.Commit(); Response.Redirect(ListPageLink); } else { // error occurred so rollback transaction tranManager.Rollback(); lblMsg.Text = "Unable to process your request."; } }