public virtual Task <PagedData <TResponse> > FindLatestAsync <TResponse>(SieveModel sieveModel, CancellationToken cancellationToken = default) where TResponse : class { var query = DbSet .EnsureType <TResponse>(Mapper) .AsNoTracking(); return(SieveProcessor.Apply(sieveModel, query, applyPagination: false) .PaginateAsync(sieveModel.Page ?? 1, sieveModel.PageSize ?? 10, cancellationToken)); }
public async static Task <PaginatedList <T> > Paginate <T>(this IQueryable <T> query, SieveProcessor processor, SieveModel model) { long totalRecords; var q = processor.Apply(model, query, applyPagination: false); totalRecords = await q.LongCountAsync(); q = processor.Apply(model, q, applyFiltering: false, applySorting: false); return(new PaginatedList <T>(await q.ToListAsync(), totalRecords, model.Page ?? 0, model.PageSize ?? 10)); }
public async Task <Tuple <IEnumerable <User>, long> > GetUsers(SieveModel model, CancellationToken token) { var entities = userRepository.Users.AsQueryable(); entities = sieveProcessor.Apply(model, entities, applyPagination: false); var total = entities.Count(); entities = sieveProcessor.Apply(model, entities, applyFiltering: false, applySorting: false); return(new Tuple <IEnumerable <User>, long>(await entities.ToAsyncEnumerable().ToList(), total)); }
public void CanFilterNullableInts() { var model = new SieveModel { Filters = "CategoryId==1" }; var result = _processor.Apply(model, _posts); var nullableResult = _nullableProcessor.Apply(model, _posts); Assert.True(result.Count() == 2); Assert.True(nullableResult.Count() == 2); }
public void ContainsCanBeCaseInsensitive() { var model = new SieveModel() { Filters = "Title@=*a" }; var result = _processor.Apply(model, _posts); Assert.AreEqual(result.First().Id, 0); Assert.IsTrue(result.Count() == 1); }
public IEnumerable <CountryCoronaInfo> GetSorted([FromQuery] SieveModel sieveModel, bool filter = false) { var data = DataHelper.GetCountryInfoQueryableAsync(); var result = _sieveProcessor.Apply(sieveModel, data); return(DataHelper.GetRanked(result.ToList())); }
public PagedList <CompanyOrder> GetCompanyOrders(CompanyOrderParametersDto companyOrderParameters) { if (companyOrderParameters == null) { throw new ArgumentNullException(nameof(companyOrderParameters)); } var collection = _context.CompanyOrders .Include(co => co.Vendor) as IQueryable <CompanyOrder>; if (!string.IsNullOrWhiteSpace(companyOrderParameters.ExternalOrderNo)) { var externalOrderNo = companyOrderParameters.ExternalOrderNo.Trim(); collection = collection.Where(a => a.ExternalOrderNo == externalOrderNo); } if (!string.IsNullOrWhiteSpace(companyOrderParameters.QueryString)) { var QueryString = companyOrderParameters.QueryString.Trim(); collection = collection.Where(co => co.ExternalOrderNo.Contains(QueryString) || co.InternalOrderNo.Contains(QueryString) || co.Comments.Contains(QueryString)); } var sieveModel = new SieveModel { Sorts = companyOrderParameters.SortOrder }; collection = _sieveProcessor.Apply(sieveModel, collection); return(PagedList <CompanyOrder> .Create(collection, companyOrderParameters.PageNumber, companyOrderParameters.PageSize)); }
public async Task <IEnumerable <Basket> > ListAsync(SieveModel query) { var items = _context.Baskets.Where(x => x.Status == BasketStatus.ACTIVE).Include(x => x.ProductPropertyId).AsNoTracking(); var result = _sieveProcessor.Apply(query, items); return(await result.ToListAsync()); }
public PagedList <ValueToReplace> GetValueToReplaces(ValueToReplaceParametersDto valueToReplaceParameters) { if (valueToReplaceParameters == null) { throw new ArgumentNullException(nameof(valueToReplaceParameters)); } var collection = _context.ValueToReplaces as IQueryable <ValueToReplace>; // TODO: AsNoTracking() should increase performance, but will break the sort tests. need to investigate if (!string.IsNullOrWhiteSpace(valueToReplaceParameters.QueryString)) { var QueryString = valueToReplaceParameters.QueryString.Trim(); collection = collection.Where(lambdaInitialsToReplace => lambdaInitialsToReplace.ValueToReplaceTextField1.Contains(QueryString) || lambdaInitialsToReplace.ValueToReplaceTextField2.Contains(QueryString)); } var sieveModel = new SieveModel { Sorts = valueToReplaceParameters.SortOrder, Filters = valueToReplaceParameters.Filters }; collection = _sieveProcessor.Apply(sieveModel, collection); return(PagedList <ValueToReplace> .Create(collection, valueToReplaceParameters.PageNumber, valueToReplaceParameters.PageSize)); }
public async Task <IEnumerable <District> > ListAsync(SieveModel query) { var items = _context.Districts.Include(x => x.ProvinceId).AsNoTracking(); var result = _sieveProcessor.Apply(query, items); return(await result.ToListAsync()); }
public PagedList <Vendor> GetVendors(VendorParametersDto vendorParameters) { if (vendorParameters == null) { throw new ArgumentNullException(nameof(vendorParameters)); } var collection = _context.Vendors as IQueryable <Vendor>; if (!string.IsNullOrWhiteSpace(vendorParameters.VendorName)) { var vendorName = vendorParameters.VendorName.Trim(); collection = collection.Where(v => v.VendorName == vendorName); } var sieveModel = new SieveModel { Sorts = vendorParameters.SortOrder }; collection = _sieveProcessor.Apply(sieveModel, collection); return(PagedList <Vendor> .Create(collection, vendorParameters.PageNumber, vendorParameters.PageSize)); }
public PagedList <Category> GetCategories(CategoryParametersDto categoryParameters) { if (categoryParameters == null) { throw new ArgumentNullException(nameof(categoryParameters)); } var collection = _context.Categories as IQueryable <Category>; if (!string.IsNullOrWhiteSpace(categoryParameters.CategoryName)) { var categoryName = categoryParameters.CategoryName.Trim(); collection = collection.Where(c => c.CategoryName == categoryName); } var sieveModel = new SieveModel { Sorts = categoryParameters.SortOrder }; collection = _sieveProcessor.Apply(sieveModel, collection); return(PagedList <Category> .Create(collection, categoryParameters.PageNumber, categoryParameters.PageSize)); }
public ActionResult GetAll([FromQuery] SieveModel sieveModel) { var cateringsQuery = cateringService.GetCateringsQuery(); var caterings = sieveProcessor.Apply(sieveModel, cateringsQuery).ToList(); List <CateringResponse> cateringDtos = new List <CateringResponse>(); foreach (Catering catering in caterings) { cateringDtos.Add(new CateringResponse { Id = catering.Id, Categories = catering.CateringCategories.Select(c => c.Category.Name).ToList(), Details = catering.Details, Name = catering.Name, UserId = catering.UserId, CreatedAt = catering.CreatedAt, SSM = catering.SSM, CompanyName = catering.CompanyName, State = catering.State, City = catering.City, Street1 = catering.Street1, Street2 = catering.Street2, Latitude = catering.Latitude, Longitude = catering.Longitude, Postcode = catering.Postcode }); } return(Ok(cateringDtos)); }
public async Task <PagedList <VisitPerson> > GetVisitPersonsAsync(VisitPersonParametersDto visitPersonParameters) { if (visitPersonParameters == null) { throw new ArgumentNullException(nameof(visitPersonParameters)); } var collection = _context.VisitPersons .Include(v => v.Visit) .Include(p => p.Person) .Include(t => t.VehicleType) as IQueryable <VisitPerson>; // TODO: AsNoTracking() should increase performance, but will break the sort tests. need to investigate var sieveModel = new SieveModel { Sorts = visitPersonParameters.SortOrder ?? "VisitPersonId", Filters = visitPersonParameters.Filters }; collection = _sieveProcessor.Apply(sieveModel, collection); return(await PagedList <VisitPerson> .CreateAsync(collection, visitPersonParameters.PageNumber, visitPersonParameters.PageSize)); }
public PagedList <ShoppingListItem> GetShoppingListItems(ShoppingListItemParametersDto ShoppingListItemParameters) { if (ShoppingListItemParameters == null) { throw new ArgumentNullException(nameof(ShoppingListItemParameters)); } var collection = _context.ShoppingListItems as IQueryable <ShoppingListItem>; if (!string.IsNullOrWhiteSpace(ShoppingListItemParameters.QueryString)) { var QueryString = ShoppingListItemParameters.QueryString.Trim(); collection = collection.Where(i => i.Name.Contains(QueryString) || i.Category.Contains(QueryString)); } var sieveModel = new SieveModel { Sorts = ShoppingListItemParameters.SortOrder, Filters = ShoppingListItemParameters.Filters }; collection = _sieveProcessor.Apply(sieveModel, collection); return(PagedList <ShoppingListItem> .Create(collection, ShoppingListItemParameters.PageNumber, ShoppingListItemParameters.PageSize)); }
public async Task <IEnumerable <ProductTrotter> > ListAsync(SieveModel query) { var items = _context.ProductTrotters.AsNoTracking(); var result = _sieveProcessor.Apply(query, items); return(await result.ToListAsync()); }
public PagedList <Ingredient> GetIngredients(IngredientParametersDto ingredientParameters) { if (ingredientParameters == null) { throw new ArgumentNullException(nameof(ingredientParameters)); } var collection = _context.Ingredients as IQueryable <Ingredient>; if (!string.IsNullOrWhiteSpace(ingredientParameters.QueryString)) { var QueryString = ingredientParameters.QueryString.Trim(); collection = collection.Where(i => i.Name.Contains(QueryString) || i.Unit.Contains(QueryString)); } if (!string.IsNullOrWhiteSpace(ingredientParameters.RecipeId.ToString())) { collection = collection.Where(i => i.RecipeId.Equals(ingredientParameters.RecipeId)); } var sieveModel = new SieveModel { Sorts = ingredientParameters.SortOrder, Filters = ingredientParameters.Filters }; collection = _sieveProcessor.Apply(sieveModel, collection); return(PagedList <Ingredient> .Create(collection, ingredientParameters.PageNumber, ingredientParameters.PageSize)); }
public async Task <PagedList <Person> > GetPersonsAsync(PersonParametersDto personParameters) { if (personParameters == null) { throw new ArgumentNullException(nameof(personParameters)); } // TODO: AsNoTracking() should increase performance, but will break the sort tests. need to investigate var collection = _context.Persons .Include(t => t.PersonTypes) .Include(e => e.Companies) as IQueryable <Person>; var sieveModel = new SieveModel { Sorts = personParameters.SortOrder ?? "Id", Filters = personParameters.Filters }; collection = _sieve.Apply(sieveModel, collection); return(await PagedList <Person> .CreateAsync(collection, personParameters.PageNumber, personParameters.PageSize)); }
public async Task <PagedList <SampleDto> > Handle(SampleListQuery request, CancellationToken cancellationToken) { if (request.QueryParameters == null) { // log error throw new ApiException("Invalid query parameters."); } // include marker -- to accomodate adding includes with craftsman commands, the next line must stay as `var result = await _db.Samples`. -- do not delete this comment var collection = _db.Samples as IQueryable <Sample>; var sieveModel = new SieveModel { Sorts = request.QueryParameters.SortOrder ?? "SampleId", Filters = request.QueryParameters.Filters }; collection = _sieveProcessor.Apply(sieveModel, collection); var dtoCollection = _db.Samples .ProjectTo <SampleDto>(_mapper.ConfigurationProvider); return(await PagedList <SampleDto> .CreateAsync(dtoCollection, request.QueryParameters.PageNumber, request.QueryParameters.PageSize)); }
public async Task <IEnumerable <OrderDetail> > ListAsync(SieveModel query) { var items = _context.OrderDetails.Include(x => x.OrderId).AsNoTracking(); var result = _sieveProcessor.Apply(query, items); return(await result.ToListAsync()); }
public async Task <PagedList <RideRequestDto> > Handle(RideRequestListQuery request, CancellationToken cancellationToken) { if (request.QueryParameters == null) { // log error throw new ApiException("Invalid query parameters."); } var collection = _db.RideRequests as IQueryable <RideRequest>; var sieveModel = new SieveModel { Sorts = request.QueryParameters.SortOrder ?? "RideRequestId", Filters = request.QueryParameters.Filters }; var appliedCollection = _sieveProcessor.Apply(sieveModel, collection); var dtoCollection = appliedCollection .ProjectTo <RideRequestDto>(_mapper.ConfigurationProvider); return(await PagedList <RideRequestDto> .CreateAsync(dtoCollection, request.QueryParameters.PageNumber, request.QueryParameters.PageSize)); }
public PagedList <Recipe> GetRecipes(RecipeParametersDto recipeParameters) { if (recipeParameters == null) { throw new ArgumentNullException(nameof(recipeParameters)); } var collection = _context.Recipes as IQueryable <Recipe>; if (!string.IsNullOrWhiteSpace(recipeParameters.QueryString)) { var QueryString = recipeParameters.QueryString.Trim(); collection = collection.Where(r => r.RecipeTextField1.Contains(QueryString) || r.RecipeTextField2.Contains(QueryString)); } var sieveModel = new SieveModel { Sorts = recipeParameters.SortOrder, Filters = recipeParameters.Filters }; collection = _sieveProcessor.Apply(sieveModel, collection); return(PagedList <Recipe> .Create(collection, recipeParameters.PageNumber, recipeParameters.PageSize)); }
public PagedList <CredentialsUserDTO> GetAllCredentialsUsers(SieveModel sieveModel) { // Get all query IQueryable <CredentialsUser> credentialsUserQuery = _unitOfWork.CredentialsUserRepository.GetAll(); // Apply filtering to the query credentialsUserQuery = _sieveProcessor.Apply(sieveModel, credentialsUserQuery, applyPagination: false); // Get the total count of records int totalCount = credentialsUserQuery.Count(); // Execute the query to get paginated values List <CredentialsUser> resultDB = PagedList <CredentialsUser> .CreateSourceFromQuery(credentialsUserQuery, sieveModel); // Map results to DTO var credentialsUserDB = _mapper.Map <List <CredentialsUserDTO> >(resultDB); // Encrypt Password //foreach(var credential in credentialsUserDB) //{ // credential.Password = _qphEncriptador.Encriptar(credential.Password); //} // Map the result to PagedList var result = PagedList <CredentialsUserDTO> .CreateFromResults(credentialsUserDB, sieveModel, totalCount); return(result); }
public async Task <PagedList <Visit> > GetVisitsAsync(VisitParametersDto visitParameters) { if (visitParameters == null) { throw new ArgumentNullException(nameof(visitParameters)); } // TODO: AsNoTracking() should increase performance, but will break the sort tests. need to investigate var collection = _context.Visits .Include(t => t.VisitType) .Include(e => e.Employee) .Include(o => o.Office) .Include(p => p.RegisterControl) .Include(e => e.VisitState) as IQueryable <Visit>; var sieveModel = new SieveModel { Sorts = visitParameters.SortOrder ?? "Id", Filters = visitParameters.Filters }; collection = _sieveProcessor.Apply(sieveModel, collection); return(await PagedList <Visit> .CreateAsync(collection, visitParameters.PageNumber, visitParameters.PageSize)); }
public JsonResult Process <T>(IQueryable <T> records, FilterOptions filterOptions) { SieveModel sieveModel = new SieveModel(); //apply filter if (!String.IsNullOrEmpty(filterOptions.filter)) { var str1 = filterOptions.filter.Replace(":\"", "@="); var str2 = str1.Replace(@"""", ""); // remove " var str3 = str2.Replace("\\", ""); // remove \ var str4 = str3.Replace("}", ""); sieveModel.Filters = str4.Replace("{", ""); } // apply sort sieveModel.Sorts = filterOptions.Sort; if (filterOptions.Order == "desc") { sieveModel.Sorts = "-" + sieveModel.Sorts; } var filteredResult = _sieveProcessor.Apply(sieveModel, records); // apply Paging sieveModel.PageSize = filterOptions.Limit; if (filterOptions.Offset == 0) { sieveModel.Page = 1; } else { sieveModel.Page = (int)(filterOptions.Offset / filterOptions.Limit) + 1; } var finalResult = _sieveProcessor.Apply(sieveModel, filteredResult); //construct return object var jsonResult = new { total = filteredResult.Count(), totalNotFiltered = records.Count(), rows = finalResult.ToList() }; return(new JsonResult(jsonResult)); }
public async Task <IEnumerable <SubCategory> > ListAsync(SieveModel query) { var items = _context.SubCategories .AsNoTracking(); var result = _sieveProcessor.Apply(query, items); return(await result.ToListAsync()); }
public async Task <IEnumerable <AttendanceRecord> > GetAllAsync(SieveModel model) { var allRecords = await repository.GetAllAsync(); var filtered = sieve.Apply(model, allRecords.AsQueryable()); return(filtered.AsEnumerable()); }
public void Filter_Equals_Null(string filter) { var model = new SieveModel { Filters = filter }; var result = _processor.Apply(model, _comments); Assert.Equal(100, result.Single().Id); }
public object Get(SieveModel sieve) { var events = this.eventsService .All(); var filteredData = sieveProcessor.Apply(sieve, events); var toListedData = filteredData.ToList(); return(filteredData); }
public async Task <IEnumerable <Product> > ListAsync(SieveModel query) { IQueryable <Product> result = _context.Products .Include(x => x.ChildCategory) .AsNoTracking(); result = _sieveProcessor.Apply(query, result); return(await result.ToListAsync()); }