protected void Page_PreRender(object sender, EventArgs e) { if (grid.UpdatedRow != null) { var redirectSeo = new RedirectSeo { ID = SQLDataHelper.GetInt(grid.UpdatedRow["ID"]), RedirectFrom = grid.UpdatedRow["RedirectFrom"].Trim().ToLower(), RedirectTo = grid.UpdatedRow["RedirectTo"].Trim().ToLower(), ProductArtNo = grid.UpdatedRow["ProductArtNo"] }; RedirectSeoService.UpdateRedirectSeo(redirectSeo); } DataTable data = _paging.PageItems; while (data.Rows.Count < 1 && _paging.CurrentPageIndex > 1) { _paging.CurrentPageIndex--; data = _paging.PageItems; } var clmn = new DataColumn("IsSelected", typeof(bool)) { DefaultValue = _inverseSelection }; data.Columns.Add(clmn); if ((_selectionFilter != null) && (_selectionFilter.Values != null)) { for (int i = 0; i <= data.Rows.Count - 1; i++) { int intIndex = i; if (Array.Exists(_selectionFilter.Values, c => c == data.Rows[intIndex]["ID"].ToString())) { data.Rows[i]["IsSelected"] = !_inverseSelection; } } } if (data.Rows.Count < 1) { goToPage.Visible = false; } grid.DataSource = data; grid.DataBind(); pageNumberer.PageCount = _paging.PageCount; lblFound.Text = _paging.TotalRowsCount.ToString(); }
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); } } } }