Exemplo n.º 1
0
        public ActionResult MagazineNews(Int32 id)
        {
            var user     = UserService.GetCurrentUser();
            var relation = UserService.UserInMagazine(id, user.UserId);

            if (!relation || !ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Magazines"));
            }

            Request.Cookies.Remove("MagazineId");
            SetCookie("MagazineId", id, true);

            if (Request.Cookies["MagazineId"].Value == null)
            {
                SetMessage("Lo sentimos, ha ocurrido un error. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Magazines"));
            }

            var magazine = MagazineService.GetMagazineById(id);

            if (magazine == null)
            {
                SetMessage("Lo sentimos, la revista no existe. Inténtelo de nuevo con una distinta.", BootstrapAlertTypes.Danger);
                return(RedirectToAction("Index", "Magazines"));
            }

            var mostUsedCat   = MagazineService.MostUsedCat(id);
            var mostViewedCat = MagazineService.MostViewedCat(id);

            var mostUsedCatName = "Ninguna";

            if (mostUsedCat != null)
            {
                mostUsedCatName = mostUsedCat.Name;
            }

            var mostViewedCatName = "Ninguna";

            if (mostViewedCat != null)
            {
                mostViewedCatName = mostViewedCat.Name;
            }

            var mostViewedCatCount = 0;

            if (mostViewedCat != null)
            {
                mostViewedCatCount = MagazineService.GetVisitsByCategoryId(mostViewedCat.CategoryId);
            }

            var mostUsedCatCount = 0;

            if (mostUsedCat != null)
            {
                mostUsedCatCount = MagazineService.MostUsedCatCount(mostUsedCat.CategoryId);
            }

            var newsAndVisits = MagazineService.GetNewsWithVisitsByMagazineId(id);

            var viewsCounts = 0;

            if (newsAndVisits != null)
            {
                viewsCounts = newsAndVisits.TotalVisits;
            }

            var newsCount = 0;

            if (newsAndVisits != null)
            {
                newsCount = newsAndVisits.TotalNews;
            }

            var model = new MagazineIndexViewModel
            {
                MagazineId         = id,
                MostUsedCat        = mostUsedCatName,
                MostViewedCat      = mostViewedCatName,
                MostViewedCatCount = mostViewedCatCount,
                MostUsedCatCount   = mostUsedCatCount,
                ViewsCount         = viewsCounts,
                NewsCount          = newsCount,
            };
            //TOP 10 STATISTICS

            var GetNews = MagazineService.GetNewsByMagazineId(id);

            var top10Count = new List <Last10CountModel>();

            foreach (var item in GetNews)
            {
                var addNew = new Last10CountModel
                {
                    NewsId   = item.NewsId,
                    NewTitle = item.Title,
                    Count    = (item.VisitsCount ?? 0)
                };

                top10Count.Add(addNew);
            }

            var top10Visited    = top10Count.OrderByDescending(x => x.Count).Take(10);
            var last10Published = top10Count.Take(10);

            ViewBag.Top10Visited    = JsonConvert.SerializeObject(top10Visited);
            ViewBag.Last10Published = JsonConvert.SerializeObject(last10Published);

            //REPORTES
            var reportsList = MagazineService.GetMyReports(id);

            var reportList = new List <ReportViewModel>();

            foreach (var item in reportsList)
            {
                var report = new ReportViewModel
                {
                    ReportId  = item.MediaId,
                    Impact    = MagazineService.getProm(item.MediaId),
                    MediaName = MagazineService.getMedioName(item.MediaId)
                };

                reportList.Add(report);
            }

            ViewBag.Reports = null;
            if (reportsList.Count > 0)
            {
                ViewBag.Reports = reportList;
            }

            ViewBag.JsonReports = JsonConvert.SerializeObject(reportList);

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult MyNews()
        {
            if (Request.Cookies["MagazineId"].Value == null)
            {
                SetMessage("Lo sentimos, ha ocurrido un error. Inténtelo de nuevo.", BootstrapAlertTypes.Danger); return(RedirectToAction("Index", "Magazines"));
            }

            var id = Int32.Parse(Request.Cookies["MagazineId"].Value);

            var user     = UserService.GetCurrentUser();
            var relation = UserService.UserInMagazine(id, user.UserId);

            if (!relation || !ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Magazines"));
            }

            var news = MagazineService.GetNewsByMagazineId(id);

            var cats = MagazineService.GetCategoriesByMagazineId(id);

            if (cats.Count == 0)
            {
                return(RedirectToAction("CreateCategory", "Wizard", new { id = id }));
            }
            var mags = MagazineService.GetCurrentUserMagazines();
            List <MagazineToCLone> magList = new List <MagazineToCLone>();

            foreach (var item in mags)
            {
                var magModel = new MagazineToCLone()
                {
                    MagazineId = item.MagazineId,
                    Title      = item.Title
                };
                magList.Add(magModel);
            }
            //var top10Influencers = MagazineService.GetTop10Influencers(id);

            var model = new MagazineIndexViewModel
            {
                MagazineId = id,
                Categories = cats,
                //Top10Influencers = top10Influencers,
                News = news
            };

            //var magazines = MagazineService.GetCurrentUserMagazines();
            //var allCats = new List<Category>();
            //foreach (var item in magazines)
            //{
            //    var items = MagazineService.GetCategoriesByMagazineId(item.MagazineId);
            //    foreach (var a in items) { allCats.Add(a); }
            //}

            //ViewBag.Visits = JsonConvert.SerializeObject(newsAndVisits.VisitCounts);
            //ViewBag.Categories = JsonConvert.SerializeObject(allCats, Formatting.None, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
            ViewBag.Magazines = JsonConvert.SerializeObject(magList, Formatting.Indented, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(View(model));
        }