Ejemplo n.º 1
0
        List <Lib.ViewModels.SioPages.ReadListItemViewModel> GetCategory(SioEnums.CatePosition position, string seoName)
        {
            var result   = new List <Lib.ViewModels.SioPages.ReadListItemViewModel>();
            var cacheKey = $"page_position_{position}";

            var data = _memoryCache.Get <List <Lib.ViewModels.SioPages.ReadListItemViewModel> >(cacheKey);

            if (data != null && SioService.GetConfig <bool>("IsCache"))
            {
                result = data;
            }
            else
            {
                var getTopCates = Lib.ViewModels.SioPages.ReadListItemViewModel.Repository.GetModelListBy
                                      (c => c.Specificulture == _culture && c.SioPagePosition.Any(
                                          p => p.PositionId == (int)position)
                                      );

                result = getTopCates.Data ?? new List <Lib.ViewModels.SioPages.ReadListItemViewModel>();
                foreach (var cate in result)
                {
                    switch (cate.Type)
                    {
                    case SioPageType.Blank:
                        foreach (var child in cate.Childs)
                        {
                            child.Page.DetailsUrl = GenerateDetailsUrl("Page", new { seoName = child.Page.SeoName });
                        }
                        break;

                    case SioPageType.StaticUrl:
                        cate.DetailsUrl = cate.StaticUrl;
                        break;

                    case SioPageType.Home:
                    case SioPageType.ListArticle:
                    case SioPageType.Article:
                    case SioPageType.Modules:
                    default:
                        cate.DetailsUrl = GenerateDetailsUrl("Page", new { seoName = cate.SeoName });
                        break;
                    }
                }
            }

            foreach (var cate in result)
            {
                cate.IsActived = (cate.SeoName == seoName ||
                                  (cate.Type == SioPageType.Home && string.IsNullOrEmpty(seoName)));
                cate.Childs.ForEach((Action <Lib.ViewModels.SioPagePages.ReadViewModel>)(c =>
                {
                    c.IsActived = (
                        c.Page.SeoName == seoName);
                    cate.IsActived = cate.IsActived || c.IsActived;
                }));
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static List <ViewModels.SioPages.ReadListItemViewModel> GetCategory(IUrlHelper Url, string culture, SioEnums.CatePosition position, string activePath = "")
        {
            var getTopCates = ViewModels.SioPages.ReadListItemViewModel.Repository.GetModelListBy
                                  (c => c.Specificulture == culture && c.SioPagePosition.Any(
                                      p => p.PositionId == (int)position)
                                  );
            var cates = getTopCates.Data ?? new List <ViewModels.SioPages.ReadListItemViewModel>();

            activePath = activePath.ToLower();
            foreach (var cate in cates)
            {
                switch (cate.Type)
                {
                case SioPageType.Blank:
                    foreach (var child in cate.Childs)
                    {
                        child.Page.DetailsUrl = Url.RouteUrl("Page", new { culture, seoName = child.Page.SeoName });
                    }
                    break;

                case SioPageType.StaticUrl:
                    cate.DetailsUrl = cate.StaticUrl;
                    break;

                case SioPageType.Home:
                case SioPageType.ListArticle:
                case SioPageType.Article:
                case SioPageType.Modules:
                default:
                    cate.DetailsUrl = Url.RouteUrl("Page", new { culture, seoName = cate.SeoName });
                    break;
                }
                cate.IsActived = (cate.DetailsUrl == activePath ||
                                  (cate.Type == SioPageType.Home && activePath == string.Format("/{0}/home", culture)));
                cate.Childs.ForEach((Action <ViewModels.SioPagePages.ReadViewModel>)(c =>
                {
                    c.IsActived = (
                        c.Page.DetailsUrl == activePath);
                    cate.IsActived = cate.IsActived || c.IsActived;
                }));
            }
            return(cates);
        }