Ejemplo n.º 1
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            var fileName      = "redirects.csv".FileNamePlusDate();
            var fileDirectory = FoldersHelper.GetPathAbsolut(FolderType.PriceTemp);

            if (!Directory.Exists(fileDirectory))
            {
                Directory.CreateDirectory(fileDirectory);
            }

            using (var csvWriter = new CsvHelper.CsvWriter(new StreamWriter(fileDirectory + fileName), new CsvConfiguration()
            {
                Delimiter = ";", SkipEmptyRecords = false
            }))
            {
                foreach (var item in new[] { "RedirectFrom", "RedirectTo", "ProductArtNo" })
                {
                    csvWriter.WriteField(item);
                }
                csvWriter.NextRecord();

                foreach (var redirect in RedirectSeoService.GetRedirectsSeo())
                {
                    csvWriter.WriteField(redirect.RedirectFrom);
                    csvWriter.WriteField(redirect.RedirectTo);
                    csvWriter.WriteField(redirect.ProductArtNo);

                    csvWriter.NextRecord();
                }
            }
            Response.Clear();
            CommonHelper.WriteResponseFile(fileDirectory + fileName, fileName);
            Response.End();
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        public static string GetRedirect301(string fromUrl, string absoluteUri)
        {
            absoluteUri = absoluteUri.ToLower();
            if (HasExtention(fromUrl) && !fromUrl.Contains(".aspx"))
            {
                return(null);
            }

            var redirect = RedirectSeoService.GetByInputUrl(fromUrl, absoluteUri);

            if (redirect == null)
            {
                return(null);
            }

            string location = string.Empty;

            if (!string.IsNullOrEmpty(redirect.ProductArtNo))
            {
                var product = Catalog.ProductService.GetProduct(redirect.ProductArtNo);

                location = product != null?GetAbsoluteLink(GetLink(ParamType.Product, product.UrlPath, product.ID))
                               : absoluteUri.Replace(fromUrl, redirect.RedirectTo);
            }
            else
            {
                string absoluteUriEncoded = absoluteUri.Split('/').Select(HttpUtility.UrlDecode).AggregateString('/').ToLower();
                if (absoluteUriEncoded.Contains(redirect.RedirectFrom))
                {
                    location = absoluteUriEncoded.Replace(redirect.RedirectFrom, redirect.RedirectTo);
                }
            }
            return(location);
        }
Ejemplo n.º 4
0
    protected void btnDelete_Click(object sender, System.EventArgs e)
    {
        int id = Int32.Parse(hiddenID.Value);

        RedirectSeoService.DeleteRedirectSeo(id);

        hiddenID.Value = "";
    }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
    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);
            }
        }
    }
Ejemplo n.º 7
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 protected void lbDeleteSelected_Click(object sender, EventArgs e)
 {
     if ((_selectionFilter != null) && (_selectionFilter.Values != null))
     {
         if (!_inverseSelection)
         {
             foreach (var id in _selectionFilter.Values)
             {
                 RedirectSeoService.DeleteRedirectSeo(SQLDataHelper.GetInt(id));
             }
         }
         else
         {
             var itemsIds = _paging.ItemsIds <int>("ID");
             //  List<int> ids = CountryService.GetAllCountryID();
             foreach (int id in itemsIds.Where(id => !_selectionFilter.Values.Contains(id.ToString(CultureInfo.InvariantCulture))))
             {
                 RedirectSeoService.DeleteRedirectSeo(id);
             }
         }
     }
 }