public PartialViewResult GetEntitlements()
        {
            List<EntitlementDisplay> list = null;
            try
            {
                if (User.Identity.IsAuthenticated)
                {
                    using (var context = new IPTV2Entities())
                    {
                        var userId = new System.Guid(User.Identity.Name);
                        User user = context.Users.FirstOrDefault(u => u.UserId == userId);
                        if (user != null)
                        {
                            var entitlements = context.Entitlements.Where(t => t.UserId == user.UserId && t.OfferingId == GlobalConfig.offeringId).OrderByDescending(t => t.EndDate);
                            if (entitlements != null)
                            {
                                list = new List<EntitlementDisplay>();
                                foreach (Entitlement entitlement in entitlements)
                                {
                                    EntitlementDisplay disp = new EntitlementDisplay()
                                    {
                                        EntitlementId = entitlement.EntitlementId,
                                        ExpiryDate = entitlement.EndDate,
                                        ExpiryDateStr = entitlement.EndDate.ToString("MMMM d, yyyy")
                                    };

                                    if (entitlement is PackageEntitlement)
                                    {
                                        var pkg = (PackageEntitlement)entitlement;
                                        disp.PackageId = pkg.PackageId;
                                        disp.PackageName = pkg.Package.Description;
                                        disp.Content = disp.PackageName;
                                    }
                                    else if (entitlement is ShowEntitlement)
                                    {
                                        var show = (ShowEntitlement)entitlement;
                                        disp.CategoryId = show.CategoryId;
                                        disp.CategoryName = show.Show.Description;
                                        disp.Content = disp.CategoryName;
                                    }
                                    else if (entitlement is EpisodeEntitlement)
                                    {
                                        var episode = (EpisodeEntitlement)entitlement;
                                        disp.EpisodeId = episode.EpisodeId;
                                        disp.EpisodeName = episode.Episode.Description + ", " + episode.Episode.DateAired.Value.ToString("MMMM d, yyyy");
                                        disp.Content = disp.EpisodeName;
                                    }
                                    list.Add(disp);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) { MyUtility.LogException(e); }
            return PartialView(list);
        }
        public JsonResult MyVideos()
        {
            if (!GlobalConfig.IsSynapseEnabled)
                return Json(null, JsonRequestBehavior.AllowGet);

            DateTime registDt = DateTime.Now;
            List<EntitlementDisplay> display = new List<EntitlementDisplay>();
            if (User.Identity.IsAuthenticated)
            {
                System.Guid userId = new System.Guid(User.Identity.Name);
                var context = new IPTV2Entities();
                User user = context.Users.FirstOrDefault(u => u.UserId == userId);
                if (user != null)
                {
                    var entitlements = context.Entitlements.Where(t => t.UserId == user.UserId && t.OfferingId == GlobalConfig.offeringId && t.EndDate > registDt).OrderByDescending(t => t.EndDate).ToList();
                    var offering = context.Offerings.Find(GlobalConfig.offeringId);
                    var service = offering.Services.FirstOrDefault(s => s.PackageId == GlobalConfig.serviceId && s.StatusId == GlobalConfig.Visible);
                    SortedSet<int> mobileShowIds = new SortedSet<int>();
                    try
                    {
                        mobileShowIds = service.GetAllMobileShowIds(user.CountryCode);
                    }
                    catch (Exception) { }

                    foreach (Entitlement entitlement in entitlements)
                    {
                        EntitlementDisplay disp = new EntitlementDisplay();

                        disp.EntitlementId = entitlement.EntitlementId;
                        disp.ExpiryDate = entitlement.EndDate;
                        disp.ExpiryDateStr = entitlement.EndDate.ToString("yyyy-MM-ddThh:mm:ss");
                        //disp.ExpiryDateStr = entitlement.EndDate.ToString("yyyy-MM-dd");
                        if (entitlement is PackageEntitlement)
                        {
                            var pkg = (PackageEntitlement)entitlement;
                            disp.PackageId = pkg.PackageId;
                            disp.PackageName = pkg.Package.Description;
                            disp.Content = disp.PackageName;
                        }
                        else if (entitlement is ShowEntitlement)
                        {
                            var show = (ShowEntitlement)entitlement;
                            if (mobileShowIds.Contains(show.CategoryId))
                            {
                                if (!(show.Show is LiveEvent))
                                {
                                    disp.CategoryId = show.CategoryId;
                                    disp.CategoryName = show.Show.Description;
                                    disp.Content = disp.CategoryName;
                                }
                            }
                        }
                        else if (entitlement is EpisodeEntitlement)
                        {
                            var episode = (EpisodeEntitlement)entitlement;
                            disp.EpisodeId = episode.EpisodeId;
                            disp.EpisodeName = episode.Episode.Description + ", " + episode.Episode.DateAired.Value.ToString("MMM d, yyyy");
                            disp.Content = disp.EpisodeName;
                        }

                        display.Add(disp);
                    }
                }
            }
            return this.Json(display, JsonRequestBehavior.AllowGet);
        }
        private List<EntitlementDisplay> ShowEntitlements()
        {
            List<EntitlementDisplay> display = new List<EntitlementDisplay>();
            if (User.Identity.IsAuthenticated)
            {
                System.Guid userId = new System.Guid(User.Identity.Name);
                var context = new IPTV2Entities();
                User user = context.Users.FirstOrDefault(u => u.UserId == userId);
                if (user != null)
                {
                    var entitlements = context.Entitlements.Where(t => t.UserId == user.UserId && t.OfferingId == GlobalConfig.offeringId).OrderByDescending(t => t.EndDate).ToList();

                    foreach (Entitlement entitlement in entitlements)
                    {
                        EntitlementDisplay disp = new EntitlementDisplay();

                        disp.EntitlementId = entitlement.EntitlementId;
                        disp.ExpiryDate = entitlement.EndDate;
                        //disp.ExpiryDateStr = entitlement.EndDate.ToString("MMM. dd, yyyy hh:mm:ss tt");
                        //disp.ExpiryDateStr = entitlement.EndDate.ToString("MM/dd/yyyy hh:mm:ss tt");
                        disp.ExpiryDateStr = entitlement.EndDate.ToString("MM/dd/yyyy");
                        if (entitlement is PackageEntitlement)
                        {
                            var pkg = (PackageEntitlement)entitlement;
                            disp.PackageId = pkg.PackageId;
                            disp.PackageName = pkg.Package.Description;
                            disp.Content = disp.PackageName;
                        }
                        else if (entitlement is ShowEntitlement)
                        {
                            var show = (ShowEntitlement)entitlement;
                            disp.CategoryId = show.CategoryId;
                            disp.CategoryName = show.Show.Description;
                            disp.Content = disp.CategoryName;
                        }
                        else if (entitlement is EpisodeEntitlement)
                        {
                            var episode = (EpisodeEntitlement)entitlement;
                            disp.EpisodeId = episode.EpisodeId;
                            disp.EpisodeName = episode.Episode.Description + ", " + episode.Episode.DateAired.Value.ToString("MMM. dd, yyyy");
                            disp.Content = disp.EpisodeName;
                        }

                        display.Add(disp);
                    }
                }
            }
            return display;
        }
        public JsonResult GetSubscriptionList()
        {
            List<EntitlementDisplay> list = null;
            try
            {
                if (User.Identity.IsAuthenticated)
                {
                    var registDt = DateTime.Now;
                    using (var context = new IPTV2Entities())
                    {
                        var listofPackagesToBeIncluded = MyUtility.StringToIntList(GlobalConfig.ListOfAirPlusPackageIds);
                        var userId = new System.Guid(User.Identity.Name);
                        User user = context.Users.FirstOrDefault(u => u.UserId == userId);
                        if (user != null)
                        {
                            var entitlements = context.Entitlements.Where(t => t.UserId == user.UserId && t.OfferingId == GlobalConfig.offeringId).OrderByDescending(t => t.EndDate);
                            if (entitlements != null)
                            {
                                list = new List<EntitlementDisplay>();
                                foreach (Entitlement entitlement in entitlements)
                                {
                                    EntitlementDisplay disp = new EntitlementDisplay()
                                    {
                                        EntitlementId = entitlement.EntitlementId,
                                        ExpiryDate = entitlement.EndDate,
                                        ExpiryDateStr = entitlement.EndDate.ToString("yyyy-MM-ddThh:mm:ss")
                                    };

                                    if (entitlement is PackageEntitlement)
                                    {
                                        var pkg = (PackageEntitlement)entitlement;
                                        if (listofPackagesToBeIncluded.Contains(pkg.PackageId))
                                        {
                                            disp.PackageId = pkg.PackageId;
                                            disp.PackageName = pkg.Package.Description;
                                            disp.Content = disp.PackageName;
                                            list.Add(disp);
                                        }
                                    }
                                    //else if (entitlement is ShowEntitlement)
                                    //{
                                    //    var show = (ShowEntitlement)entitlement;
                                    //    disp.CategoryId = show.CategoryId;
                                    //    disp.CategoryName = show.Show.Description;
                                    //    disp.Content = disp.CategoryName;
                                    //}
                                    //else if (entitlement is EpisodeEntitlement)
                                    //{
                                    //    var episode = (EpisodeEntitlement)entitlement;
                                    //    disp.EpisodeId = episode.EpisodeId;
                                    //    disp.EpisodeName = episode.Episode.Description + ", " + episode.Episode.DateAired.Value.ToString("MMMM d, yyyy");
                                    //    disp.Content = disp.EpisodeName;
                                    //}
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) { MyUtility.LogException(e); }
            return this.Json(list, JsonRequestBehavior.AllowGet);
        }