public override void OnActionExecuted(ActionExecutedContext filterContext) { var request = filterContext.HttpContext.Request; //Recupera o id da cidade que está gravada no cookie var cidadeId = CookieFx.GetLocationId(request); //Get current city object var currentCity = Cidade.Load(cidadeId); //Set the whether GetTemperature(filterContext, cidadeId); //Current city if (filterContext.Controller.ViewBag.CurrentCity == null) { filterContext.Controller.ViewBag.CurrentCity = currentCity; } //Microregions if (filterContext.Controller.ViewBag.Microregions == null) { filterContext.Controller.ViewBag.Microregions = Microregiao.GetAllUrlToDictionary(); } //Cities if (filterContext.Controller.ViewBag.Cidades == null) { filterContext.Controller.ViewBag.Cidades = new SelectList(Cidade.GetAllToDictionary(), "Key", "Value", cidadeId); } }
public ActionResult Subscribe(NewsletterSubscribe model) { //Get the user city var cityId = CookieFx.GetLocationId(Request); var objNewsletter = new Newsletter { Nome = model.Nome, Email = model.Email, CidadeId = cityId }; objNewsletter.Subscribe(); return(Json("ok")); }
private string GetKeyByCustonParmeters(HttpContext context, string custom) { var request = new HttpRequestWrapper(context.Request); switch (custom) { case "Microregion": { var locationId = CookieFx.GetLocationId(request); var city = Cidade.Load(locationId); return($"MicroregiaoId:{city.MicroregiaoId}"); } case "Location": { var locationId = CookieFx.GetLocationId(request); return($"Location:{locationId}"); } case "Origin": { var origem = context.Request.UrlReferrer?.AbsolutePath.TrimEnd('/') ?? string.Empty; if (origem.StartsWith("/tag")) { return("Origin:Tag"); } if (origem.StartsWith("/fotos")) { return("Origin:Fotos"); } if (origem.StartsWith("/videos")) { return("Origin:Videos"); } return("Origin:Default"); } default: { return(base.GetVaryByCustomString(context, custom)); } } }
public ActionResult LoadNexNews(string noticiaUrl, bool allowComments) { //Recupera a origem var origem = Request.UrlReferrer?.AbsolutePath.TrimEnd('/') ?? string.Empty; //Get the location id var locationId = CookieFx.GetLocationId(Request); //Remove .html noticiaUrl = noticiaUrl.Remove(noticiaUrl.Length - 5, 5); var url = noticiaUrl.TrimStart('/').Split('/').Last(); var objNoticia = Noticia.GetByUrl(url); ViewBag.AllowComments = allowComments; return(PartialView("_NoticiaItem", new NewsItemViewModel(objNoticia, ControllerContext))); }
public ActionResult LoadNexNavegationLink(string firstId, string scopeId, string publishDate, string navegationType) { var first = Convert.ToInt32(firstId.Split('-').Last()); int idScope; int.TryParse(scopeId, out idScope); var locationId = CookieFx.GetLocationId(Request); //Get the user city var objCidade = Cidade.Load(locationId); var objNoticia = (Noticia)null; switch (navegationType) { case "plantao": { //Sua Região objNoticia = NoticiaSrv.GetNextNewsCached(objCidade.MicroregiaoId, DateTime.Parse(publishDate), new[] { first }); break; } case "parana": { //Paraná objNoticia = NoticiaSrv.GetNextNewsCached(objCidade.MicroregiaoId, DateTime.Parse(publishDate), new[] { first }, true); break; } case "categoria": { //Categoria objNoticia = NoticiaSrv.GetNextNewsByCategoryCached(idScope, DateTime.Parse(publishDate), new[] { first }); break; } case "tags": { //Tags objNoticia = NoticiaSrv.GetNextNewsByTagCached(idScope, DateTime.Parse(publishDate), new[] { first }); break; } case "fotos": { //Fotos objNoticia = NoticiaSrv.GetNextNewsByFeaturedCached(Destaque.Galeria.Id, DateTime.Parse(publishDate), new[] { first }); break; } case "videos": //Videos objNoticia = NoticiaSrv.GetNextNewsByFeaturedCached(Destaque.Video.Id, DateTime.Parse(publishDate), new[] { first }); break; case "blog": { //Categoria objNoticia = NoticiaSrv.GetNextNewsByBlog(idScope, DateTime.Parse(publishDate), new[] { first }); break; } } return(objNoticia == null ? null : PartialView("_NavItem", new NoticiaNavItem(objNoticia, false))); }
private ActionResult LoadIndexNews(string editorialUrl, string categoryUrl, string blogurl, string newsUrl, bool isPreview = false) { try { // redirect where curitiba if (editorialUrl == "where-curitiba") { return(new RedirectResult("http://www.wherecuritiba.com.br", true)); } 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.Categoria.Editorial.Url; ViewBag.EditoriaTitulo = objNoticia.Categoria.Editorial.Titulo; // Categoria ViewBag.Categoria = objNoticia.CategoriaUrl; //Formata Noticia Site Antigo Negocio da Terra if (editorialUrl == "negocios-da-terra" && objNoticia.DataPublicacao < new DateTime(2017, 09, 12)) { var aux = model.News.News.Conteudo.Split('\n'); model.News.News.Conteudo = ""; foreach (var item in aux) { if (!String.IsNullOrEmpty(item)) { model.News.News.Conteudo = model.News.News.Conteudo + "<p>" + item + "</p>"; } } } 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; } }
public ActionResult Index() { var city = Cidade.Load(CookieFx.GetLocationId(Request)); return(RedirectToAction("Category", new { uf = "pr", city = city.Url, category = "destaque" })); }
public ActionResult Index(ContaViewModel model) { model.Usuario.CityId = CookieFx.GetLocationId(Request); if (!ModelState.IsValid) { var vm = BuildIndexViewModel(); vm.Usuario = model.Usuario; return(View(vm)); } if (string.IsNullOrEmpty(model.Usuario.PrimeiroNome)) { ModelState.AddModelError("Usuario.PrimeiroNome", "Nome obrigatório!"); var vm = BuildIndexViewModel(); vm.Usuario = model.Usuario; return(View(vm)); } if (!string.IsNullOrEmpty(model.Usuario.DataNascimento)) { DateTime dataValida; if (!DateTime.TryParse(model.Usuario.DataNascimento, out dataValida)) { ModelState.AddModelError("Usuario.DataNascimento", "Data de nascimento inválida!"); var vm = BuildIndexViewModel(); vm.Usuario = model.Usuario; return(View(vm)); } if (Convert.ToDateTime(model.Usuario.DataNascimento) > DateTime.Now.AddYears(-16)) { ModelState.AddModelError("Usuario.DataNascimento", "Idade permitida acima de 16 anos!"); var vm = BuildIndexViewModel(); vm.Usuario = model.Usuario; return(View(vm)); } } if (!string.IsNullOrEmpty(model.Usuario.Cpf)) { if (!Text.ValidaCpf(model.Usuario.Cpf)) { ModelState.AddModelError("Usuario.Cpf", "CPF inválido!"); var vm = BuildIndexViewModel(); vm.Usuario = model.Usuario; return(View(vm)); } } model.Usuario.NoticiasPersonalizadas = model.Usuario.NoticiasPersonalizadasCheckbox > 0; try { CurrentUser.Update(model.Usuario); var cookieUserName = Request.Cookies["username"]; if (cookieUserName == null) { cookieUserName = new HttpCookie("username"); } cookieUserName.Value = model.Usuario.PrimeiroNome.ToString(); Response.Cookies.Add(cookieUserName); } catch (Exception exc) { ModelState.AddModelError("", exc); return(View(model)); } return(RedirectToAction("Index")); //ViewBag.ActiveNav = "Minha conta"; ///* base model defaults */ //model.Title = "Meus dados - Massa News"; //model.Description = "Meus dados de cadastro - Massa News"; //model.Robots = "noindex, nofollow"; //model.Canonical = $"{Constants.UrlWeb}/minha-conta"; //return View(model); }