public async Task <IActionResult> GetAll([FromQuery] PageArguments pageArgs, [FromQuery] SortingArguments sortingArgs, [FromQuery] FilterArguments filterArgs) { var languages = await _mediator.Send(new GetLanguagesQuery(pageArgs, sortingArgs, filterArgs)); return(Ok(languages)); }
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)); }
public async Task <PageDataContainer <UserDto> > GetUsers(PageArguments pageArguments, string query) { PageDataContainer <UserDto> pagedUsers = await _userRepository.GetPagedUsers(query, pageArguments); if (pagedUsers.PageData.Count > 0) { return(pagedUsers); } return(null); }
public async Task <ActionResult <CountryModel> > GetCountryByAlphaCode(string code, [FromQuery] PageArguments pageArgs, [FromQuery] SortingArguments sortingArgs) { Expression <Func <Country, bool> > expression = c => c.Alpha2Code == code || c.Alpha3Code == code; var predicates = new List <Expression <Func <Country, bool> > >(); predicates.Add(expression); var country = await _mediator.Send(new GetCountriesWithPredicateQuery(predicates)); return(Ok(country)); }
public async Task <PageDataContainer <BrandDto> > GetAllBrands(BrandFilterArguments filterArguments, PageArguments pageArguments, SortingArguments sortingArguments) { PageDataContainer <BrandDto> pagedBrands = await _brandRepo.GetPagedBrands(filterArguments, sortingArguments, pageArguments); if (pagedBrands.PageData.Count > 0) { return(pagedBrands); } return(null); }
public async Task <PagedResponse <TEntity> > GetAllAsync <TEntity>(PageArguments pageArgs, SortingArguments sortingArgs, List <FilterArguments> filterArgs, LogicalOperator logicalOperator) where TEntity : BaseEntity { try { return(await _ctx.Set <TEntity>().CreatePaginatedResponse(pageArgs, sortingArgs, filterArgs, logicalOperator)); } catch (Exception e) { throw new BadRequestException("Some of the query params are invalid.", e); } }
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); }
public async Task <IActionResult> GetUsers([FromQuery] PageArguments pageArguments, [FromQuery] string filter) { PageDataContainer <UserDto> pagedUserDtos = await _userService.GetUsers(pageArguments, filter); if (pagedUserDtos == null) { return(NoContent()); } PageDataContainer <UserAuditWebModel> pagedUserAuditModels = _mapper.Map <PageDataContainer <UserAuditWebModel> >(pagedUserDtos); return(Ok(pagedUserAuditModels)); }
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)); }
public async Task <IActionResult> Get([FromQuery] BrandFilterArguments filterArgs, [FromQuery] PageArguments pageArgs, [FromQuery] SortingArguments sortingArgs) { PageDataContainer <BrandDto> pagedBrandDtos = await _brandService.GetAllBrands(filterArgs, pageArgs, sortingArgs); if (pagedBrandDtos == null) { return(NoContent()); } PageDataContainer <BrandWebModel> pagedBrandModels = _mapper.Map <PageDataContainer <BrandWebModel> >(pagedBrandDtos); return(Ok(pagedBrandModels)); }
public async Task <ActionResult <IEnumerable <CountryModel> > > GetCountries([FromQuery] PageArguments pageArgs, [FromQuery] SortingArguments sortingArgs, [FromQuery] FilterArguments filterArgs, [FromHeader(Name = ApiConstants.AcceptHeader)] string mediaType) { if (!MediaTypeHeaderValue.TryParse(mediaType, out var parsedMediaType)) { return(BadRequest()); } var pagedCountries = await _mediator.Send(new GetCountriesQuery(pageArgs, sortingArgs, new List <FilterArguments> { filterArgs })); var links = DecorateResponse(pagedCountries.PageData, sortingArgs, filterArgs, Request.Path); return(parsedMediaType.MediaType.Contains(ApiConstants.HateoasKeyword) ? Ok(new { pagedCountries.Items, links }) : Ok(pagedCountries.Items)); }
public async Task <PageDataContainer <TownDto> > GetPagedTows(string filter, PageArguments pageArguments) { var references = new string[0]; var filters = new List <Expression <Func <Town, bool> > >() { town => town.Title == filter }; var orderParams = new List <OrderParams <Town> > { new OrderParams <Town> { OrderBy = (town) => town.Title, Descending = false } }; PageDataContainer <Town> pagedTowns = await GetPagedData(references, filters, orderParams, pageArguments); return(_mapper.Map <PageDataContainer <TownDto> >(pagedTowns)); }
public static async Task <PageDataContainer <T> > GetPageAsync <T>(this IOrderedQueryable <T> queryAbleData, PageArguments pageParams) { int maxPageSize = 50; int TotalEntries = queryAbleData.Count(); int PageSize = pageParams.PageSize; if (PageSize > maxPageSize) { PageSize = maxPageSize; } else if (PageSize <= 0) { PageSize = 10; } int TotalPages = (int)Math.Ceiling((double)TotalEntries / PageSize); int PageNumber = pageParams.PageNumber; if (PageNumber <= 0) { PageNumber = 1; } else if (PageNumber > TotalPages) { PageNumber = TotalPages; } List <T> PageData; if (TotalEntries != 0) { PageData = await GetDataForCurrentPage <T>(queryAbleData, PageNumber, PageSize); } else { PageData = new List <T>(); } return(new PageDataContainer <T>(PageData, PageNumber, PageSize, TotalPages, TotalEntries)); }
public async Task <ActionResult <IEnumerable <CountryModel> > > GetCountriesByAlphaCodes([FromQuery] string codes, [FromQuery] PageArguments pageArgs, [FromQuery] SortingArguments sortingArgs) { var filterArgs = new List <FilterArguments> { new FilterArguments { FilterProperty = nameof(Country.Alpha2Code), FilterValues = codes.Split(';') }, new FilterArguments { FilterProperty = nameof(Country.Alpha3Code), FilterValues = codes.Split(';') } }; var pagedCountries = await _mediator.Send(new GetCountriesQuery(pageArgs, sortingArgs, filterArgs)); return(Ok(pagedCountries.Items)); }
public async Task <ActionResult <IEnumerable <CountryModel> > > GetCountriesByCurrency(string currency, [FromQuery] PageArguments pageArgs, [FromQuery] SortingArguments sortingArgs, [FromHeader(Name = ApiConstants.AcceptHeader)] string mediaType) { var pagedCountries = await _mediator.Send(new GetCountriesQuery(pageArgs, sortingArgs, new List <FilterArguments> { new FilterArguments { FilterProperty = "Currency.Code", FilterValues = new string[] { currency } } })); return(Ok(pagedCountries.Items)); }
public static async Task <PagedResponse <TEntity> > CreatePaginatedResponse <TEntity>(this IQueryable <TEntity> source, PageArguments pageArgs, SortingArguments sortArgs, List <FilterArguments> filterArgs, LogicalOperator logicalOperator) where TEntity : class { source = source.ApplyFilters(filterArgs, logicalOperator); var total = await source.CountAsync(); source = source.ApplyPagination(pageArgs.PageIndex, pageArgs.PageSize); source = source.ApplySort(sortArgs.OrderBy, sortArgs.Direction); var listResult = await source.ToListAsync(); return(new PagedResponse <TEntity> { PageData = new PageData { PageIndex = pageArgs.PageIndex, PageSize = pageArgs.PageSize, TotalItems = total }, Items = listResult }); }
public async Task <PageDataContainer <BrandDto> > GetPagedBrands(BrandFilterArguments filterOptions, SortingArguments sortingArguments, PageArguments pageArguments) { var filters = new List <Expression <Func <Brand, bool> > >() { brand => brand.Title.Contains(filterOptions.Title ?? ""), }; var includes = new string[] { "BrandCategories.Category" }; var orderParameters = new List <OrderParams <Brand> >() { new OrderParams <Brand> { OrderBy = (x) => x.Title, Descending = (sortingArguments.Direction == "desc") } }; IOrderedQueryable <Brand> query = GetAllForPaging(includes, filters, orderParameters); PageDataContainer <Brand> pagedBrands = await query.GetPageAsync(pageArguments); return(_mapper.Map <PageDataContainer <BrandDto> >(pagedBrands)); }
public async Task <PageDataContainer <TownDto> > GetPagedTowns(string filter, PageArguments pageArguments) { filter = filter?.ToLower() ?? string.Empty; PageDataContainer <TownDto> pagedTowns = await _townRepository.GetPagedTows(filter, pageArguments); if (pagedTowns.PageData.Count == 0) { return(null); } return(pagedTowns); }
public async Task <PageDataContainer <T> > GetPagedData(string[] references, List <Expression <Func <T, bool> > > filters, List <OrderParams <T> > orderParams, PageArguments pageArguments) { var query = _context.Set <T>().AsQueryable().AsNoTracking(); query = references.Aggregate(query, (current, includeProperty) => current.Include(includeProperty)); query = filters.Aggregate(query, (current, filterProperty) => current.Where(filterProperty)); var firstOrderParam = orderParams[0]; var orderedQuery = firstOrderParam.Descending ? query.OrderByDescending(firstOrderParam.OrderBy) : query.OrderBy(firstOrderParam.OrderBy); if (orderParams.Count > 1) { orderedQuery = orderParams.Skip(1).Aggregate(orderedQuery, (current, orderParam) => orderParam.Descending ? current.ThenByDescending(orderParam.OrderBy) : current.ThenBy(orderParam.OrderBy)); } return(await orderedQuery.GetPageAsync(pageArguments)); }
public async Task <PageDataContainer <UserDto> > GetPagedUsers(string filter, PageArguments pageArguments) { var filters = new List <Expression <Func <User, bool> > >() { user => user.UserName.Contains(filter ?? ""), user => user.Email.Contains(filter ?? ""), }; var includes = new string[] { $"{nameof(User.UserRoles)}.{nameof(Role)}", $"{nameof(User.Town)}" }; var orderParameters = new List <OrderParams <User> >() { new OrderParams <User> { OrderBy = (x) => x.UserName, Descending = false } }; var pagedUsers = await GetPagedData(includes, filters, orderParameters, pageArguments); return(_mapper.Map <PageDataContainer <UserDto> >(pagedUsers)); }
public GetCountriesQuery(PageArguments pageArgs, SortingArguments sortingArgs, List <FilterArguments> filterArgs) { PageArgs = pageArgs; SortingArgs = sortingArgs; FilterArgs = filterArgs; }