public string GetFilterExpressionTest(CustomerPageQuery q) { var bld = new StringBuilder(); GetFilterExpression(q, bld); return(bld.ToString()); }
public async Task <DkmsPage <CustomerModel> > GetPageAsync(CustomerPageQuery query) { var page = await _dkmsUserRepository.GetPageAsync <CustomerEntity>(DkmsUserContext.UserIdDefaultEmpty, query); if (!page.Any()) { return(DkmsPage <CustomerModel> .Empty(query)); } var userId = DkmsUserContext.UserIdDefaultEmpty; var customerIds = page.GetKeys(s => s.Id); var values = await _dkmsPropertyValueRepository.GetListAsync <CustomerPropertyValueEntity>(userId, customerIds); var customers = page.List.Select(customer => { var model = new CustomerModel { Customer = customer }; model.Values = values.Where(v => v.InstanceId == customer.Id).ToList(); return(model); }).ToList(); return(new DkmsPage <CustomerModel>() { Count = page.Count, List = customers, PageSize = page.PageSize, PageIndex = page.PageIndex }); }
public void QueryValidation() { var q1 = new CustomerPageQuery() { PageSize = 10, PageNumber = 0 }; new ValidationQueryHandlerDecorator <CustomerPageQuery, DataPage <Customer> >(null, _hndlLinq).Handle(q1); }
public override DataPage <Customer> Handle(CustomerPageQuery q) { var res = DbContextUser.DataSource.Skip((q.PageNumber - 1) * q.PageSize).Take(q.PageSize).Select(c => c); var cnt = DbContextUser.DataSource.Count(); return(new DataPage <Customer> { Data = res.ToList(), TotalRecordsCount = cnt, TotalPages = cnt / q.PageSize, PageNumber = q.PageNumber }); }
public override void TestInitialize() { base.TestInitialize(); _defaultQuery = new CustomerPageQuery(); _sortSurname = new CustomerPageQuery() { PageSize = 10 }; _sortSurname.AddSorting("SurName"); _hndlLinq = new CustomerPageQueryLinqHandler(new CustomersDataContext(Customer.GetTestdata())); _hndlLinqRef = new CustomerRefPageQueryLinqHandler(new CustomersDataContext(Customer.GetTestdata())); }
public void TestLinqPagging() { var q1 = new CustomerPageQuery() { PageSize = Constants.PageSizeNoPagging }; var pg = _hndlLinq.Handle(q1); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 1); Assert.IsTrue(pg.TotalRecordsCount == 17); q1.PageSize = 10; q1.PageNumber = 1; pg = _hndlLinq.Handle(q1); Assert.IsTrue(pg.Data.Count == 10); Assert.IsTrue(pg.Data[0].Name == "Frederik"); Assert.IsTrue(pg.Data[9].Name == "Nick 3"); q1.PageNumber = 2; pg = _hndlLinq.Handle(q1); Assert.IsTrue(pg.Data.Count == 7); Assert.IsTrue(pg.Data[0].Name == "Nick 4"); Assert.IsTrue(pg.Data[6].Name == "Nick' [10]"); q1.PageNumber = 100; pg = _hndlLinq.Handle(q1); Assert.IsTrue(pg.PageNumber == 2); Assert.IsTrue(pg.TotalPages == 2); Assert.IsTrue(pg.Data[0].Name == "Nick 4"); Assert.IsTrue(pg.Data[6].Name == "Nick' [10]"); //Dumper.Dump(pg); }
public void TestLinqSorting() { var pg = _hndlLinq.Handle(_sort1Asc); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 1); Assert.IsTrue(pg.TotalRecordsCount == 3); Assert.IsTrue(pg.Data[0].Name == "Thomas"); Assert.IsTrue(pg.Data[2].Name == "Thomas"); pg = _hndlLinq.Handle(_sort2Asc); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 1); Assert.IsTrue(pg.TotalRecordsCount == 1); Assert.IsTrue(pg.Data[0].Name == "Thomas"); pg = _hndlLinq.Handle(_sort3Asc); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 1); Assert.IsTrue(pg.TotalRecordsCount == 1); Assert.IsTrue(pg.Data[0].Name == "Thomas"); pg = _hndlLinq.Handle(_sort4Asc); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 2); Assert.IsTrue(pg.TotalRecordsCount == 14); Assert.IsTrue(pg.Data[0].Name == "Ariel"); Assert.IsTrue(pg.Data[9].Name == "Nick 5"); pg = _hndlLinq.Handle(_sort1Dsc); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 2); Assert.IsTrue(pg.TotalRecordsCount == 11); Assert.IsTrue(pg.Data[0].Name == "Nick 9"); Assert.IsTrue(pg.Data[9].Name == "Nick' [10]"); pg = _hndlLinq.Handle(_sort2Dsc); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 1); Assert.IsTrue(pg.TotalRecordsCount == 10); Assert.IsTrue(pg.Data[0].Name == "Nick 9"); Assert.IsTrue(pg.Data[9].Name == "Nick' [10]"); pg = _hndlLinq.Handle(_sort3Dsc); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 1); Assert.IsTrue(pg.TotalRecordsCount == 4); Assert.IsTrue(pg.Data[0].Name == "Nick 6"); Assert.IsTrue(pg.Data[2].Name == "Nick 2"); pg = _hndlLinq.Handle(_sort4Dsc); Assert.IsTrue(pg.PageNumber == 0); Assert.IsTrue(pg.TotalPages == 0); Assert.IsTrue(pg.TotalRecordsCount == 0); pg = _hndlLinq.Handle(_not1); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 1); Assert.IsTrue(pg.TotalRecordsCount == 1); Assert.IsTrue(pg.Data[0].Name == "Nick 6"); pg = _hndlLinq.Handle(_not2); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 1); Assert.IsTrue(pg.TotalRecordsCount == 7); Assert.IsTrue(pg.Data[0].Name == "Frederik"); Assert.IsTrue(pg.Data[6].Name == "Thomas"); pg = _hndlLinq.Handle(_sortSurname); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 2); Assert.IsTrue(pg.TotalRecordsCount == 17); Assert.IsTrue(pg.Data[0].Name == "Nick 6"); Assert.IsTrue(pg.Data[9].Name == "Nick 4"); pg = _hndlLinq.Handle(_likeScreen1); Assert.IsTrue(pg.PageNumber == 0); Assert.IsTrue(pg.TotalPages == 0); Assert.IsTrue(pg.TotalRecordsCount == 0); pg = _hndlLinq.Handle(_likeScreen2); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 1); Assert.IsTrue(pg.TotalRecordsCount == 1); Assert.IsTrue(pg.Data[0].Name == "Nick' [10]"); pg = _hndlLinq.Handle(_likeScreen3); Assert.IsTrue(pg.PageNumber == 0); Assert.IsTrue(pg.TotalPages == 0); Assert.IsTrue(pg.TotalRecordsCount == 0); var qCase = new CustomerPageQuery() { PageSize = 10 }; qCase.AddFiltering("Name", "thOmas", CriterionPredicate.Eq, true); qCase.AddFiltering("SurName", "Frank", CriterionPredicate.Neq); qCase.AddFiltering("Rank", 5, CriterionPredicate.LtEq); pg = _hndlLinq.Handle(qCase); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 1); Assert.IsTrue(pg.TotalRecordsCount == 2); Assert.IsTrue(pg.Data[0].Name == "Thomas"); Assert.IsTrue(pg.Data[1].Name == "Thomas"); qCase = new CustomerPageQuery() { PageSize = 10 }; qCase.AddFiltering("Name", "thOmas", CriterionPredicate.Eq, false); qCase.AddFiltering("SurName", "Frank", CriterionPredicate.Neq); qCase.AddFiltering("Rank", 5, CriterionPredicate.LtEq); pg = _hndlLinq.Handle(qCase); Assert.IsTrue(pg.PageNumber == 0); Assert.IsTrue(pg.TotalPages == 0); Assert.IsTrue(pg.TotalRecordsCount == 0); qCase = new CustomerPageQuery() { PageSize = 10 }; qCase.AddFiltering("Name", "thOmas", CriterionPredicate.StartsWith, true); qCase.AddFiltering("SurName", "Frank", CriterionPredicate.Neq); qCase.AddFiltering("Rank", 5, CriterionPredicate.LtEq); pg = _hndlLinq.Handle(qCase); Assert.IsTrue(pg.PageNumber == 1); Assert.IsTrue(pg.TotalPages == 1); Assert.IsTrue(pg.TotalRecordsCount == 2); Assert.IsTrue(pg.Data[0].Name == "Thomas"); Assert.IsTrue(pg.Data[1].Name == "Thomas"); qCase = new CustomerPageQuery() { PageSize = 10 }; qCase.AddFiltering("Name", "thOmas", CriterionPredicate.StartsWith, false); qCase.AddFiltering("Rank", 5, CriterionPredicate.LtEq); pg = _hndlLinq.Handle(qCase); Assert.IsTrue(pg.PageNumber == 0); Assert.IsTrue(pg.TotalPages == 0); Assert.IsTrue(pg.TotalRecordsCount == 0); //Dumper.Dump(pg); }
public async Task <DkmsPage <CustomerModel> > GetPageAsync([FromQuery] CustomerPageQuery query) { return(await _customerSearcher.GetPageAsync(query)); }
public virtual void TestInitialize() { _sort1Asc = new CustomerPageQuery() { PageSize = 10 }; _sort1Asc.AddSorting("Name") .AddFiltering("Name", "Thomas", CriterionPredicate.Eq); _sortNameFilter2RankAnd = new CustomerPageQuery() { PageSize = 10 }; _sortNameFilter2RankAnd.AddSorting("Rank", true) .AddSorting("Rank", true) .AddFiltering("Rank", 10, CriterionPredicate.GtEq) .AddFiltering("Rank", 20, CriterionPredicate.LtEq) .Filtering.CombiningRule = FilteringCollection.CombiningFilters.And; _sortNameFilter2RankOr = new CustomerPageQuery() { PageSize = 10 }; _sortNameFilter2RankOr.AddSorting("Rank", true) .AddSorting("Rank", true) .AddFiltering("Rank", 14, CriterionPredicate.Eq) .AddFiltering("Rank", 16, CriterionPredicate.Eq) .AddFiltering("Rank", 2, CriterionPredicate.Eq) .Filtering.CombiningRule = FilteringCollection.CombiningFilters.Or; _sort2Asc = new CustomerPageQuery() { PageSize = 10 }; _sort2Asc.AddSorting("Name"); _sort2Asc.AddSorting("SurName") .AddFiltering("Name", "Thomas", CriterionPredicate.Eq) .AddFiltering("SurName", "Nikolas", CriterionPredicate.Eq); _sort3Asc = new CustomerPageQuery() { PageSize = 10 }; _sort3Asc.AddSorting("Name") .AddSorting("SurName") .AddSorting("Rank") .AddFiltering("Name", "Thomas", CriterionPredicate.Eq) .AddFiltering("SurName", "Nikolas", CriterionPredicate.Eq) .AddFiltering("Rank", 7, CriterionPredicate.Eq); _sort4Asc = new CustomerPageQuery() { PageSize = 10 }; _sort4Asc.AddSorting("Name") .AddSorting("SurName") .AddSorting("Rank") .AddSorting("Amt") .AddFiltering("Name", "Thomas", CriterionPredicate.Neq); _sort1Dsc = new CustomerPageQuery() { PageSize = 10 }; _sort1Dsc.AddSorting("Name", true) .AddFiltering("Rank", 10, CriterionPredicate.Gt); _sort2Dsc = new CustomerPageQuery() { PageSize = 10 }; _sort2Dsc.AddSorting("Name", true) .AddSorting("SurName", true) .AddFiltering("Name", "ck", CriterionPredicate.Contains); _sort3Dsc = new CustomerPageQuery() { PageSize = 10 }; _sort3Dsc.AddSorting("Name", true) .AddSorting("SurName", true) .AddSorting("Rank", true) .AddFiltering("Name", "Ni", CriterionPredicate.StartsWith) .AddFiltering("Amt", 15.5f, CriterionPredicate.LtEq); _sort4Dsc = new CustomerPageQuery() { PageSize = 10 }; _sort4Dsc.AddSorting("Name", true) .AddSorting("SurName", true) .AddSorting("Rank", true) .AddSorting("Amt", true) .AddFiltering("Name", "As", CriterionPredicate.EndsWith) .AddFiltering("Amt", 17.25f, CriterionPredicate.GtEq); _not1 = new CustomerPageQuery() { PageSize = 10 }; _not1.AddFiltering("SurName", null, CriterionPredicate.Null) .AddFiltering("Amt", 1f, CriterionPredicate.Gt); _not2 = new CustomerPageQuery() { PageSize = 10 }; _not2.AddFiltering("SurName", null, CriterionPredicate.NotNull) .AddFiltering("SurName", "Tomazo", CriterionPredicate.Neq); _likeScreen1 = new CustomerPageQuery() { PageSize = 10 }; _likeScreen1.AddFiltering("Name", "abc'rgb_1", CriterionPredicate.Neq) .AddFiltering("SurName", "Tom'az'!", CriterionPredicate.Contains); _likeScreen2 = new CustomerPageQuery() { PageSize = 10 }; _likeScreen2.AddFiltering("Name", "' [10]", CriterionPredicate.Contains); _likeScreen3 = new CustomerPageQuery() { PageSize = 10 }; _likeScreen3.AddFiltering("Name", "abc'''bcb123%%111", CriterionPredicate.Contains); }
public override DataPage <Customer> Handle(CustomerPageQuery q) { return(GetPage(q, DbContextUser.DataSource.AsQueryable())); }