Example #1
0
 public void Update(UrlRedirect item, UrlRedirect oldItem)
 {
     UpdateOrAdd(item, oldItem);
 }
        protected void btndownload_Click(object sender, EventArgs e)
        {
            var allRecords = Repository.GetAll();

            if (allRecords.Any())
            {
                StringBuilder csvHeader = new StringBuilder();
                StringBuilder csv       = new StringBuilder(10 * allRecords.Count * 3);

                for (int recordCount = 0; recordCount < allRecords.Count; recordCount++)
                {
                    UrlRedirect   urlRedirect = allRecords[recordCount];
                    StringBuilder csvRow      = new StringBuilder(10 * allRecords.Count() * 3);

                    for (int c = 0; c < 4; c++)
                    {
                        object columnValue;

                        if (c != 0)
                        {
                            csvRow.Append(",");
                        }

                        switch (c)
                        {
                        case 0:
                            columnValue = urlRedirect.SiteName;
                            break;

                        case 1:
                            columnValue = urlRedirect.OldUrl;
                            break;

                        case 2:
                            columnValue = urlRedirect.NewUrl;
                            break;

                        default:
                            columnValue = urlRedirect.IsPermanent ? "301" : "302";
                            break;
                        }
                        if (columnValue == null)
                        {
                            csvRow.Append("");
                        }
                        else
                        {
                            string columnStringValue  = columnValue.ToString();
                            string cleanedColumnValue = CleanCSVString(columnStringValue);
                            csvRow.Append(cleanedColumnValue);
                        }
                    }
                    csv.AppendLine(csvRow.ToString());
                }

                HttpContext context = HttpContext.Current;
                context.Response.Clear();

                context.Response.Write(csvHeader);
                context.Response.Write(csv.ToString());
                context.Response.Write(Environment.NewLine);

                context.Response.ContentType = "text/csv";
                context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + "RedirectUrls" + ".csv");
                context.Response.End();
            }
            else
            {
                this.btndownload.Visible  = false;
                lblSuccessMessage.Text    = "No Records found to Export Redirects.";
                lblSuccessMessage.Visible = true;
            }
        }
Example #3
0
 public void Add(UrlRedirect item)
 {
     UpdateOrAdd(item, item);
 }
Example #4
0
        public ActionResult BlogPosts(string categoria, string blog, int p = 1)
        {
            if (categoria == null || blog == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            var objBlog = Db.Blogs.FirstOrDefault(b => b.Url == blog);

            if (objBlog == null)
            {
                var    slugBlogNotFound = $"/blogs/{categoria}/{blog}/posts";
                string urlDestino       = UrlRedirect.GetByUrl(slugBlogNotFound);

                if (!string.IsNullOrEmpty(urlDestino))
                {
                    return(new RedirectResult($"{urlDestino}"));
                }
                else
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                }
            }

            if (objBlog.Categoria.Url != categoria)
            {
                return(new RedirectResult($"/blogs/{objBlog.Categoria.Url}/{objBlog.Url}/posts/", true));
            }

            ViewBag.TotalRegistros = objBlog.Noticias.Count;

            //Get the list of blog autors
            var lstAutors = Autor.GetAllByBlogId(objBlog.Id).ToList();

            //Set the path in the images
            lstAutors.ForEach(a => a.Avatar = $"{Constants.UrlDominioEstaticoUploads}/{"autores"}/{a.Avatar}");

            var model = new BlogPostViewModel
            {
                Blog   = objBlog,
                Autors = lstAutors
            };

            var lstNoticiasHighlights = GetNoticiasByBlogHighlight(objBlog.CategoriaId, objBlog.Id);

            var noticias = objBlog.Noticias.Where(post => post.StatusId == Status.Publicada.Id)
                           .OrderByDescending(b => b.DataPublicacao)
                           .Skip((p - 1) * Constants.TakeNoticias)
                           .Take(Constants.TakeNoticias)
                           .ToList();


            if (p == 1)
            {
                model.NoticiasHighlights = lstNoticiasHighlights?.Select(Service.Models.Noticia.Map).ToList();
            }


            model.Blog.Noticias = noticias.Where(n => !lstNoticiasHighlights.Any(n2 => n2.Id == n.Id)).ToList();



            //Paginação
            ViewBag.PaginaAtual = p;

            var totalPaginas = Math.Ceiling(((double)ViewBag.TotalRegistros / Constants.TakeNoticias));

            if (Convert.ToInt32(totalPaginas) > 1)
            {
                ViewBag.Paginacao = Pagination.AddPagination(ViewBag.PaginaAtual, Convert.ToInt32(totalPaginas), 5, true);
            }

            //base model defaults
            model.Title        = $"Blog {objBlog.Titulo} - Massa News";
            model.Description  = $"{objBlog.Descricao} Confira o Blog {objBlog.Titulo}!";
            model.Robots       = "index, follow";
            model.Canonical    = $"{Constants.UrlWeb}/blogs/{categoria}/{blog}/posts";
            model.ImgOpenGraph = $"{Constants.UrlWeb}/content/images/avatar/blogs/{blog}.jpg";

            ViewBag.ActiveNav = objBlog.Titulo;

            // Página
            ViewBag.Pagina = "blog";

            // Editoria
            ViewBag.EditoriaUrl = "blogs";

            // Categoria
            ViewBag.Categoria = model.Blog.Categoria.Url;

            // Blog
            ViewBag.Blog = model.Blog.Url;

            return(View(model));
        }
Example #5
0
 public UrlRedirect_Metadata()
 {
     UrlRedirect map = new UrlRedirect();
 }
Example #6
0
 public static T ToUrlRedirectEntity <T>(this UrlRedirect model)
     where T : IUrlRedirectEntity, new()
 {
     return(ToUrlRedirectEntity(model, new T()));
 }
        private ActionResult LoadIndexNews(string editorialUrl, string categoryUrl, string blogurl, string newsUrl, bool isPreview = false)
        {
            try
            {
                var newsId = ToolService.GetIdByUrl(Request.Url.ToString());

                //Get the news object
                var objNoticia = null as Noticia;

                if (newsId.HasValue)
                {
                    objNoticia = Noticia.Load(newsId.Value);
                }

                if (objNoticia == null)
                {
                    objNoticia = Noticia.GetByUrl(newsUrl);
                }

                #region Validations
                //Redirect 301 to new url
                if (!isPreview)
                {
                    #region Redirect

                    var originUrl = Request.RawUrl.Remove(Request.RawUrl.Length - 5);

                    if (objNoticia != null)
                    {
                        if (originUrl != objNoticia.UrlFull)
                        {
                            return(new RedirectResult($"{objNoticia.UrlFull}.html", true));
                        }
                    }
                    else
                    {
                        var redirectUrl = UrlRedirect.GetByUrl(originUrl);

                        if (!string.IsNullOrEmpty(redirectUrl))
                        {
                            return(new RedirectResult($"{redirectUrl}.html", true));
                        }
                    }

                    #endregion
                }

                if (objNoticia == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                }

                if (objNoticia.Autores != null && objNoticia.Autores.Count() > 0)
                {
                    //19 = Estadão, 65 = Folhapress
                    var objAutorGoogleNews = objNoticia.Autores.Where(a => a.Id == 19 || a.Id == 65).FirstOrDefault();

                    ViewBag.isAutorGoogleNews = objAutorGoogleNews != null ? true : false;
                }

                //Caso a noticia for inativa responde com redirect permanente para a home
                if ((objNoticia.StatusId == Status.Inativa.Id || !objNoticia.Categoria.Status) && !isPreview)
                {
                    return(new RedirectResult("/", true));
                }

                //Caso a noticia for diferente de publicada responde com 404
                if (objNoticia.StatusId != Status.Publicada.Id && !isPreview)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                }

                #endregion

                //Recupera a origem
                var urlReferrer = Request.UrlReferrer?.AbsolutePath.TrimEnd('/') ?? string.Empty;

                //Ultimas Notícias
                var lastestNews = new List <Noticia>();

                //Get the location id
                var locationId = CookieFx.GetLocationId(Request);

                //Get the user city
                var objCidade = Cidade.Load(locationId);

                //getTemperature(locationId);

                if (urlReferrer.StartsWith("/tag"))
                {
                    var tagUrl = urlReferrer.Split('/').Last();

                    var tag = Tag.GetByUrl(tagUrl);

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

                    var isNewsWithTag = false;

                    var newsWithTag = NoticiaSrv.GetTagsByNewsIdCached(objNoticia.Id);

                    foreach (var item in newsWithTag)
                    {
                        if (item.Id == tag.Id)
                        {
                            isNewsWithTag = true;
                            break;
                        }
                    }

                    if (isNewsWithTag)
                    {
                        lastestNews = GetValuesOfTag(urlReferrer, objNoticia).ToList();
                    }
                    else if (editorialUrl == "blogs")
                    {
                        lastestNews = GetValuesOfBlogCategory(objNoticia).ToList();
                    }
                    else
                    if (objNoticia.CidadeId.HasValue && objNoticia.CategoriaUrl.Equals("plantao"))
                    {
                        if (objNoticia.Cidade.MicroregiaoId == objCidade.MicroregiaoId)
                        {
                            lastestNews = GetValuesOfMyRegion(objCidade.MicroregiaoId, objNoticia).ToList();
                        }
                        else if (objNoticia.Cidade.MicroregiaoId != objCidade.MicroregiaoId)
                        {
                            lastestNews = GetValuesOfParana(objCidade.MicroregiaoId, objNoticia).ToList();
                        }
                    }
                    else if (!objNoticia.CidadeId.HasValue && objNoticia.CategoriaUrl.Equals("plantao"))
                    {
                        lastestNews = GetValuesOfParana(objCidade.MicroregiaoId, objNoticia).ToList();
                    }
                    else
                    {
                        lastestNews = GetValuesOfCategory(objNoticia).ToList();
                    }
                }
                else if (urlReferrer.StartsWith("/fotos"))
                {
                    lastestNews = GetValuesOfGallery().ToList();
                }
                else if (editorialUrl == "blogs")
                {
                    lastestNews = GetValuesOfBlogCategory(objNoticia).ToList();
                }
                else
                {
                    if (objNoticia.CidadeId.HasValue)
                    {
                        //If the news has the category 'plantao'
                        if (objNoticia.CategoriaUrl.Equals("plantao"))
                        {
                            if (objNoticia.Cidade.MicroregiaoId == objCidade.MicroregiaoId)
                            {
                                //Sua Região
                                lastestNews = GetValuesOfMyRegion(objCidade.MicroregiaoId, objNoticia).ToList();
                            }
                            else if (objNoticia.Cidade.MicroregiaoId != objCidade.MicroregiaoId)
                            {
                                //Paraná
                                lastestNews = GetValuesOfParana(objCidade.MicroregiaoId, objNoticia).ToList();
                            }
                        }
                        else
                        {
                            //If the news is's category 'plantao
                            lastestNews = GetValuesOfCategory(objNoticia).ToList();
                        }
                    }
                    else
                    {
                        //If the news has the category 'plantao'
                        if (objNoticia.CategoriaUrl.Equals("plantao"))
                        {
                            //Paraná
                            lastestNews = GetValuesOfParana(objCidade.MicroregiaoId, objNoticia).ToList();
                        }
                        else
                        {
                            //If the news is's category 'plantao
                            lastestNews = GetValuesOfCategory(objNoticia).ToList();
                        }
                    }
                }

                //Habilita Comentários
                ViewBag.AllowComments = !isPreview;

                //Caso a notícia exista na lista é removida para evitar duplicidade
                if (lastestNews.Any(n => n.Id == objNoticia.Id))
                {
                    lastestNews.Remove(lastestNews.Single(n => n.Id == objNoticia.Id));
                }

                //insere noticia na lista de notícias
                lastestNews.Insert(0, objNoticia);

                ViewBag.NavItems = lastestNews.Select(n => new NoticiaNavItem(n, lastestNews.IndexOf(n).Equals(0)));

                ViewBag.Lastest4News = lastestNews.Take(4).ToList();

                //Set the list of categories
                if (objNoticia.Categoria.EditorialId == 4 && ViewBag.NavigationType == "categoria")
                {
                    ViewBag.Categorias      = NoticiaSrv.GetCategoriasByEditorial(objNoticia.Categoria.EditorialId);
                    ViewBag.MenuCategoriaId = objNoticia.Categoria.CategoriaPaiId.HasValue ? objNoticia.Categoria.CategoriaPaiId : objNoticia.Categoria.Id;
                }

                ViewBag.AmpLink = $"{Constants.UrlWeb}/amp{objNoticia.UrlFull}.html";

                /* base model defaults */
                var model = new NoticiaModel
                {
                    //Title = $"{objNoticia.Titulo} - Massa News {objNoticia.Cidade.Nome}",
                    Description = $"{(objNoticia.Conteudo.Length > 220 ? Text.RemoveHtmlTags(objNoticia.Conteudo.Substring(0, 220) + "... Leia mais no Massa News!") : Text.RemoveHtmlTags(objNoticia.Conteudo) + " Leia no Massa News!")}",
                    Robots      = isPreview ? "noindex, nofollow" : "index, follow",
                    Canonical   = $"{Constants.UrlWeb}{objNoticia.UrlFull}.html",
                    News        = new NewsItemViewModel(objNoticia, ControllerContext)
                };

                if (objNoticia.Cidade != null && !string.IsNullOrEmpty(objNoticia.Cidade.Nome))
                {
                    model.Title = $"{objNoticia.Titulo} - Massa News {objNoticia.Cidade.Nome}";
                }
                else if (objNoticia.Blog != null && !string.IsNullOrEmpty(objNoticia.Blog.Titulo))
                {
                    model.Title = $"{objNoticia.Titulo} - {objNoticia.Blog.Titulo} - Massa News";
                }
                else
                {
                    model.Title = $"{objNoticia.Titulo} - Massa News";
                }

                if (!string.IsNullOrEmpty(objNoticia.ImgLg))
                {
                    model.ImgOpenGraph = $"{Constants.UrlDominioEstaticoUploads}/{"noticias"}/{objNoticia.ImgLg}";
                }
                else if (objNoticia.Blog != null)
                {
                    model.ImgOpenGraph = $"{Constants.UrlWeb}/content/images/avatar/blogs/{objNoticia.Blog.Url}.jpg";
                }

                // Página
                ViewBag.Pagina = "interna";

                // ID
                ViewBag.Id = objNoticia.Id;

                // Editoria
                ViewBag.EditoriaUrl = objNoticia.EditorialUrl;

                // Categoria
                ViewBag.Categoria = objNoticia.CategoriaUrl;

                return(View("index", model));
            }
            catch (Exception ex)
            {
                var vars = new Dictionary <string, string>
                {
                    { "Editorial", editorialUrl },
                    { "Category", categoryUrl },
                    { "NewsUrl", newsUrl }
                };

                NewRelic.Api.Agent.NewRelic.NoticeError(ex, vars);

                throw;
            }
        }
Example #8
0
    /// <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.";
        }
    }