//[OutputCache(VaryByParam = "id", Duration = 300)] public JsonResult GetCarousel(int id) { List<JsonCarouselItem> jci = null; string jsonString = String.Empty; try { var cache = DataCache.Cache; string cacheKey = "JRGC:U:" + id.ToString() + ";C:" + MyUtility.getCountry(Request.GetUserHostAddressFromCloudflare()).getCode(); try { jsonString = (string)cache[cacheKey]; } catch (Exception) { } if (String.IsNullOrEmpty(jsonString)) { var context = new IPTV2Entities(); jci = new List<JsonCarouselItem>(); Carousel carousel = context.Carousels.FirstOrDefault(c => c.CarouselId == id && c.StatusId == GlobalConfig.Visible); if (carousel != null) { List<CarouselSlide> slides = carousel.CarouselSlides.Where(c => c.StatusId == GlobalConfig.Visible).OrderByDescending(c => c.AuditTrail.UpdatedOn).ThenByDescending(c => c.CarouselSlideId).ToList(); foreach (CarouselSlide slide in slides) { JsonCarouselItem item = new JsonCarouselItem() { CarouselSlideId = slide.CarouselSlideId, BannerImageUrl = String.Format("{0}{1}/{2}", GlobalConfig.CarouselImgPath, slide.CarouselSlideId.ToString(), slide.BannerImageUrl), Blurb = HttpUtility.HtmlEncode(slide.Blurb), Name = slide.Name, Header = slide.Header, TargetUrl = slide.TargetUrl, ButtonLabel = slide.ButtonLabel }; jci.Add(item); } } jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(jci); cache.Put(cacheKey, jsonString, DataCache.CacheDuration); } else jci = Newtonsoft.Json.JsonConvert.DeserializeObject<List<JsonCarouselItem>>(jsonString); } catch (Exception e) { MyUtility.LogException(e); } return Json(jci, JsonRequestBehavior.AllowGet); }
private void FillHomePage(IPTV2Entities context, TimeSpan cacheDuration) { var countries = context.Countries; foreach (var cx in countries) { try { string cacheKey = "SYNAPSEGHOMEPAGE:O:;C:" + cx.Code; SynapseHomepage homepage = new SynapseHomepage(); List<FeatureItem> featureItems = null; var featuredShows = context.Features.FirstOrDefault(f => f.FeatureId == LatestShows && f.StatusId == Visible); if (featuredShows != null) { List<SynapseShow> shows = new List<SynapseShow>(); var fItems = featuredShows.FeatureItems.Where(f => f.StatusId == Visible); if (fItems != null) { featureItems = fItems.ToList(); foreach (var f in featureItems) { if (f is ShowFeatureItem) { ShowFeatureItem sft = (ShowFeatureItem)f; int parentId = 0; string parent = String.Empty; Show show = sft.Show; if (show.IsMobileAllowed(cx.Code)) { foreach (var item in show.ParentCategories.Where(p => p.CategoryId != FreeTvCategoryId)) { parentId = item.CategoryId; parent = item.Description; } string img = String.IsNullOrEmpty(show.ImagePoster) ? AssetsBaseUrl + BlankGif : String.Format("{0}{1}/{2}", ShowImgPath, show.CategoryId.ToString(), show.ImagePoster); string banner = String.IsNullOrEmpty(show.ImageBanner) ? AssetsBaseUrl + BlankGif : String.Format("{0}{1}/{2}", ShowImgPath, show.CategoryId.ToString(), show.ImageBanner); SynapseShow s = new SynapseShow() { id = show.CategoryId, name = show.Description, blurb = show.Blurb, image = img, banner = banner, parent = parent, parentId = parentId }; shows.Add(s); } } } } homepage.show = shows; } var featuredCelebrities = context.Features.FirstOrDefault(f => f.FeatureId == FeaturedCelebrities && f.StatusId == Visible); if (featuredCelebrities != null) { List<SynapseCelebrity> celebrities = new List<SynapseCelebrity>(); var fCelebItems = featuredCelebrities.FeatureItems.Where(f => f.StatusId == Visible); if (fCelebItems != null) { featureItems = fCelebItems.ToList(); foreach (var f in featureItems) { if (f is CelebrityFeatureItem) { CelebrityFeatureItem cft = (CelebrityFeatureItem)f; Celebrity person = cft.Celebrity; string img = String.IsNullOrEmpty(person.ImageUrl) ? AssetsBaseUrl + BlankGif : String.Format("{0}{1}/{2}", CelebrityImgPath, person.CelebrityId.ToString(), person.ImageUrl); SynapseCelebrity c = new SynapseCelebrity() { id = person.CelebrityId, name = person.FullName, image = img }; celebrities.Add(c); } } } homepage.celebrity = celebrities; } var mainCarousel = CarouselEntertainmentId; //hard-coded Carousel carousel = context.Carousels.FirstOrDefault(c => c.CarouselId == mainCarousel && c.StatusId == Visible); if (carousel != null) { var fSlides = carousel.CarouselSlides.Where(c => c.MobileStatusId == Visible).OrderByDescending(c => c.CarouselSlideId); if (fSlides != null) { List<CarouselSlide> slides = fSlides.ToList(); var random = slides.OrderBy(x => System.Guid.NewGuid()).FirstOrDefault(); JsonCarouselItem item = new JsonCarouselItem() { CarouselSlideId = random.CarouselSlideId, BannerImageUrl = String.Format("{0}{1}/{2}", CarouselImgPath, random.CarouselSlideId.ToString(), random.BannerImageUrl), Blurb = random.Blurb, Name = random.Name, Header = random.Header, TargetUrl = random.TargetUrl, ButtonLabel = random.ButtonLabel }; homepage.carousel = item; } } var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(homepage); DataCache.Cache.Put(cacheKey, jsonString, cacheDuration); } catch (Exception e) { Trace.TraceError("FillHomePage Cache - Error! " + e.Message); } } }
public JsonResult GetHomepage() { Response.Filter = new GZipStream(Response.Filter, CompressionMode.Compress); string jsonString = String.Empty; SynapseHomepage homepage = null; try { var countryCode = MyUtility.GetCurrentCountryCodeOrDefault(); var cache = DataCache.Cache; string cacheKey = "SYNAPSEGHOMEPAGE:O:;C:" + countryCode; try { jsonString = (string)cache[cacheKey]; } catch (Exception) { } if (String.IsNullOrEmpty(jsonString)) { homepage = new SynapseHomepage(); var context = new IPTV2Entities(); List<FeatureItem> featureItems = null; var featuredShows = context.Features.FirstOrDefault(f => f.FeatureId == GlobalConfig.LatestShows && f.StatusId == GlobalConfig.Visible); if (featuredShows != null) { List<SynapseShow> shows = new List<SynapseShow>(); var fItems = featuredShows.FeatureItems.Where(f => f.StatusId == GlobalConfig.Visible); if (fItems != null) { featureItems = fItems.ToList(); foreach (var f in featureItems) { if (f is ShowFeatureItem) { ShowFeatureItem sft = (ShowFeatureItem)f; int parentId = 0; string parent = String.Empty; Show show = sft.Show; if (show.IsMobileAllowed(countryCode)) { foreach (var item in show.ParentCategories.Where(p => p.CategoryId != GlobalConfig.FreeTvCategoryId)) { parentId = item.CategoryId; parent = item.Description; } string img = String.IsNullOrEmpty(show.ImagePoster) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, show.CategoryId.ToString(), show.ImagePoster); string banner = String.IsNullOrEmpty(show.ImageBanner) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, show.CategoryId.ToString(), show.ImageBanner); SynapseShow s = new SynapseShow() { id = show.CategoryId, name = show.Description, blurb = show.Blurb, image = img, banner = banner, parent = parent, parentId = parentId }; shows.Add(s); } } } } homepage.show = shows; } var featuredCelebrities = context.Features.FirstOrDefault(f => f.FeatureId == GlobalConfig.FeaturedCelebrities && f.StatusId == GlobalConfig.Visible); if (featuredCelebrities != null) { List<SynapseCelebrity> celebrities = new List<SynapseCelebrity>(); var fCelebItems = featuredCelebrities.FeatureItems.Where(f => f.StatusId == GlobalConfig.Visible); if (fCelebItems != null) { featureItems = fCelebItems.OrderByDescending(f => f.FeatureItemId).ToList(); foreach (var f in featureItems) { if (f is CelebrityFeatureItem) { CelebrityFeatureItem cft = (CelebrityFeatureItem)f; Celebrity person = cft.Celebrity; string img = String.IsNullOrEmpty(person.ImageUrl) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.CelebrityImgPath, person.CelebrityId.ToString(), person.ImageUrl); SynapseCelebrity c = new SynapseCelebrity() { id = person.CelebrityId, name = person.FullName, image = img }; celebrities.Add(c); } } } homepage.celebrity = celebrities; } var mainCarousel = GlobalConfig.CarouselEntertainmentId; //hard-coded Carousel carousel = context.Carousels.FirstOrDefault(c => c.CarouselId == mainCarousel && c.StatusId == GlobalConfig.Visible); if (carousel != null) { var fSlides = carousel.CarouselSlides.Where(c => c.MobileStatusId == GlobalConfig.Visible).OrderByDescending(c => c.CarouselSlideId); if (fSlides != null) { List<CarouselSlide> slides = fSlides.ToList(); var random = slides.OrderBy(x => System.Guid.NewGuid()).FirstOrDefault(); JsonCarouselItem item = new JsonCarouselItem() { CarouselSlideId = random.CarouselSlideId, BannerImageUrl = String.Format("{0}{1}/{2}", GlobalConfig.CarouselImgPath, random.CarouselSlideId.ToString(), random.BannerImageUrl), Blurb = random.Blurb, Name = random.Name, Header = random.Header, TargetUrl = random.TargetUrl, ButtonLabel = random.ButtonLabel }; homepage.carousel = item; } } var cacheDuration = new TimeSpan(0, GlobalConfig.SynapseGenericCacheDuration, 0); jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(homepage); cache.Put(cacheKey, jsonString, cacheDuration); } else homepage = Newtonsoft.Json.JsonConvert.DeserializeObject<SynapseHomepage>(jsonString); } catch (Exception e) { MyUtility.LogException(e); } return Json(homepage, JsonRequestBehavior.AllowGet); }
public PartialViewResult GetFeaturedImageFromCarousel(int id, string partialViewName = "") { List<JsonCarouselItem> jci = null; string jsonString = String.Empty; try { string CountryCode = MyUtility.GetCountryCodeViaIpAddressWithoutProxy(); var cache = DataCache.Cache; string cacheKey = "JRGC:U:" + id + ";C:" + CountryCode; try { jsonString = (string)cache[cacheKey]; } catch (Exception) { } if (String.IsNullOrEmpty(jsonString)) { var context = new IPTV2Entities(); jci = new List<JsonCarouselItem>(); Carousel carousel = context.Carousels.FirstOrDefault(c => c.CarouselId == id && c.StatusId == GlobalConfig.Visible); if (carousel != null) { List<CarouselSlide> slides = carousel.CarouselSlides.Where(c => c.StatusId == GlobalConfig.Visible).OrderByDescending(c => c.AuditTrail.UpdatedOn).ThenByDescending(c => c.CarouselSlideId).ToList(); var MEPacMayCountryCodeList = GlobalConfig.MEPacMayAllowedCountryCodes.Split(','); foreach (var slide in slides) { JsonCarouselItem item = new JsonCarouselItem() { CarouselSlideId = slide.CarouselSlideId, BannerImageUrl = String.Format("{0}{1}/{2}", GlobalConfig.CarouselImgPath, slide.CarouselSlideId.ToString(), slide.BannerImageUrl), Blurb = HttpUtility.HtmlEncode(slide.Blurb), Name = slide.Name, Header = slide.Header, TargetUrl = slide.TargetUrl, ButtonLabel = slide.ButtonLabel }; if (MyUtility.StringToIntList(GlobalConfig.PBBCarouselSlideIds).Contains(slide.CarouselSlideId)) { var PBBCountryCodeList = GlobalConfig.PBBBlockedCountryCodes.Split(','); if (!PBBCountryCodeList.Contains(CountryCode)) jci.Add(item); } else if (MyUtility.StringToIntList(GlobalConfig.BCWMHThanksgivingConcertSlideIds).Contains(slide.CarouselSlideId)) { var BCWMHCountryCodeList = GlobalConfig.BCWMHThanksgivingConcertBlockedCountryCodes.Split(','); if (!BCWMHCountryCodeList.Contains(CountryCode)) jci.Add(item); } else if (MyUtility.StringToIntList(GlobalConfig.USAllowedCarouselIds).Contains(slide.CarouselSlideId)) { if (String.Compare(CountryCode, "US", true) == 0) jci.Add(item); } else if (MyUtility.StringToIntList(GlobalConfig.CAAllowedCarouselIds).Contains(slide.CarouselSlideId)) { if (String.Compare(CountryCode, "CA", true) == 0) jci.Add(item); } else if (MyUtility.StringToIntList(GlobalConfig.MEPacMayCarouselIds).Contains(slide.CarouselSlideId)) { if (MEPacMayCountryCodeList.Contains(CountryCode)) jci.Add(item); } else if (MyUtility.StringToIntList(GlobalConfig.NonMEPacMayCarouselIds).Contains(slide.CarouselSlideId)) { if (!MEPacMayCountryCodeList.Contains(CountryCode)) jci.Add(item); } else jci.Add(item); } } jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(jci); cache.Put(cacheKey, jsonString, DataCache.CacheDuration); } else jci = Newtonsoft.Json.JsonConvert.DeserializeObject<List<JsonCarouselItem>>(jsonString); } catch (Exception e) { MyUtility.LogException(e); } if (!String.IsNullOrEmpty(partialViewName)) return PartialView(partialViewName, jci); return PartialView(jci); }