public async Task <IActionResult> Category(string category, [FromQuery] PagingModel paging = null)
        {
            var model = new PEngineGenericListModel <ArticleModel>(_svp, HttpContext, false);

            if (paging != null)
            {
                paging.Count = paging.Count > 0 ? paging.Count : model.Settings.PerPagePostArchived;
                if (string.IsNullOrEmpty(paging.SortField))
                {
                    paging.SortField     = "Name";
                    paging.SortAscending = false;
                }
            }
            var articles = (await _articleService.ListArticles(category, model.State.HasAdmin)).ToList();

            if (!articles.Any())
            {
                return(model.State.HasAdmin ? (IActionResult)this.Redirect(Settings.Current.BasePath) : this.NotFound());
            }
            if (articles.Count > 1 || model.State.HasAdmin)
            {
                model.ListData = PagingUtils.Paginate <ArticleModel>(ref paging, articles);
                model.Paging   = paging;
                return(View("List", model));
            }
            else
            {
                return(Redirect($"{Settings.Current.BasePath}article/view/{articles.First().UniqueName}"));
            }
        }
        public async Task <IActionResult> Index([FromQuery] string query, [FromQuery] PagingModel paging = null)
        {
            var model = new PEngineGenericListModel <PEngineSearchResultModel>(HttpContext, false);

            model.State.CurrentSection = query;

            var results = new List <PEngineSearchResultModel>();

            string[] searchTerms = !string.IsNullOrWhiteSpace(query) ? query.Split(' ') : new string[] {};

            results.AddRange((await _articleService.SearchArticles(searchTerms, model.State.HasAdmin))
                             .Select(a => new PEngineSearchResultModel(a)));

            results.AddRange((await _postService.SearchPosts(searchTerms, model.State.HasAdmin))
                             .Select(p => new PEngineSearchResultModel(p)));

            if (!Settings.Current.DisableForum)
            {
                results.AddRange((await _forumService.SearchForumThreadPosts(searchTerms, model.State.HasForumAdmin))
                                 .Select(ftp => new PEngineSearchResultModel(ftp)));
            }

            if (paging != null)
            {
                paging.Count = paging.Count > 0 ? paging.Count : model.Settings.PerPageSearchResults;
                if (string.IsNullOrEmpty(paging.SortField))
                {
                    paging.SortField     = "CreatedUTC";
                    paging.SortAscending = false;
                }
            }
            model.ListData = PagingUtils.Paginate <PEngineSearchResultModel>(ref paging, results);
            model.Paging   = paging;
            return(View(model));
        }
        public async Task <IActionResult> Index([FromQuery] string query, [FromQuery] PagingModel paging = null)
        {
            var model = new PEngineGenericListModel <PEngineSearchResultModel>(_svp, HttpContext, false);

            if (!Settings.Current.DisableSearch)
            {
                model.State.CurrentSection = query;

                var      results     = new List <PEngineSearchResultModel>();
                string[] searchTerms = !string.IsNullOrWhiteSpace(query) ? query.Split(' ') : new string[] {};

                var articleResults = (await _articleService.SearchArticles(query, searchTerms, model.State.HasAdmin));
                results.AddRange(articleResults.exact.Select(a => new PEngineSearchResultModel(a, true)));
                results.AddRange(articleResults.fuzzy.Select(a => new PEngineSearchResultModel(a, false)));

                var postResults = (await _postService.SearchPosts(query, searchTerms, model.State.HasAdmin));
                results.AddRange(postResults.exact.Select(p => new PEngineSearchResultModel(p, true)));
                results.AddRange(postResults.fuzzy.Select(p => new PEngineSearchResultModel(p, false)));

                if (paging != null)
                {
                    paging.Count = paging.Count > 0 ? paging.Count : model.Settings.PerPageSearchResults;
                    if (string.IsNullOrEmpty(paging.SortField))
                    {
                        paging.SortField     = "ExactMatch DESC, CreatedUTC";
                        paging.SortAscending = false;
                    }
                }
                model.ListData = PagingUtils.Paginate <PEngineSearchResultModel>(ref paging, results);
                model.Paging   = paging;
                return(View(model));
            }
            return(model.State.HasAdmin ? (IActionResult)this.Redirect(Settings.Current.BasePath) : this.NotFound());
        }
Esempio n. 4
0
        public async Task <IActionResult> Index()
        {
            var model = new PEngineGenericListModel <PostModel>(_svp, HttpContext, true);

            model.ListData        = PagingUtils.Paginate(1, model.Settings.PerPagePostFront, "CreatedUTC", false, await _postService.ListPosts(model.State.HasAdmin));
            model.State.QuoteText = (await _quoteService.GetRandom()).Data;
            return(View(model));
        }
        public async Task <IActionResult> List([FromQuery] PagingModel paging = null)
        {
            var model = new PEngineGenericListModel <PostModel>(HttpContext, false);

            if (paging != null)
            {
                paging.Count = paging.Count > 0 ? paging.Count : model.Settings.PerPagePostArchived;
                if (string.IsNullOrEmpty(paging.SortField))
                {
                    paging.SortField     = "CreatedUTC";
                    paging.SortAscending = false;
                }
            }
            model.ListData = PagingUtils.Paginate <PostModel>(ref paging, await _postService.ListPosts(model.State.HasAdmin));
            model.Paging   = paging;
            return(View(model));
        }
Esempio n. 6
0
        public async Task <IEnumerable <PostModel> > Get([FromQuery] PagingModel paging = null)
        {
            var posts = await _postDal.ListPosts();

            return(PagingUtils.Paginate(ref paging, posts));
        }
        public async Task <IEnumerable <ArticleModel> > Get(string category, [FromQuery] PagingModel paging = null)
        {
            var articles = await _articleDal.ListArticles(category);

            return(PagingUtils.Paginate(ref paging, articles));
        }
        public async Task <IEnumerable <ForumThreadModel> > GetForumThreads(Guid forumGuid, [FromQuery] PagingModel paging = null)
        {
            var forumThreads = await _forumService.ListForumThreads(forumGuid, null, HttpContext.User.IsInRole("ForumAdmin"));

            return(PagingUtils.Paginate(ref paging, forumThreads));
        }
        public async Task <IEnumerable <ForumUserModel> > GetForumUsers([FromQuery] PagingModel paging = null)
        {
            var forumUsers = await _forumDal.ListForumUsers();

            return(PagingUtils.Paginate(ref paging, forumUsers));
        }
Esempio n. 10
0
        public async Task <IEnumerable <QuoteModel> > Get([FromQuery] PagingModel paging = null)
        {
            var quotes = await _quoteService.Get();

            return(PagingUtils.Paginate(ref paging, quotes));
        }