Exemple #1
0
        public async Task <IActionResult> Index(string term, int page = 1)
        {
            var model = new ListModel {
                PostListType = PostListType.Blog
            };

            try
            {
                model.Blog = await _blogProvider.GetBlogItem();
            }
            catch
            {
                return(Redirect("~/admin"));
            }

            model.Pager = new Pager(page, model.Blog.ItemsPerPage);

            if (string.IsNullOrEmpty(term))
            {
                if (model.Blog.IncludeFeatured)
                {
                    model.Posts = await _postProvider.GetList(model.Pager, 0, "", "FP");
                }
                else
                {
                    model.Posts = await _postProvider.GetList(model.Pager, 0, "", "P");
                }
            }
            else
            {
                model.PostListType     = PostListType.Search;
                model.Blog.Title       = term;
                model.Blog.Description = "";
                model.Posts            = await _postProvider.Search(model.Pager, term, 0, "FP");
            }

            if (model.Pager.ShowOlder)
            {
                model.Pager.LinkToOlder = $"?page={model.Pager.Older}";
            }
            if (model.Pager.ShowNewer)
            {
                model.Pager.LinkToNewer = $"?page={model.Pager.Newer}";
            }

            if (!string.IsNullOrEmpty(term))
            {
                string viewPath = $"~/Views/Themes/{model.Blog.Theme}/Search.cshtml";
                if (IsViewExists(viewPath))
                {
                    return(View(viewPath, model));
                }
            }

            return(View($"~/Views/Themes/{model.Blog.Theme}/Index.cshtml", model));
        }
        public async Task <IActionResult> Error()
        {
            try
            {
                PostModel model = new PostModel();
                model.Blog = await _blogProvider.GetBlogItem();

                string viewPath = $"~/Views/Themes/{model.Blog.Theme}/404.cshtml";
                if (IsViewExists(viewPath))
                {
                    return(View(viewPath, model));
                }
                return(View($"~/Views/Error.cshtml"));
            }
            catch
            {
                return(View($"~/Views/Error.cshtml"));
            }
        }