public IActionResult Search([FromForm] PostSearch post)
        {
            var listpost           = _postService.listPost(post.Page, post.Title, post.Address);
            List <PostModel> model = new List <PostModel>();

            listpost.ForEach(p =>
            {
                model.Add(new PostModel()
                {
                    Company_Name    = p.Company_Name,
                    PostID          = p.Post_ID,
                    Title           = p.Title,
                    Address         = p.Address,
                    ExactAddress    = p.ExactAddress,
                    Position        = p.Position,
                    Gender          = p.Gender,
                    Salary          = p.Salary,
                    Amount          = p.Amount,
                    Experience      = p.Experience,
                    Submit_Deadline = p.Submit_Deadline,
                    Reciever        = p.Reciever,
                    Email_Reciever  = p.Email_Reciever,
                    Phone_Reciever  = p.Phone_Reciever,
                    Description     = p.Description,
                    Require         = p.Require,
                    Benefit         = p.Benefit,
                    Skill           = p.Skill
                });
            });
            var tupleModel = new Tuple <List <PostModel>, PostSearch>(model, post);

            return(View(tupleModel));
        }
        public IEnumerable <GetPostDto> Execute(PostSearch request)
        {
            var query = _context.Posts.Where(r => r.IsDeleted == false).AsQueryable();

            if (request.Title != null)
            {
                if (!query.Any(r => r.Title.ToLower().Contains(request.Title.ToLower())))
                {
                    throw new EntityNotFoundException("Post");
                }

                query = query.Where(r => r.Title.ToLower().Contains(request.Title.ToLower()));
            }

            return(query.Select(r => new GetPostDto
            {
                Description = r.Description,
                Id = r.Id,
                ImageName = r.PostImage.ImageName,
                PostImageId = r.PostImageId,
                Rating = r.Rating,
                Title = r.Title,
                UserId = r.UserId
            }));
        }
Example #3
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);
        }
Example #4
0
        public IEnumerable <PostDto> Execute(PostSearch request)
        {
            var query = Context.Posts.AsQueryable();

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

            if (request.searchString != null)
            {
                var search = request.searchString.ToLower();
                query = query.Where(p => p.Name.ToLower().Contains(search));
            }
            return(query.Include(p => p.CategoryPost).Include(p => p.Pictures).Include(p => p.User).Select(p => new PostDto {
                Id = p.Id,
                Name = p.Name,
                Text = p.Text,
                PictureDtos = p.Pictures.Select(od => new PictureDto {
                    Id = od.Id,
                    Name = od.Name
                }).ToList(),
                CategoryName = p.CategoryPost.NameCat,
                UserId = p.User.Username
            }


                                                                                                           ).ToList());
        }
        public IActionResult Index(
            int?page, string searchString, int?postCategoryId, string postTag, PostSortFilterType postSortFilterType = PostSortFilterType.SortByDateDesc)
        {
            var postSearch = new PostSearch()
            {
                SearchString       = searchString,
                PostCategoryId     = postCategoryId,
                PostTag            = postTag,
                PostSortFilterType = postSortFilterType,
            };

            int pageSize = 6;

            var posts = GetPosts(postSearch, pageIndex: page - 1 ?? 0, pageSize: pageSize);

            var blogViewModel = new PostsViewModel()
            {
                PostViewModels     = _mapper.Map <IEnumerable <Post>, IEnumerable <PostViewModel> >(posts),
                Pager              = new Pager(posts.TotalCount, posts.TotalPages, page, pageSize),
                SearchString       = searchString,
                PostCategoryId     = postCategoryId,
                PostTag            = postTag,
                PostSortFilterType = postSortFilterType
            };

            return(View(blogViewModel));
        }
        public PagedResponse <PostDto> Execute(PostSearch search)
        {
            var query = _context.Posts.Include(x => x.Category).Include(x => x.Image).Include(x => x.Comments).AsQueryable();

            if (!string.IsNullOrEmpty(search.Title) && !string.IsNullOrWhiteSpace(search.Title))
            {
                query = query.Where(x => x.Title.ToLower().Contains(search.Title.ToLower()));
            }

            if (!string.IsNullOrEmpty(search.Description) && !string.IsNullOrWhiteSpace(search.Description))
            {
                query = query.Where(x => x.Description.ToLower().Contains(search.Description.ToLower()));
            }

            var skipCount = search.PerPage * (search.Page - 1);

            var response = new PagedResponse <PostDto>
            {
                CurrentPage  = search.Page,
                ItemsPerPage = search.PerPage,
                TotalCount   = query.Count(),
                //Items = query.Skip(skipCount).Take(search.PerPage).Select(x => _mapper.Map<PostDto>(x)).ToList()
                Items = query.Skip(skipCount).Take(search.PerPage).Select(x => new PostDto
                {
                    Id          = x.Id,
                    Title       = x.Title,
                    Description = x.Description,
                    ImageId     = x.ImageId,
                    CategoryId  = x.CategoryId,
                    Comments    = x.Comments
                }).ToList() // KAKO SE MAPIRA SA KOLEKCIJAMA???
            };

            return(response);
        }
Example #7
0
 public ActionResult <IEnumerable <PostDto> > Get([FromQuery] PostSearch ps)
 {
     try
     {
         var posts = _getPosts.Execute(ps);
         return(Ok(posts));
     }
     catch (EntityNotFoundException e) { return(NotFound(e.Message)); }
     catch (Exception e) { return(StatusCode(500, e.Message)); }
 }
Example #8
0
        public PagedResponse <PostDto> Execute(PostSearch search)
        {
            var query = context.Posts.Include(c => c.User).Include(u => u.Picture).Include(u => u.Category).AsQueryable();

            if (!string.IsNullOrEmpty(search.Name) || !string.IsNullOrWhiteSpace(search.Name))
            {
                query = query.Where(x => x.Name.ToLower().Contains(search.Name.ToLower()));
            }
            return(query.Paged <PostDto, Domain.Entities.Post>(search, mapper));
        }
Example #9
0
        public PagedResponse <PostDto> Execute(PostSearch search)
        {
            var query = context.Posts.AsQueryable();

            if (!string.IsNullOrEmpty(search.Name) || !string.IsNullOrWhiteSpace(search.Name))
            {
                query = query.Where(x => x.Name.ToLower().Contains(search.Name.ToLower()));
            }

            return(query.Paged <PostDto, Post>(search, _mapper));
        }
Example #10
0
        // GET: Post
        public IActionResult Index([FromQuery] PostSearch search)
        {
            var vm = new PostIndexViewModel();

            vm.Posts         = _getPost.Execute(search);
            vm.CategoryPosts = _getCategory.Execute(new Aplication.Search.CategorySearch
            {
                OnlyActive = true
            });
            return(View(vm));
        }
        // GET: Posts
        public ActionResult Index([FromQuery] PostSearch ps)
        {
            try
            {
                var posts = _getPosts.Execute(ps);
                return(View(posts));
            }

            catch (EntityNotFoundException e) { TempData["Error"] = e.Message; }
            catch (Exception e) { TempData["Error"] = "Server error " + e.Message; }
            return(View());
        }
Example #12
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
            //});
        }
Example #13
0
 public IActionResult Get(
     [FromQuery] PostSearch search,
     [FromServices] IGetPostsQuery query)
 {
     try
     {
         return(Ok(_executor.ExecuteQuery(query, search)));
     }
     catch (Exception)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError));
     }
 }
Example #14
0
        public PagedResponse <ReadPostDto> Execute(PostSearch search)
        {
            var query = _context.Posts
                        .Include(x => x.Topic)
                        .Include(x => x.User).AsQueryable();

            if (!string.IsNullOrEmpty(search.Title) || !string.IsNullOrWhiteSpace(search.Title))
            {
                query = query.Where(x => x.Title.ToLower().Contains(search.Title.ToLower()));
            }

            if (!string.IsNullOrEmpty(search.Topic) || !string.IsNullOrWhiteSpace(search.Topic))
            {
                query = query.Where(x => x.Topic.Name.ToLower().Contains(search.Topic));
            }

            if (!string.IsNullOrEmpty(search.Content) || !string.IsNullOrWhiteSpace(search.Content))
            {
                query = query.Where(x => x.Content.ToLower().Contains(search.Content.ToLower()));
            }

            if (!string.IsNullOrEmpty(search.UserEmail) || !string.IsNullOrWhiteSpace(search.UserEmail))
            {
                query = query.Where(x => x.User.Email.ToLower().Contains(search.UserEmail.ToLower()));
            }

            var skipCount = search.PerPage * (search.Page - 1);

            var response = new PagedResponse <ReadPostDto>
            {
                CurrentPage  = search.Page,
                ItemsPerPage = search.PerPage,
                TotalCount   = query.Count(),
                Items        = query.Skip(skipCount).Take(search.PerPage).Select(x => new ReadPostDto
                {
                    Id            = x.Id,
                    Title         = x.Title,
                    Content       = x.Content,
                    UserId        = x.User.Id,
                    UserEmail     = x.User.Email,
                    Topic         = x.Topic.Name,
                    PhotoPath     = x.PhotoPath,
                    TotalComments = x.Comments.Count(),
                    TotalRatings  = x.Ratings.Count(),
                    AverageRating = x.Ratings.Count() > 0 ? Decimal.Round((decimal)x.Ratings.Sum(y => y.Value) / x.Ratings.Count(), 1) : 0
                }).ToList()
            };

            return(response);
        }
        public PagedList <Post> GetPosts(PostSearch postSearchDto = null, int pageIndex = 0, int pageSize = int.MaxValue)
        {
            var query = _unitOfWork.PostRepository.GetAll();

            if (postSearchDto != null)
            {
                if (postSearchDto.PostCategoryId != null)
                {
                    query = query.Where(x => x.PostCategoryId == postSearchDto.PostCategoryId);
                }

                if (!string.IsNullOrWhiteSpace(postSearchDto.PostTag))
                {
                    query = query.Where(x => x.Tags.Contains(postSearchDto.PostTag));
                }

                if (!string.IsNullOrWhiteSpace(postSearchDto.SearchString))
                {
                    string searchString = postSearchDto.SearchString?.ToLower();
                    query = query.Where(
                        x => (x.Title.Contains(searchString) ||
                              x.Tags.Contains(searchString) ||
                              x.PostCategory.Title.Contains(searchString) ||
                              x.Body.Contains(searchString))
                        );
                }

                switch (postSearchDto.PostSortFilterType)
                {
                case PostSortFilterType.SortByDateAsc:
                    query = query.OrderBy(x => x.CreateDate);
                    break;

                case PostSortFilterType.SortByDateDesc:
                    query = query.OrderByDescending(x => x.CreateDate);
                    break;

                default:
                    query = query.OrderByDescending(x => x.CreateDate);
                    break;
                }
            }
            else
            {
                query = query.OrderByDescending(x => x.CreateDate);
            }

            return(new PagedList <Post>(query, pageIndex, pageSize));
        }
Example #16
0
 public ActionResult <IEnumerable <GetPostDto> > Get([FromQuery] PostSearch search)
 {
     try
     {
         var posts = _getCommand.Execute(search);
         return(Ok(posts));
     }
     catch (EntityNotFoundException e)
     {
         return(NotFound(e.Message));
     }
     catch (Exception)
     {
         return(StatusCode(500, "Server error has occurred."));
     }
 }
Example #17
0
        public IEnumerable <PostDTO> Execute(PostSearch request)
        {
            var query = Context.Posts.Where(p => p.IsDeleted == false).AsQueryable();

            if (request.Title != null)
            {
                query = query.Where(p => p.Title.ToLower().Contains(request.Title.ToLower()));
            }

            return(query.Select(p => new PostDTO
            {
                Id = p.Id,
                Title = p.Title,
                Description = p.Description
            }));
        }
Example #18
0
 // GET: Posts
 public ActionResult Index([FromQuery] PostSearch search)
 {
     try
     {
         var posts = _getCommand.Execute(search);
         return(View(posts.Data));
     }
     catch (EntityNotFoundException)
     {
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception)
     {
         TempData["error"] = "Server error has occurred.";
         return(RedirectToAction(nameof(Index)));
     }
 }
Example #19
0
        public Pagination <PostDto> Execute(PostSearch request)
        {
            var query = Context.Posts.AsQueryable();

            if (request.Keyword != null)
            {
                query = query.Where(p => p.Name
                                    .ToLower()
                                    .Contains(request.Keyword.ToLower()));
            }

            if (request.IsDeleted.HasValue)
            {
                query = query.Where(p => p.IsDeleted != request.IsDeleted);
            }

            var totalCount = query.Count();

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

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

            return(new Pagination <PostDto>
            {
                CurrentPage = request.PageNumber,
                Pages = pagesCount,
                Total = totalCount,
                Data = query.Include(p => p.PostTags)
                       .ThenInclude(pt => pt.Tag)
                       .Select(p => new PostDto
                {
                    id = p.Id,
                    Name = p.Name,
                    Description = p.Description,
                    TagsName = p.PostTags.Select(pt => new TagDto {
                        Content = pt.Tag.Content,
                        id = pt.Tag.Id
                    })
                })
            });
        }
Example #20
0
        public PagedResponse <GetPostDto> Execute(PostSearch request)
        {
            var query = _context.Posts.Where(r => r.IsDeleted == false).AsQueryable();

            if (request.Title != null)
            {
                if (!query.Any(r => r.Title.ToLower().Contains(request.Title.ToLower())))
                {
                    throw new EntityNotFoundException("Post");
                }

                query = query.Where(r => r.Title.ToLower().Contains(request.Title.ToLower()));
            }

            var totalCount = query.Count();

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

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

            var response = new PagedResponse <GetPostDto>
            {
                PagesCount  = pagesCount,
                CurrentPage = request.PageNumber,
                TotalCount  = totalCount,
                Data        = query.Select(r => new GetPostDto
                {
                    Id          = r.Id,
                    Title       = r.Title,
                    Description = r.Description,
                    ImageName   = r.PostImage.ImageName,
                    PostImageId = r.PostImageId,
                    Rating      = r.Rating,
                    UserId      = r.UserId
                })
            };

            return(response);
        }
        public PagedResponse <PostDto, Post> Execute(PostSearch search)
        {
            var query = _context.Posts.Include(p => p.Photo).AsQueryable();

            if (!string.IsNullOrEmpty(search.Title) && !string.IsNullOrWhiteSpace(search.Title))
            {
                query = query.Where(g => g.Title.ToLower().Contains(search.Text.ToLower()));
            }

            if (!string.IsNullOrEmpty(search.Text) && !string.IsNullOrWhiteSpace(search.Text))
            {
                query = query.Where(g => g.Text.ToLower().Contains(search.Text.ToLower()));
            }

            if (!string.IsNullOrEmpty(search.PhotoCaption) && !string.IsNullOrWhiteSpace(search.PhotoCaption))
            {
                query = query.Where(g => g.Photo.Caption.ToLower().Contains(search.PhotoCaption.ToLower()));
            }

            query = query;

            return(new PagedResponse <PostDto, Post>(query, search, _mapper));
        }
        public IActionResult Index(int?page, int?postCategoryId, PostSortFilterType postSortFilterType = PostSortFilterType.SortByDateDesc)
        {
            var postSearch = new PostSearch()
            {
                PostCategoryId     = postCategoryId,
                PostTag            = null,
                PostSortFilterType = postSortFilterType
            };

            int pageSize = 12;

            var posts = GetPosts(PostCategoryType.Portfolio, postSearch, pageIndex: page - 1 ?? 0, pageSize: pageSize);

            var postsViewModel = new PostsViewModel()
            {
                PostViewModels     = _mapper.Map <IEnumerable <Post>, IEnumerable <PostViewModel> >(posts),
                Pager              = new Pager(posts.TotalCount, posts.TotalPages, page, pageSize),
                PostCategoryId     = postCategoryId,
                PostTag            = null,
                PostSortFilterType = postSortFilterType
            };

            return(View(postsViewModel));
        }
Example #23
0
        public PagedResponse <PostDto> Execute(PostSearch search)
        {
            var query = _context.Posts.AsQueryable();

            if (!string.IsNullOrEmpty(search.Title) || !string.IsNullOrWhiteSpace(search.Title))
            {
                query = query.Where(x => x.Title.ToLower().Contains(search.Title.ToLower()));
            }
            var skipCount = search.PerPage * (search.Page - 1);

            var response = new PagedResponse <PostDto>
            {
                CurrentPage  = search.Page,
                ItemsPerPage = search.PerPage,
                TotalCount   = query.Count(),
                Items        = query.Skip(skipCount).Take(search.PerPage).Select(x => new PostDto
                {
                    Title = x.Title,
                    Text  = x.Text,
                }).ToList()
            };

            return(response);
        }
        public PagedResponse <GetPostDto> Execute(PostSearch request)
        {
            var query = Context.Posts.AsQueryable();

            if (request.Title != null)
            {
                query = query.Where(r => r.Title.ToLower().Contains(request.Title.ToLower()));
            }

            if (request.Active.HasValue)
            {
                query = query.Where(c => c.IsDeleted != request.Active);
            }
            else
            {
                query = query.Where(c => c.IsDeleted == false);
            }


            if (request.UserId.HasValue)
            {
                if (!Context.Users.Any(u => u.Id == request.UserId))
                {
                    throw new EntityNotFoundException("User");
                }
                query = query.Where(p => p.UserId == request.UserId);
            }

            if (request.CategoryId.HasValue)
            {
                if (!Context.Categories.Any(c => c.Id == request.CategoryId))
                {
                    throw new EntityNotFoundException("Category");
                }
                query = query.Where(p => p.CategoryId == request.CategoryId);
            }

            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 PagedResponse <GetPostDto>
            {
                CurrentPage = request.PageNumber,
                TotalCount  = totalCount,
                PagesCount  = pagesCount,
                Data        = query.Select(p => new GetPostDto
                {
                    Id        = p.Id,
                    Title     = p.Title,
                    Content   = p.Content,
                    ImagePath = p.ImagePath,
                    User      = p.User.FirstName + " " + p.User.LastName,
                    Category  = p.Category.Name,
                    PostedOn  = p.CreatedAt
                })
            };

            return(response);
        }
 public IActionResult Get([FromQuery] PostSearch search, [FromServices] IGetPostsCommand query) => Ok(executor.ExecuteQuery(query, search));
Example #26
0
 public IActionResult Get(
     [FromQuery] PostSearch search,
     [FromServices] IGetPostsQuery query)
 {
     return(Ok(_executor.ExecuteQuery(query, search)));
 }
Example #27
0
 public ActionResult GetPost([FromQuery] PostSearch search)
 {
     return(Ok(_postsCommand.Execute(search)));
 }
 public ActionResult <IEnumerable <PostDTO> > Get([FromQuery] PostSearch query)
 {
     return(Ok(_getCommand.Execute(query)));
 }
Example #29
0
        // GET: Posts
        public ActionResult Index(PostSearch search)
        {
            var posts = _getPosts.Execute(search);

            return(View(posts));
        }
Example #30
0
 public PagedResponses <PostDto> Execute(PostSearch search)
 {
     throw new NotImplementedException();
 }