Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static IQueryable<EnrollCustomerPremise> ApplyCustomerEnrollmentSearchFilter(this IQueryable<EnrollCustomerPremise> source, CustomerEnrollmentSearchCommand filter)
- {
- var name = filter.CustomerName;
- var query = source
- .Include(p => p.EnrollCustomer)
- .Include(p => p.EnrollCustomer.EnrollStatus);
- if (!string.IsNullOrWhiteSpace(filter.CustomerType))
- {
- query = query.Where(c => (c.EnrollCustomer.CustomerType.Contains(filter.CustomerType)));
- }
- if (!string.IsNullOrWhiteSpace(filter.Phone))
- {
- query = query.Where(c => (c.EnrollCustomer.PrimaryPhone.Contains(filter.Phone)));
- }
- if (!string.IsNullOrWhiteSpace(filter.Email))
- {
- query = query.Where(c => (c.EnrollCustomer.BillingEmail.Contains(filter.Email)));
- }
- if ((filter.Status ?? default(int)) != default(int))
- {
- query = query.Where(c => (c.EnrollCustomer.EnrollStatusId == filter.Status));
- }
- if (!string.IsNullOrWhiteSpace(filter.Zip))
- {
- query = query.Where(c => (c.EnrollCustomer.BillingZip.Contains(filter.Zip)));
- }
- if (!string.IsNullOrWhiteSpace(filter.IstaAccountNumber))
- {
- query = query.Where(c => (c.EnrollCustomer.CustomerAccountNumber.Contains(filter.IstaAccountNumber)));
- }
- if (!string.IsNullOrWhiteSpace(filter.SsnTaxId))
- {
- query = query.Where(c => (c.EnrollCustomer.TaxId.Contains(filter.SsnTaxId)));
- }
- if (!string.IsNullOrWhiteSpace(filter.IgniteAccountNumber))
- {
- query = query.Where(c => (c.BillingAccountNumber.Contains(filter.IgniteAccountNumber)));
- }
- if (!string.IsNullOrWhiteSpace(filter.Ldc))
- {
- query = query.Where(c => (c.EsiId.Contains(filter.Ldc)));
- }
- if (!string.IsNullOrWhiteSpace(name))
- {
- var names = name.Split(' ');
- // Suppressed the warning RCS1155 because linq cannot translate indexof string comparison to sql.
- #pragma warning disable RCS1155 // Use StringComparison when comparing strings.
- query = query.Where(c => names.AsQueryable().All(n => c.EnrollCustomer.CustomerName.ToLower().Contains(n.ToLower())));
- #pragma warning restore RCS1155 // Use StringComparison when comparing strings.
- }
- return query;
- }
Add Comment
Please, Sign In to add comment