Ejemplo n.º 1
0
        public async Task <PageDataContainer <AnnoucementDto> > GetPagedAnnoucements(AnnoucementFilterArguments filterOptions,
                                                                                     PageArguments paginateParams, SortingArguments orderParams)
        {
            _dataSet = _context.Annoucements;
            IQueryable <Annoucement>        annoucements         = IncludeProperties(_dataSet);
            IQueryable <Annoucement>        filteredAnnoucements = ApplySeachQuery(annoucements, filterOptions);
            IOrderedQueryable <Annoucement> orderedAnnoucements  = OrderAnnoucements(filteredAnnoucements, orderParams);
            var pagedAnnoucements = await orderedAnnoucements.GetPageAsync(paginateParams);

            return(_mapper.Map <PageDataContainer <AnnoucementDto> >(pagedAnnoucements));
        }
Ejemplo n.º 2
0
        public async Task <PageDataContainer <AnnoucementDto> > GetAnnoucements(AnnoucementFilterArguments filterOptions,
                                                                                PageArguments paginateParams, SortingArguments orderParams)
        {
            PageDataContainer <AnnoucementDto> pagedAnnoucements = await _annoucementRepo.GetPagedAnnoucements(filterOptions, paginateParams, orderParams);

            if (pagedAnnoucements.PageData.Count == 0)
            {
                return(null);
            }

            return(pagedAnnoucements);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetAll([FromQuery] AnnoucementFilterArguments filterArgs,
                                                 [FromQuery] PageArguments pageArgs, [FromQuery] SortingArguments sortingArgs)
        {
            PageDataContainer <AnnoucementDto> pagedAnnoucementDtos = await _annoucementService.GetAnnoucements(filterArgs, pageArgs, sortingArgs);

            if (pagedAnnoucementDtos == null)
            {
                return(NoContent());
            }
            PageDataContainer <AnnoucementWebModel> pagedWebAnnoucements = _mapper.Map <PageDataContainer <AnnoucementWebModel> >(pagedAnnoucementDtos);

            return(Ok(pagedWebAnnoucements));
        }
Ejemplo n.º 4
0
        private static IQueryable <Annoucement> ApplySeachQuery(IQueryable <Annoucement> annoucements, AnnoucementFilterArguments searchOptions)
        {
            if (searchOptions.UserId > 0)
            {
                annoucements = annoucements.Where(x => x.UserId == searchOptions.UserId);
            }

            if (!string.IsNullOrWhiteSpace(searchOptions.Category))
            {
                annoucements = annoucements.Where(x => x.BrandCategory.Category.Title.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);
        }