Exemple #1
0
        public PagedResponses <PostDto> Execute(PostSearch search)
        {
            var query = _context.Posts.AsQueryable();

            if (search.Name != null)
            {
                var keyword = search.Name.ToLower();
                query = query.Where(x => x.Name.ToLower().Contains(keyword));
            }
            var skipCount = search.PerPage * (search.Page - 1);

            var response = new PagedResponses <PostDto>
            {
                CurrentPage  = search.Page,
                ItemsPerPage = search.PerPage,
                TotalCount   = query.Count(),
                data         = query.Include(p => p.user).Include(p => p.pictures).Include(p => p.Category).Take(search.PerPage).Skip(skipCount).Select(p => new PostDto
                {
                    Name         = p.Name,
                    Description  = p.Description,
                    CategoryName = p.Category.CategoryName,
                    PostId       = p.Id,
                    UserId       = p.user.Id,
                    pictures     = p.pictures.Select(x => new PictureDto
                    {
                        Name = x.Name,
                        Id   = x.Id
                    }).ToList()
                }).ToList()
            };

            return(response);
        }
Exemple #2
0
        public PagedResponses <UserDto> Execute(UserSearch request)
        {
            var query      = Context.Users.AsQueryable();
            var totalCount = query.Count();

            query = query.Include(p => p.UserType).Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage);

            var pagesCount = (int)Math.Ceiling((double)totalCount / request.PerPage);

            var response = new PagedResponses <UserDto>
            {
                CurrentPage = request.PageNumber,
                TotalCount  = totalCount,
                PagesCount  = pagesCount,
                Data        = query.Select(p => new UserDto
                {
                    Id       = p.Id,
                    UserName = p.Username,
                    Email    = p.Email,
                    userType = p.UserType.Type
                })
            };

            return(response);
        }
Exemple #3
0
        public PagedResponses <PostDto> Execute(PostSearch request)
        {
            var query = Context.Posts.AsQueryable();

            if (request.Name != null)
            {
                var name = request.Name.ToLower();
                query = query.Where(p => p.Name.ToLower().Contains(name));
            }
            if (request.CategoryId != null)
            {
                query = query.Where(p => p.CategoryPostId == request.CategoryId);
            }
            var totalCount = query.Count();

            query = query
                    .Include(p => p.CategoryPost).Include(p => p.Pictures).Include(p => p.User)
                    .Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage);

            var pagesCount = (int)Math.Ceiling((double)totalCount / request.PerPage);

            var response = new PagedResponses <PostDto>
            {
                CurrentPage = request.PageNumber,
                TotalCount  = totalCount,
                PagesCount  = pagesCount,
                Data        = query.Select(p => new PostDto
                {
                    Id          = p.Id,
                    Name        = p.Name,
                    PictureDtos = p.Pictures.Select(od => new PictureDto
                    {
                        Id = od.Id,

                        Name = od.Name
                    }).ToList(),
                    Text         = p.Text,
                    CategoryName = p.CategoryPost.NameCat,
                    UserId       = p.User.Username
                }).ToList()
            };

            return(response);

            //return query.Include(p => p.CategoryPost).Select(p => new PostDto
            //{
            //    Id = p.Id,
            //    Name = p.Name,
            //    Pictute = p.Picture,
            //    Text = p.Text,
            //    CategoryName = p.CategoryPost.NameCat
            //});
        }
Exemple #4
0
        public PagedResponses <CategoryPostDto> Execute(CategorySearch request)
        {
            var query      = Context.Posts.AsQueryable();
            var totalCount = query.Count();

            query = query.Skip((request.PageNumber - 1) * request.PerPage).Take(request.PerPage);

            var pagesCount = (int)Math.Ceiling((double)totalCount / request.PerPage);

            var response = new PagedResponses <CategoryPostDto>
            {
                CurrentPage = request.PageNumber,
                TotalCount  = totalCount,
                PagesCount  = pagesCount,
                Data        = query.Select(p => new CategoryPostDto
                {
                    Id   = p.Id,
                    Name = p.Name
                })
            };

            return(response);
        }
        public PagedResponses <CommentDto> Execute(CommentSearch search)
        {
            var query      = _context.Comments.AsQueryable();
            var totalCount = query.Count();

            query = query.Skip((search.PageNumber - 1) * search.PerPage).Take(search.PerPage);

            var pagesCount = (int)Math.Ceiling((double)totalCount / search.PerPage);

            var response = new PagedResponses <CommentDto>
            {
                CurrentPage  = search.PageNumber,
                TotalCount   = totalCount,
                ItemsPerPage = pagesCount,
                data         = query.Select(p => new CommentDto
                {
                    Id      = p.Id,
                    Comment = p.Comment
                })
            };

            return(response);
        }
Exemple #6
0
        public PagedResponses <CategoryDto> Execute(CategorySearch search)
        {
            var query = _context.Categories.AsQueryable();

            if (search.Keyword != null)
            {
                query = query.Where(c => c.CategoryName.ToLower().Contains(search.Keyword.ToLower()));
            }
            var skipCount = search.PerPage * (search.PageNumber - 1);
            var response  = new PagedResponses <CategoryDto>
            {
                CurrentPage  = search.PageNumber,
                ItemsPerPage = search.PerPage,
                TotalCount   = query.Count(),
                data         = query.Select(c => new CategoryDto
                {
                    Id   = c.Id,
                    Name = c.CategoryName
                })
            };

            return(response);
        }