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);
        }
        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); }
            }
        }