protected void grid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteRedirectSeo") { RedirectSeoService.DeleteRedirectSeo(SQLDataHelper.GetInt(e.CommandArgument)); } if (e.CommandName == "AddRedirectSeo") { GridViewRow footer = grid.FooterRow; var txtNexRedirectFrom = ((TextBox)footer.FindControl("txtNexRedirectFrom")).Text.Trim().ToLower(); var txtNewRedirectTo = ((TextBox)footer.FindControl("txtNewRedirectTo")).Text.Trim().ToLower(); var txtNewProductArtNo = ((TextBox)footer.FindControl("txtNewProductArtNo")).Text.Trim(); if (string.IsNullOrEmpty(txtNexRedirectFrom) || (string.IsNullOrEmpty(txtNewRedirectTo) && string.IsNullOrEmpty(txtNewProductArtNo))) { grid.FooterStyle.BackColor = System.Drawing.Color.FromName("#ffcccc"); return; } var redirectSeo = new RedirectSeo { RedirectFrom = txtNexRedirectFrom, RedirectTo = txtNewRedirectTo, ProductArtNo = txtNewProductArtNo }; RedirectSeoService.AddRedirectSeo(redirectSeo); grid.ShowFooter = false; } if (e.CommandName == "CancelAdd") { grid.FooterStyle.BackColor = System.Drawing.Color.FromName("#ccffcc"); grid.ShowFooter = false; } }
protected void btnAddResirects_Click(object sender, EventArgs e) { string[] lines = redirects.Value.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { string[] words = line.Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (words.Length == 2) { var redirect = new RedirectSeo { RedirectFrom = (words[0][0] != '/') ? "/" + words[0] : words[0], RedirectTo = (words[1][0] != '/') ? "/" + words[1] : words[1] }; RedirectSeoService.AddRedirectSeo(redirect); } } }
protected void btnImport_Click(object sender, EventArgs e) { if (!fuImportFile.HasFile) { return; } var filePath = FoldersHelper.GetPathAbsolut(FolderType.PriceTemp); var fileName = "redirectsImport.csv"; var fullFileName = filePath + fileName.FileNamePlusDate(); FileHelpers.CreateDirectory(filePath); fuImportFile.SaveAs(fullFileName); using (var csvReader = new CsvHelper.CsvReader(new StreamReader(fullFileName), new CsvConfiguration() { Delimiter = ";" })) { while (csvReader.Read()) { var currentRecord = new RedirectSeo { RedirectFrom = csvReader.GetField <string>("RedirectFrom"), RedirectTo = csvReader.GetField <string>("RedirectTo"), ProductArtNo = csvReader.GetField <string>("ProductArtNo") }; var redirect = RedirectSeoService.GetRedirectsSeoByRedirectFrom(currentRecord.RedirectFrom); if (redirect == null) { RedirectSeoService.AddRedirectSeo(currentRecord); } else { currentRecord.ID = redirect.ID; RedirectSeoService.UpdateRedirectSeo(currentRecord); } } } }