コード例 #1
0
        public async Task <IActionResult> GetAll([FromQuery] AnnoucementFilter filterOptions,
                                                 [FromQuery] PaginateParams paginateParams, [FromQuery] OrderParams orderByParams)
        {
            Paged <AnnoucementForViewDto> pagedObject = await _service.GetAnnoucements(filterOptions, paginateParams, orderByParams);

            if (pagedObject != null)
            {
                return(Ok(pagedObject));
            }
            else
            {
                return(NoContent());
            }
        }
コード例 #2
0
        public async Task <IActionResult> Get([FromQuery] AnnoucementFilter filterOptions,
                                              [FromQuery] PaginateParams paginateParams, [FromQuery] OrderParams orderParams)
        {
            var brands = _repo.GetAll().OrderBy(x => x.Title).Include(x => x.BrandCategories).ThenInclude(x => x.Category)
                         .Select(x => new BrandForViewDto
            {
                BrandId    = x.BrandId,
                Title      = x.Title,
                Categories = x.BrandCategories.Select(x => x.Category.Title)
            });
            var filtered      = brands.Where(x => x.Title.Contains(filterOptions.Query ?? ""));
            var paginatedData = await Paged <BrandForViewDto> .Paginate(filtered, paginateParams);

            return(Ok(paginatedData));
        }
コード例 #3
0
        public async Task <Paged <AnnoucementForViewDto> > GetAnnoucements(AnnoucementFilter filterOptions,
                                                                           PaginateParams paginateParams, OrderParams orderParams)
        {
            var annoucements = _repo.GetAll();
            IQueryable <AnnoucementForViewDto> annoucementsDto = annoucements.ProjectTo <AnnoucementForViewDto>(_mapper.ConfigurationProvider);
            var filteredAnnoucements = annoucementsDto.ApplySeachQuery(filterOptions);

            if (filteredAnnoucements.Count() > 0)
            {
                var orderedAnnoucements = filteredAnnoucements.OrderAnnoucements(orderParams);
                var pageData            = await Paged <AnnoucementForViewDto> .Paginate(orderedAnnoucements, paginateParams);

                return(pageData);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        public static IQueryable <AnnoucementForViewDto> ApplySeachQuery(this IQueryable <AnnoucementForViewDto> annoucements, AnnoucementFilter searchOptions)
        {
            if (searchOptions.UserId > 0)
            {
                annoucements = annoucements.Where(x => x.UserId == searchOptions.UserId);
            }

            if (!string.IsNullOrWhiteSpace(searchOptions.Category))
            {
                annoucements = annoucements.Where(x => x.Category.ToLower().Contains(searchOptions.Category.ToLower()));
            }

            if (!string.IsNullOrWhiteSpace(searchOptions.Query))
            {
                annoucements = annoucements.Where(x => x.Title.ToLower().Contains(searchOptions.Query.ToLower()) || x.Description.ToLower().Contains(searchOptions.Query.ToLower()));
            }

            return(annoucements);
        }