예제 #1
0
        protected async Task SetPageTitleAndMetadataAsync(GetPostListRequestModel model)
        {
            AppendPageTitle(_basicSettings.Title);

            if (model.Category != null)
            {
                InsertPageTitle(model.Category.Name);
                SetPageDescription($"{model.Category.Description}. {_basicSettings.Description}");
            }
            else if (model.Tags != null)
            {
                InsertPageTitle(model.Tags.Name);
                SetPageDescription($"{_basicSettings.Description}");
            }
            else if (model.Author != null)
            {
                InsertPageTitle(model.Author.DisplayName);

                SetPageDescription($"{model.Author.DisplayName}. {model.Author.Bio}{_basicSettings.Description}");
            }
            else
            {
                AppendPageTitle(_basicSettings.Description);
                SetPageDescription(_basicSettings.Description);
            }

            if (model.Page >= 2)
            {
                InsertPageTitle($"Page {model.Page}");
            }

            var keywords = (string.Join(",", (await _categoryService.GetListAsync()).Select(t => t.Name)));

            SetPageKeywords(keywords);
        }
예제 #2
0
        protected async Task <IActionResult> GetPostsAsync(GetPostListRequestModel model)
        {
            var vm = new PostsViewModel();

            var limit = _basicSettings.PageShowCount;

            if (limit <= 0)
            {
                limit = 1;
            }
            if (limit > 100)
            {
                limit = 100;
            }

            var listInputModel = new PostListInputModel()
            {
                Skip           = 0,
                Limit          = limit,
                IsDraft        = false,
                IncludeOptions = new PostIncludeOptions()
                {
                    IncludeCategory = true,
                    IncludeTags     = true,
                    IncludeUser     = true,
                }
            };

            listInputModel.CategoryId         = model.Category?.Id;
            listInputModel.TagsId             = model.Tags?.Id;
            listInputModel.UserId             = model.Author?.Id;
            listInputModel.PublishedYearMonth = model.PublishYearMonth;

            if (model.Page <= 1)
            {
                model.Page = 1;
            }
            listInputModel.Skip = (model.Page - 1) * listInputModel.Limit;

            if (!string.IsNullOrWhiteSpace(model.Q))
            {
                listInputModel.SearchTerm = model.Q;
            }

            await SetPageTitleAndMetadataAsync(model);

            var list = await _postService.GetPostsPagedListAsync(listInputModel);

            vm.Posts = list.ReplaceTo((item) => _postFactory.ToModel(item, new Models.PostModel()));

            return(View("Posts", vm));
        }