Ejemplo n.º 1
0
        public IActionResult GetUserCollections([FromQuery] UserNameParameters model)
        {
            Claim idClaim = User.FindFirst("sub");
            UserPostCollectionsReturn ret = _userInfoDataService.GetUserPostCollections(model.Username, model.PageIndex, model.PageSize, model.Order);

            return(Ok(ret));
        }
Ejemplo n.º 2
0
        public UserPostCollectionsReturn GetUserPostCollections(string userName, int pageIndex, int pageSize, string order = "dateUtcModified")
        {
            UserPostCollectionsReturn ret = new UserPostCollectionsReturn();

            if (string.IsNullOrWhiteSpace(userName))
            {
                return(ret);
            }

            var author          = GetUserCardInfo(userName);
            var collectionCount = _context.Set <PostCollection>().Count(p => p.UserInfoId == author.AppUserId);
            var collections     = _context.Set <PostCollection>().AsNoTracking()
                                  .Select(f => new CollectionCard()
            {
                Id              = f.Id,
                Name            = f.Name,
                PostsCount      = f.Posts.Count(),
                DateUtcModified = f.DateUtcModified,
                ThumbImageUrl   = f.ThumbFile.ThumbPath,
                UserInfo        = author,
                UserInfoId      = f.UserInfoId
            })
                                  .Where(p => p.UserInfoId == author.AppUserId)
                                  .OrderByDescending(p => p.DateUtcModified)
                                  .Skip((pageIndex - 1) * pageSize)
                                  .Take(pageSize);

            ret.Entities = collections.ToPaginatedList(pageIndex, pageSize, collectionCount);
            return(ret);
        }