Example #1
0
        public JsonResult GetCurrentShow()
        {
            var ReturnCode = new ShowListDisplay()
            {
                Name = String.Empty
            };

            try
            {
                var context = new IPTV2Entities();
                DateTime utc = DateTime.Now.ToUniversalTime();
                DateTime gmt = utc.AddHours(8); //convert to GMT
                var dow = (int)gmt.DayOfWeek;
                var channels = GlobalConfig.ProjectAirProgramScheduleChannelIds.Split(','); //Channel Id (Sunday-Saturday)
                var psChannelId = Convert.ToInt32(channels[dow]); //ProgramSchedule Channel Id                               

                var sked = context.ProgramSchedules.Where(p => p.ChannelId == psChannelId);
                if (sked != null)
                    if (sked.Count() > 0)
                    {
                        var military_time = gmt.ToString("HH:mm");
                        var current_show = sked.FirstOrDefault(s => military_time.CompareTo(s.StartTime) >= 0 && military_time.CompareTo(s.EndTime) <= 0);
                        if (current_show != null)
                            ReturnCode.Name = current_show.ShowName;
                    }
            }
            catch (Exception e) { MyUtility.LogException(e); }
            return Json(ReturnCode, JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetShows(string id, int? currentCategoryId, int type = 0)
        {
            List<ShowListDisplay> list = null;
            var cache = DataCache.Cache;
            string cacheKey = "SUBSGSWS:O:" + id + ";T:" + type + ";CCID:" + currentCategoryId;
            list = (List<ShowListDisplay>)cache[cacheKey];
            if (list == null)
            {
                list = new List<ShowListDisplay>();
                try
                {
                    var registDt = DateTime.Now;
                    var countryCode = MyUtility.GetCurrentCountryCodeOrDefault();
                    var context = new IPTV2Entities();
                    var offering = context.Offerings.Find(GlobalConfig.offeringId);
                    var service = offering.Services.FirstOrDefault(o => o.PackageId == GlobalConfig.serviceId);

                    if (type == 0) // id is a package id, ALL
                    {
                        if (!String.IsNullOrEmpty(id))
                        {
                            var packageIds = MyUtility.StringToIntList(id);
                            var pkgType = context.PackageTypes.Where(p => packageIds.Contains(p.PackageId));
                            if (pkgType != null)
                            {
                                foreach (var pkg in pkgType)
                                {
                                    if (pkg.Categories != null)
                                    {
                                        foreach (var c in pkg.Categories)
                                        {
                                            var catS = (Category)context.CategoryClasses.Find(c.CategoryId);
                                            if (catS.StatusId == GlobalConfig.Visible && catS.StartDate < registDt && catS.EndDate > registDt)
                                            {
                                                var subcategories = catS.SubCategories.Where(s => s.StatusId == GlobalConfig.Visible && s.StartDate < registDt && s.EndDate > registDt);
                                                if (subcategories.Count() > 0)
                                                {
                                                    foreach (var s in subcategories)
                                                    {
                                                        var showIds = service.GetAllOnlineShowIds(countryCode, s);
                                                        var categories = context.CategoryClasses.Where(cc => showIds.Contains(cc.CategoryId));
                                                        if (categories != null)
                                                        {
                                                            foreach (var cat in categories)
                                                            {
                                                                if (cat.StatusId == GlobalConfig.Visible && cat.StartDate < registDt && cat.EndDate > registDt && cat is Show)
                                                                {
                                                                    string img = String.IsNullOrEmpty(cat.ImagePoster) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, cat.CategoryId, cat.ImagePoster);
                                                                    var item = new ShowListDisplay()
                                                                    {
                                                                        CategoryId = cat.CategoryId,
                                                                        Name = MyUtility.Ellipsis(cat.Description, 35),
                                                                        ImgUrl = img,
                                                                        ParentCategoryId = s.CategoryId,
                                                                        ParentCategoryName = s.Description
                                                                    };
                                                                    list.Add(item);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    var showIds = service.GetAllOnlineShowIds(countryCode, catS);
                                                    var categories = context.CategoryClasses.Where(cc => showIds.Contains(cc.CategoryId));
                                                    if (categories != null)
                                                    {
                                                        foreach (var cat in categories)
                                                        {
                                                            if (cat.StatusId == GlobalConfig.Visible && cat.StartDate < registDt && cat.EndDate > registDt && cat is Show)
                                                            {
                                                                string img = String.IsNullOrEmpty(cat.ImagePoster) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, cat.CategoryId, cat.ImagePoster);
                                                                var item = new ShowListDisplay()
                                                                {
                                                                    CategoryId = cat.CategoryId,
                                                                    Name = MyUtility.Ellipsis(cat.Description, 35),
                                                                    ImgUrl = img,
                                                                    ParentCategoryId = catS.CategoryId,
                                                                    ParentCategoryName = catS.Description
                                                                };
                                                                list.Add(item);
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (type == 1) // id is a category
                    {
                        if (!String.IsNullOrEmpty(id))
                        {
                            int cId = 0;
                            if (Int32.TryParse(id, out cId))
                            {
                                if (cId > 0)
                                {
                                    var category = (Category)context.CategoryClasses.Find(cId);
                                    if (category.StatusId == GlobalConfig.Visible && category.StartDate < registDt && category.EndDate > registDt)
                                    {
                                        var subcategories = category.SubCategories.Where(s => s.StatusId == GlobalConfig.Visible && s.StartDate < registDt && s.EndDate > registDt);
                                        if (subcategories.Count() > 0)
                                        {
                                            foreach (var s in subcategories)
                                            {
                                                var showIds = service.GetAllOnlineShowIds(countryCode, s);
                                                var categories = context.CategoryClasses.Where(cc => showIds.Contains(cc.CategoryId));
                                                if (categories != null)
                                                {
                                                    foreach (var cat in categories)
                                                    {
                                                        if (cat.StatusId == GlobalConfig.Visible && cat.StartDate < registDt && cat.EndDate > registDt && cat is Show)
                                                        {
                                                            string img = String.IsNullOrEmpty(cat.ImagePoster) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, cat.CategoryId, cat.ImagePoster);
                                                            var item = new ShowListDisplay()
                                                            {
                                                                CategoryId = cat.CategoryId,
                                                                Name = MyUtility.Ellipsis(cat.Description, 35),
                                                                ImgUrl = img,
                                                                ParentCategoryId = s.CategoryId,
                                                                ParentCategoryName = s.Description
                                                            };
                                                            list.Add(item);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            var categoryS = (Category)context.CategoryClasses.Find(cId);
                                            var showIds = service.GetAllOnlineShowIds(countryCode, categoryS);
                                            var categories = context.CategoryClasses.Where(cc => showIds.Contains(cc.CategoryId));
                                            if (categories != null)
                                            {
                                                foreach (var cat in categories)
                                                {
                                                    if (cat.StatusId == GlobalConfig.Visible && cat.StartDate < registDt && cat.EndDate > registDt && cat is Show)
                                                    {
                                                        string img = String.IsNullOrEmpty(cat.ImagePoster) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, cat.CategoryId, cat.ImagePoster);
                                                        var item = new ShowListDisplay()
                                                        {
                                                            CategoryId = cat.CategoryId,
                                                            Name = MyUtility.Ellipsis(cat.Description, 35),
                                                            ImgUrl = img,
                                                            ParentCategoryId = categoryS.CategoryId,
                                                            ParentCategoryName = categoryS.Description
                                                        };
                                                        list.Add(item);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }
                    else if (type == 2) //ala carte
                    {
                        if (!String.IsNullOrEmpty(id))
                        {
                            int cId = 0;
                            if (Int32.TryParse(id, out cId))
                            {
                                if (cId > 0)
                                {
                                    var sShow = context.CategoryClasses.Find(cId);
                                    if (sShow.StatusId == GlobalConfig.Visible && sShow.StartDate < registDt && sShow.EndDate > registDt && sShow is Show)
                                    {
                                        string img = String.IsNullOrEmpty(sShow.ImagePoster) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, sShow.CategoryId, sShow.ImagePoster);
                                        var item = new ShowListDisplay()
                                        {
                                            CategoryId = sShow.CategoryId,
                                            Name = MyUtility.Ellipsis(sShow.Description, 35),
                                            ImgUrl = img,
                                            ParentCategoryId = 0,
                                            ParentCategoryName = ""
                                        };
                                        list.Add(item);
                                    }
                                }
                            }
                        }
                    }

                    //position swap!
                    if (currentCategoryId != null)
                    {
                        var index = list.FindIndex(x => x.CategoryId == currentCategoryId);
                        var item = list[index];
                        list[index] = list[0];
                        list[0] = item;
                    }

                    var cacheDuration = new TimeSpan(0, GlobalConfig.PackageAndProductCacheDuration, 0);
                    //cache.Put(cacheKey, list, cacheDuration);
                }
                catch (Exception e) { MyUtility.LogException(e); }
            }
            return Json(list, JsonRequestBehavior.AllowGet);
        }