Ejemplo n.º 1
0
        //public void getTemperature(int locationId)
        //{
        //  var objCidade = LocalSrv.GetCidadeByIdCached(locationId);

        //  var obj = WeatherSrv.GetWeather(objCidade.Id);

        //  ViewBag.City = obj == null ? string.Empty : obj.City ?? string.Empty;
        //  ViewBag.Description = obj == null ? string.Empty : obj.Description ?? string.Empty;
        //  ViewBag.Icon = obj == null ? string.Empty : obj.Icon ?? string.Empty;
        //  ViewBag.Temperature = obj == null ? string.Empty : obj.Temperature == 0 ? string.Empty : obj.Temperature.ToString();
        //}

        public ActionResult CustomActionEditorial(Editorial objEditorial, int page, string[] listCategoriaId)
        {
            if (objEditorial == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            //Verificação da página
            if (page <= 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            //int totalRegistros;

            var lstNoticiasHighlights = page == 1 ? GetNoticiasByEditorialHighlight(objEditorial.Id) : null;

            //var lstNoticias = GetNoticiasByEditorial(objEditorial.Id, page, out totalRegistros, lstNoticiasHighlights?.Select(s => s.Id).ToList());

            List <NoticiaByCategoria> lstNoticiasByCategoria = new List <NoticiaByCategoria>();

            foreach (var item in listCategoriaId)
            {
                var categoria         = GetCategoriaById(Convert.ToInt32(item));
                var lstNoticiasComImg = GetNoticiasByEditorialComImg(objEditorial.Id, page, lstNoticiasHighlights?.Select(s => s.Id).ToList(), Convert.ToInt32(item));
                var lstNoticiasAux    = GetNoticiasByEditorial(objEditorial.Id, page, lstNoticiasHighlights?.Select(s => s.Id).ToList(), Convert.ToInt32(item));

                var noticiaporcategoria = new NoticiaByCategoria();
                noticiaporcategoria.UrlEditorial = objEditorial.Url;
                noticiaporcategoria.Categoria    = categoria;
                //noticiaporcategoria.NoticiasHighlights = lstNoticiasAux.Where(n => n.ImgLg != null).Take(2).ToList();
                noticiaporcategoria.NoticiasHighlights = lstNoticiasComImg;
                noticiaporcategoria.Noticias           = lstNoticiasAux.Where(n => !noticiaporcategoria.NoticiasHighlights.Any(n2 => n2.Id == n.Id)).Take(3).ToList();

                lstNoticiasByCategoria.Add(noticiaporcategoria);
            }

            var model = new CategoriaModel
            {
                //Base
                Title        = $"{objEditorial.Titulo} - Massa News",
                Description  = $"Leia tudo sobre {objEditorial.Titulo} no Massa News.",
                Robots       = "index, follow",
                Canonical    = $"{Constants.UrlWeb}/{objEditorial.Url}",
                ImgOpenGraph = $"{Constants.UrlWeb}/content/images/avatar/editorial/avatar-{objEditorial.Url}.jpg",
                //Model
                Editorial          = objEditorial,
                NoticiasHighlights = lstNoticiasHighlights?.Select(Service.Models.Noticia.Map).ToList(),
                //Noticias = lstNoticias,
                NoticiaByCategoria = lstNoticiasByCategoria,
                //Pots = lstPostsNegociosDaTerra
            };

            if (objEditorial.Id == 6)
            {
                model.Pots = GetLastPostNegociosDaTerra();
                model.ComunidadeTopicos = ComunidadeService.GetAllTopico().ToList();
            }

            ViewBag.ActiveNav   = objEditorial.Titulo;
            ViewBag.PaginaAtual = page;
            //ViewBag.TotalRegistros = totalRegistros;

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

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

            //Recupera as 4 ultimas notícias que são exibidas na sidebar
            ViewBag.Lastest4News = Service.Models.Noticia.GetLastestNews(4).ToList();

            //Recuper as 5 ultimas notícias mais acessadas
            ViewBag.Popular5News = Service.Models.Noticia.GetMoreAccessedNews(objEditorial.Id);

            ViewBag.Editorial = Service.Models.Editorial.Map(objEditorial);

            ViewBag.ExibirLogo = true;

            if (objEditorial.Id == 4)
            {
                ViewBag.Categorias = NoticiaSrv.GetCategoriasByEditorial(objEditorial.Id);
            }

            ViewBag.TbActiveClassifA = true;
            ViewBag.TbActiveClassifB = false;

            return(View("Editorial", model));
        }