Guest User

Untitled

a guest
Dec 14th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. public static IQueryable<EnrollCustomerPremise> ApplyCustomerEnrollmentSearchFilter(this IQueryable<EnrollCustomerPremise> source, CustomerEnrollmentSearchCommand filter)
  2. {
  3. var name = filter.CustomerName;
  4.  
  5. var query = source
  6. .Include(p => p.EnrollCustomer)
  7. .Include(p => p.EnrollCustomer.EnrollStatus);
  8.  
  9. if (!string.IsNullOrWhiteSpace(filter.CustomerType))
  10. {
  11. query = query.Where(c => (c.EnrollCustomer.CustomerType.Contains(filter.CustomerType)));
  12. }
  13. if (!string.IsNullOrWhiteSpace(filter.Phone))
  14. {
  15. query = query.Where(c => (c.EnrollCustomer.PrimaryPhone.Contains(filter.Phone)));
  16. }
  17. if (!string.IsNullOrWhiteSpace(filter.Email))
  18. {
  19. query = query.Where(c => (c.EnrollCustomer.BillingEmail.Contains(filter.Email)));
  20. }
  21. if ((filter.Status ?? default(int)) != default(int))
  22. {
  23. query = query.Where(c => (c.EnrollCustomer.EnrollStatusId == filter.Status));
  24. }
  25. if (!string.IsNullOrWhiteSpace(filter.Zip))
  26. {
  27. query = query.Where(c => (c.EnrollCustomer.BillingZip.Contains(filter.Zip)));
  28. }
  29. if (!string.IsNullOrWhiteSpace(filter.IstaAccountNumber))
  30. {
  31. query = query.Where(c => (c.EnrollCustomer.CustomerAccountNumber.Contains(filter.IstaAccountNumber)));
  32. }
  33. if (!string.IsNullOrWhiteSpace(filter.SsnTaxId))
  34. {
  35. query = query.Where(c => (c.EnrollCustomer.TaxId.Contains(filter.SsnTaxId)));
  36. }
  37. if (!string.IsNullOrWhiteSpace(filter.IgniteAccountNumber))
  38. {
  39. query = query.Where(c => (c.BillingAccountNumber.Contains(filter.IgniteAccountNumber)));
  40. }
  41. if (!string.IsNullOrWhiteSpace(filter.Ldc))
  42. {
  43. query = query.Where(c => (c.EsiId.Contains(filter.Ldc)));
  44. }
  45. if (!string.IsNullOrWhiteSpace(name))
  46. {
  47. var names = name.Split(' ');
  48. // Suppressed the warning RCS1155 because linq cannot translate indexof string comparison to sql.
  49. #pragma warning disable RCS1155 // Use StringComparison when comparing strings.
  50. query = query.Where(c => names.AsQueryable().All(n => c.EnrollCustomer.CustomerName.ToLower().Contains(n.ToLower())));
  51. #pragma warning restore RCS1155 // Use StringComparison when comparing strings.
  52. }
  53.  
  54. return query;
  55. }
Add Comment
Please, Sign In to add comment