public JsonResult GetMovies()
        {
            Response.Filter = new GZipStream(Response.Filter, CompressionMode.Compress);

            try
            {
                var context = new IPTV2Entities();
                var offering = context.Offerings.FirstOrDefault(o => o.OfferingId == GlobalConfig.offeringId);
                var service = offering.Services.FirstOrDefault(s => s.PackageId == GlobalConfig.serviceId);
                var category = context.CategoryClasses.FirstOrDefault(c => c.CategoryId == GlobalConfig.Movies && c.StatusId == GlobalConfig.Visible);

                List<SynapseShow> list = new List<SynapseShow>();

                string countrycode = MyUtility.GetCurrentCountryCodeOrDefault();
                var setOfMovies = service.GetAllMobileShowIds(countrycode, (Category)category);

                var movies = context.CategoryClasses.Where(c => setOfMovies.Contains(c.CategoryId) && c.StatusId == GlobalConfig.Visible);

                if (movies != null)
                {
                    foreach (var movie in movies)
                    {
                        SynapseShow show = null;
                        if (movie is Show)
                        {
                            string type = "show";
                            var temp = (Show)movie;
                            if (temp is Movie)
                            {
                                type = "movie";
                                var eList = temp.Episodes.OrderByDescending(e => e.Episode.DateAired);
                                if (eList != null)
                                {
                                    var epList = eList.ToList();
                                    List<SynapseEpisode> episodes = new List<SynapseEpisode>();
                                    foreach (var e in epList)
                                    {
                                        string epImg = String.IsNullOrEmpty(e.Episode.ImageAssets.ImageVideo) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.EpisodeImgPath, e.Episode.EpisodeId.ToString(), e.Episode.ImageAssets.ImageVideo);
                                        SynapseEpisode episode = new SynapseEpisode() { id = e.Episode.EpisodeId, name = e.Episode.Description, dateaired = e.Episode.DateAired.Value.ToString("MMM d, yyyy"), synopsis = e.Episode.Synopsis, image = epImg };
                                        episodes.Add(episode);
                                    }
                                    string img = String.IsNullOrEmpty(temp.ImagePoster) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, temp.CategoryId.ToString(), temp.ImagePoster);
                                    string banner = String.IsNullOrEmpty(temp.ImageBanner) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, temp.CategoryId.ToString(), temp.ImageBanner);
                                    show = new SynapseShow() { id = temp.CategoryId, name = temp.Description, blurb = temp.Blurb, image = img, banner = banner, type = type };
                                    var parentcat = temp.CategoryClassParentCategories.FirstOrDefault(c => c.ParentCategory.CategoryId != GlobalConfig.FreeTvCategoryId);
                                    show.parentId = parentcat.ParentId;
                                    show.parent = parentcat.ParentCategory.Description;
                                    show.episodes = episodes;
                                }
                                list.Add(show);
                            }
                        }
                    }
                    return this.Json(list, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception e) { MyUtility.LogException(e); }
            return this.Json(null, JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetEpisodeDetails(int? id)
        {
            Response.Filter = new GZipStream(Response.Filter, CompressionMode.Compress);
            if (id == null)
                id = 0;

            var context = new IPTV2Entities();
            DateTime registDt = DateTime.Now;
            var offering = context.Offerings.FirstOrDefault(o => o.OfferingId == GlobalConfig.offeringId);
            var service = offering.Services.FirstOrDefault(s => s.PackageId == GlobalConfig.serviceId);
            var e = context.Episodes.FirstOrDefault(ep => ep.EpisodeId == id && ep.MobileStatusId == GlobalConfig.Visible && ep.MobileStartDate < registDt && ep.MobileEndDate > registDt);
            SynapseEpisode episode = null;
            if (e != null)
            {
                EpisodeCategory category = e.EpisodeCategories.FirstOrDefault(ec => ec.Episode.MobileStatusId == GlobalConfig.Visible);
                Show show = null;
                if (category != null)
                    show = category.Show;

                string epImg = String.IsNullOrEmpty(e.ImageAssets.ImageVideo) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.EpisodeImgPath, e.EpisodeId.ToString(), e.ImageAssets.ImageVideo);
                episode = new SynapseEpisode() { id = e.EpisodeId, name = e.Description, dateaired = e.DateAired.Value.ToString("MMM d, yyyy"), synopsis = e.Synopsis, image = epImg, show = show.Description };

                return this.Json(episode, JsonRequestBehavior.AllowGet);
            }

            return this.Json(String.Empty, JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetShowDetails(int? id, int? status)
        {
            Response.Filter = new GZipStream(Response.Filter, CompressionMode.Compress);
            if (id == null)
                id = 0;

            var context = new IPTV2Entities();
            DateTime registDt = DateTime.Now;
            var offering = context.Offerings.FirstOrDefault(o => o.OfferingId == GlobalConfig.offeringId);
            var service = offering.Services.FirstOrDefault(s => s.PackageId == GlobalConfig.serviceId);
            var category = context.CategoryClasses.FirstOrDefault(c => c.CategoryId == id && c.StatusId == GlobalConfig.Visible);
            SynapseShow show = null;
            if (category != null)
            {
                if (category is Show)
                {
                    var countryCode = MyUtility.GetCurrentCountryCodeOrDefault();
                    var showT = (Show)category;
                    if (!showT.IsMobileAllowed(countryCode))
                        return this.Json(String.Empty, JsonRequestBehavior.AllowGet);

                    string type = "show";
                    // Check if movie
                    var temp = (Show)category;
                    int parentId = 0;
                    string parent = String.Empty;
                    foreach (var item in temp.ParentCategories.Where(p => p.CategoryId != GlobalConfig.FreeTvCategoryId))
                    {
                        if (item.CategoryClassParentCategories.Where(p => p.ParentId == GlobalConfig.Movies && p.ParentId != GlobalConfig.FreeTvCategoryId).Count() > 0)
                            type = "movie";

                        parentId = item.CategoryId;
                        parent = item.Description;

                    }

                    //IOrderedEnumerable<EpisodeCategory> eList;
                    var episodeCategories = context.EpisodeCategories1.Where(e => e.CategoryId == category.CategoryId && e.Episode.MobileStatusId == GlobalConfig.Visible).Select(e => e.EpisodeId);
                    var episodeList = context.Episodes.Where(e => episodeCategories.Contains(e.EpisodeId) && e.MobileStatusId == GlobalConfig.Visible && e.MobileStartDate < registDt && e.MobileEndDate > registDt)
                        .OrderByDescending(e => e.DateAired);

                    if (episodeList != null)
                    {
                        //var epList = eList.ToList();
                        List<SynapseEpisode> episodes = new List<SynapseEpisode>();
                        foreach (var e in episodeList)
                        {
                            string epImg = String.IsNullOrEmpty(e.ImageAssets.ImageVideo) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.EpisodeImgPath, e.EpisodeId.ToString(), e.ImageAssets.ImageVideo);
                            string EpLength = "";
                            if (!(e.EpisodeLength == null))
                            {
                                TimeSpan span = new TimeSpan(0, 0, Convert.ToInt32(e.EpisodeLength) * 60);
                                EpLength = String.Format("{0}:{1}:{2}", span.Hours.ToString().PadLeft(2, '0'), span.Minutes.ToString().PadLeft(2, '0'), span.Seconds.ToString().PadLeft(2, '0'));
                            }
                            SynapseEpisode episode = new SynapseEpisode() { id = e.EpisodeId, name = e.Description, dateaired = e.DateAired.Value.ToString("MMM d, yyyy"), synopsis = e.Synopsis, image = epImg, episodelength = EpLength, episodenumber = e.EpisodeNumber, expirydate = e.EndDate.Value.ToString("MM/dd/yyyy hh:mm:ss"), oexpirydate = e.OnlineEndDate.Value.ToString("MM/dd/yyyy hh:mm:ss"), mexpirydate = e.MobileEndDate.Value.ToString("MM/dd/yyyy hh:mm:ss"), statusid = e.MobileStatusId };
                            episodes.Add(episode);

                        }

                        string img = String.IsNullOrEmpty(category.ImagePoster) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, category.CategoryId.ToString(), category.ImagePoster);
                        string banner = String.IsNullOrEmpty(category.ImageBanner) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, category.CategoryId.ToString(), category.ImageBanner);
                        show = new SynapseShow() { id = category.CategoryId, name = category.Description, blurb = category.Blurb, image = img, banner = banner, type = type, parent = parent, parentId = parentId };
                        show.episodes = episodes;
                    }
                }

                return this.Json(show, JsonRequestBehavior.AllowGet);
            }
            return this.Json(String.Empty, JsonRequestBehavior.AllowGet);
        }