Пример #1
0
        public async Task <IndexViewModel> GetAdminDashBoard(ClaimsPrincipal claimsPrincipal)
        {
            var applicationUser = await userManager.GetUserAsync(claimsPrincipal);

            return(new IndexViewModel {
                Blogs = blogServices.GetBlogs(applicationUser)
            });
        }
Пример #2
0
        public async Task <IActionResult> GetBlogs(int blogCategoryId, [FromQuery] FopQuery request)
        {
            try
            {
                var fopRequest = FopExpressionBuilder <BlogForList> .Build(request.Filter, request.Order, request.PageNumber, request.PageSize);

                var(blogsByCateId, totalCount) = await _blogServices.GetBlogs(blogCategoryId, fopRequest);

                if (blogsByCateId == null)
                {
                    return(new BadRequestObjectResult(new { Message = "Không tìm tháy tin tức nào!" }));
                }
                var response = new PagedResult <IEnumerable <BlogForList> >((blogsByCateId), totalCount, request.PageNumber, request.PageSize);;
                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(new { Message = ex.Message.ToString() }));
            }
        }
Пример #3
0
        public ActionResult <AuthorViewModel> GetAuthorViewModel(string authorId, string searchString, int?page)
        {
            if (authorId is null)
            {
                return(new BadRequestResult());
            }
            var applicationUser = userService.Get(authorId);

            if (applicationUser is null)
            {
                return(new NotFoundResult());
            }
            int pageSize   = 20;
            int pageNumber = page ?? 1;
            var blogs      = blogServices.GetBlogs(searchString ?? string.Empty).Where(x => x.Published && x.Creator == applicationUser);

            return(new AuthorViewModel
            {
                Author = applicationUser,
                Blogs = new StaticPagedList <Blog>(blogs.Skip((pageNumber - 1) * pageSize).Take(pageSize), pageNumber, pageSize, blogs.Count()),
                SearchString = searchString,
                PageNumber = pageNumber
            });
        }
Пример #4
0
        public IndexViewModel GetIndexViewModel(string searchString, int?page)
        {
            int pageSize   = 20;
            int pageNumber = page ?? 1;
            var blogs      = blogServices.GetBlogs(searchString ?? string.Empty).Where(x => x.Published);

            //https://github.com/esty-c/AspNetCore.SEOHelper/tree/e66b8f24b02e53019bf895871aad5d429d35d316
            //var obj = new SitemapDocument();
            //List<SitemapNode> list = new List<SitemapNode>();
            //foreach (var blog in blogs)
            //{
            //    list.Add(new SitemapNode { LastModified = blog.UpdatedOn, Priority = 0.8, Url = $@"http://garibbro.com/Post/{blog.Id}", Frequency = SitemapFrequency.Yearly });
            //}
            //var baseDirectroy = AppContext.BaseDirectory.Substring(0, AppContext.BaseDirectory.IndexOf("bin"));
            //obj.CreateSitemapXML(list, baseDirectroy);
            //var items = obj.LoadFromFile(baseDirectroy);

            return(new IndexViewModel
            {
                Blogs = new StaticPagedList <Blog>(blogs.Skip((pageNumber - 1) * pageSize).Take(pageSize), pageNumber, pageSize, blogs.Count()),
                SearchString = searchString,
                PageNumber = pageNumber
            });
        }