示例#1
0
        public PartialViewResult CreateMenu()
        {
            List<MyMainMenu> mainmenu = new List<MyMainMenu>();
            var menuItemList = GlobalConfig.MainMenuItems.Split(',');
            foreach (string item in menuItemList)
            {
                MyMainMenu menuItem = new MyMainMenu();
                menuItem.name = item;
                menuItem.menu = BuildMenuGroup(item);
                mainmenu.Add(menuItem);
            }

            return PartialView("_Menu", mainmenu);
        }
        public JsonResult GetSiteMenu()
        {
            Response.Filter = new GZipStream(Response.Filter, CompressionMode.Compress);
            int[] mainMenuIds = { 736, 738, 737 };
            List<MyMainMenu> siteMenus = null;
            string jsonString = String.Empty;
            var cache = DataCache.Cache;
            string cacheKey = "SYNGETSITEMENU:0:";
            try { jsonString = (string)cache[cacheKey]; }
            catch (Exception) { }
            if (String.IsNullOrEmpty(jsonString))
            {
                siteMenus = new List<MyMainMenu>();
                foreach (int mainMenuId in mainMenuIds)
                {
                    var context = new IPTV2Entities();
                    Category mainCategory = (Category)context.CategoryClasses.FirstOrDefault(c => c.CategoryId == mainMenuId);
                    List<MyMenu> fullMenu = new List<MyMenu>();
                    string id = String.Format("{0}MenuIds", mainCategory.Description);
                    string menuId = ConfigurationManager.AppSettings[id];
                    var menuids = MyUtility.StringToIntList(menuId);

                    var features = context.Features.Where(f => menuids.Contains(f.FeatureId) && f.StatusId == GlobalConfig.Visible).ToList();

                    Dictionary<int, Feature> d = features.ToDictionary(x => x.FeatureId);
                    List<Feature> ordered = new List<Feature>();
                    foreach (var i in menuids)
                    {
                        if (d.ContainsKey(i))
                            ordered.Add(d[i]);
                    }
                    //var ordered = menuids.Select(i => d[i]).ToList();

                    foreach (var feature in ordered)
                    {
                        var temp = feature.Description.Split('|');

                        var featureItems = feature.FeatureItems.Where(f => f.MobileStatusId == GlobalConfig.Visible);
                        List<MyMenuShows> mms = new List<MyMenuShows>();
                        foreach (var f in featureItems)
                        {
                            if (f is ShowFeatureItem)
                            {
                                ShowFeatureItem sft = (ShowFeatureItem)f;
                                var category = context.CategoryClasses.FirstOrDefault(c => c.CategoryId == sft.CategoryId);
                                if (category != null)
                                {
                                    if (category is Show)
                                    {
                                        Show show = sft.Show;
                                        string img = String.IsNullOrEmpty(show.ImagePoster) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format("{0}{1}/{2}", GlobalConfig.ShowImgPath, show.CategoryId.ToString(), show.ImagePoster);
                                        MyMenuShows m = new MyMenuShows() { name = show.Description, id = show.CategoryId, image = img };
                                        mms.Add(m);
                                    }
                                }
                            }
                        }

                        MyMenu item = new MyMenu()
                        {
                            name = temp[0],
                            id = Convert.ToInt32(temp[1]),
                            shows = mms
                        };

                        if (item.shows.Count > 0)
                            fullMenu.Add(item);
                    }
                    MyMainMenu siteMenu = new MyMainMenu()
                    {
                        id = mainCategory.CategoryId,
                        name = mainCategory.Description,
                        menu = fullMenu
                    };
                    siteMenus.Add(siteMenu);
                }

                var cacheDuration = new TimeSpan(0, GlobalConfig.MenuCacheDuration, 0);
                jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(siteMenus);
                cache.Put(cacheKey, jsonString, cacheDuration);
            }
            else
                siteMenus = Newtonsoft.Json.JsonConvert.DeserializeObject<List<MyMainMenu>>(jsonString);
            return Json(siteMenus, JsonRequestBehavior.AllowGet);
        }
        private void FillSiteMenu(IPTV2Entities context, TimeSpan cacheDuration)
        {
            int[] mainMenuIds = { 736, 738, 737 };
            string cacheKey = "SYNGETSITEMENU:0:";
            try
            {
                List<MyMainMenu> siteMenus = new List<MyMainMenu>();
                foreach (int mainMenuId in mainMenuIds)
                {
                    Category mainCategory = (Category)context.CategoryClasses.FirstOrDefault(c => c.CategoryId == mainMenuId);
                    List<MyMenu> fullMenu = new List<MyMenu>();
                    string id = String.Format("{0}MenuIds", mainCategory.Description);
                    string menuId = RoleEnvironment.GetConfigurationSettingValue(id);
                    var menuids = StringToIntList(menuId);
                    var features = context.Features.Where(f => menuids.Contains(f.FeatureId) && f.StatusId == Visible).ToList();

                    Dictionary<int, Feature> d = features.ToDictionary(x => x.FeatureId);
                    List<Feature> ordered = new List<Feature>();
                    foreach (var i in menuids)
                    {
                        if (d.ContainsKey(i))
                            ordered.Add(d[i]);
                    }

                    foreach (var feature in ordered)
                    {
                        var temp = feature.Description.Split('|');

                        var featureItems = feature.FeatureItems.Where(f => f.MobileStatusId == Visible);
                        List<MyMenuShows> mms = new List<MyMenuShows>();
                        foreach (var f in featureItems)
                        {
                            if (f is ShowFeatureItem)
                            {
                                ShowFeatureItem sft = (ShowFeatureItem)f;
                                var category = context.CategoryClasses.FirstOrDefault(c => c.CategoryId == sft.CategoryId);
                                if (category != null)
                                {
                                    if (category is Show)
                                    {
                                        Show show = sft.Show;
                                        string img = String.IsNullOrEmpty(show.ImagePoster) ? AssetsBaseUrl + BlankGif : String.Format("{0}{1}/{2}", ShowImgPath, show.CategoryId.ToString(), show.ImagePoster);
                                        MyMenuShows m = new MyMenuShows() { name = show.Description, id = show.CategoryId, image = img };
                                        mms.Add(m);
                                    }
                                }
                            }
                        }
                        MyMenu item = new MyMenu()
                        {
                            name = temp[0],
                            id = Convert.ToInt32(temp[1]),
                            shows = mms
                        };

                        if (item.shows.Count > 0)
                            fullMenu.Add(item);
                    }
                    MyMainMenu siteMenu = new MyMainMenu()
                    {
                        id = mainCategory.CategoryId,
                        name = mainCategory.Description,
                        menu = fullMenu
                    };
                    siteMenus.Add(siteMenu);
                }
                var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(siteMenus);                
                DataCache.Cache.Put(cacheKey, jsonString, cacheDuration);
            }
            catch (Exception) { }
        }