List <Lib.ViewModels.MixPages.ReadListItemViewModel> GetCategory(MixEnums.CatePosition position, string seoName) { var result = new List <Lib.ViewModels.MixPages.ReadListItemViewModel>(); var cacheKey = $"page_position_{position}"; var data = _memoryCache.Get <List <Lib.ViewModels.MixPages.ReadListItemViewModel> >(cacheKey); if (data != null && MixService.GetConfig <bool>("IsCache")) { result = data; } else { var getTopCates = Lib.ViewModels.MixPages.ReadListItemViewModel.Repository.GetModelListBy (c => c.Specificulture == _culture && c.MixPagePosition.Any( p => p.PositionId == (int)position) ); result = getTopCates.Data ?? new List <Lib.ViewModels.MixPages.ReadListItemViewModel>(); foreach (var cate in result) { switch (cate.Type) { case MixPageType.Blank: foreach (var child in cate.Childs) { child.Page.DetailsUrl = GenerateDetailsUrl("Page", new { seoName = child.Page.SeoName }); } break; case MixPageType.StaticUrl: cate.DetailsUrl = cate.StaticUrl; break; case MixPageType.Home: case MixPageType.ListArticle: case MixPageType.Article: case MixPageType.Modules: default: cate.DetailsUrl = GenerateDetailsUrl("Page", new { seoName = cate.SeoName }); break; } } } foreach (var cate in result) { cate.IsActived = (cate.SeoName == seoName || (cate.Type == MixPageType.Home && string.IsNullOrEmpty(seoName))); cate.Childs.ForEach((Action <Lib.ViewModels.MixPagePages.ReadViewModel>)(c => { c.IsActived = ( c.Page.SeoName == seoName); cate.IsActived = cate.IsActived || c.IsActived; })); } return(result); }
public static List <ViewModels.MixPages.ReadListItemViewModel> GetCategory(IUrlHelper Url, string culture, MixEnums.CatePosition position, string activePath = "") { var getTopCates = ViewModels.MixPages.ReadListItemViewModel.Repository.GetModelListBy (c => c.Specificulture == culture && c.MixPagePosition.Any( p => p.PositionId == (int)position) ); var cates = getTopCates.Data ?? new List <ViewModels.MixPages.ReadListItemViewModel>(); activePath = activePath.ToLower(); foreach (var cate in cates) { switch (cate.Type) { case MixPageType.Blank: foreach (var child in cate.Childs) { child.DetailsUrl = Url.RouteUrl("Page", new { culture, seoName = child.SeoName }); } break; case MixPageType.StaticUrl: cate.DetailsUrl = cate.StaticUrl; break; case MixPageType.Home: case MixPageType.ListArticle: case MixPageType.Article: case MixPageType.Modules: default: cate.DetailsUrl = Url.RouteUrl("Page", new { culture, seoName = cate.SeoName }); break; } cate.IsActived = (cate.DetailsUrl == activePath || (cate.Type == MixPageType.Home && activePath == string.Format("/{0}/home", culture))); cate.Childs.ForEach((Action <ViewModels.MixPages.ReadListItemViewModel>)(c => { c.IsActived = ( c.DetailsUrl == activePath); cate.IsActived = cate.IsActived || c.IsActived; })); } return(cates); }
async System.Threading.Tasks.Task <List <Lib.ViewModels.MixPages.ReadListItemViewModel> > GetCategoryAsync(MixEnums.CatePosition position, string seoName) { List <Lib.ViewModels.MixPages.ReadListItemViewModel> result = null; var cacheKey = $"mvc_menus_{position}"; if (MixService.GetConfig <bool>("IsCache")) { result = await MixCacheService.GetAsync <List <Lib.ViewModels.MixPages.ReadListItemViewModel> >(cacheKey); } if (result == null) { var getTopCates = Lib.ViewModels.MixPages.ReadListItemViewModel.Repository.GetModelListBy (c => c.Specificulture == _culture && c.MixPagePosition.Any( p => p.PositionId == (int)position) ); result = getTopCates.Data ?? new List <Lib.ViewModels.MixPages.ReadListItemViewModel>(); foreach (var cate in result) { switch (cate.Type) { case MixPageType.Blank: foreach (var child in cate.Childs) { child.Page.DetailsUrl = GenerateDetailsUrl( new { culture = _culture, seoName = child.Page.SeoName }); } break; case MixPageType.StaticUrl: cate.DetailsUrl = cate.StaticUrl; break; case MixPageType.Home: case MixPageType.ListPost: case MixPageType.Post: case MixPageType.Modules: default: cate.DetailsUrl = GenerateDetailsUrl( new { culture = _culture, seoName = cate.SeoName } ); break; } } } foreach (var cate in result) { cate.IsActived = (cate.SeoName == seoName || (cate.Type == MixPageType.Home && string.IsNullOrEmpty(seoName))); cate.Childs.ForEach((Action <Lib.ViewModels.MixPagePages.ReadViewModel>)(c => { c.IsActived = ( c.Page.SeoName == seoName); cate.IsActived = cate.IsActived || c.IsActived; })); } return(result); }