SupplierLookups.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Linq;
  3. using InABox.Clients;
  4. using InABox.Core;
  5. namespace Comal.Classes
  6. {
  7. public class SupplierLookups : EntityLookup<Supplier>, ILookupDefinition<Supplier, Product>
  8. {
  9. public Filter<Supplier> DefineFilter(Product[] items)
  10. {
  11. var item = items?.SingleOrDefault();
  12. var suppliers = new Client<SupplierProduct>().Query(
  13. new Filter<SupplierProduct>(x => x.Product.ID).IsEqualTo(item.ID),
  14. new Columns<SupplierProduct>(x => x.SupplierLink.ID));
  15. var ids = suppliers.Rows.Select(r => r.Get<SupplierProduct, Guid>(x => x.SupplierLink.ID)).ToArray();
  16. return new Filter<Supplier>(x => x.ID).InList(ids);
  17. }
  18. Columns<Product> ILookupDefinition<Supplier, Product>.DefineFilterColumns()
  19. => new Columns<Product>(x => x.ID);
  20. public override Columns<Supplier> DefineColumns()
  21. {
  22. return new Columns<Supplier>(
  23. x => x.ID,
  24. x => x.Code,
  25. x => x.Name
  26. );
  27. }
  28. public override Filter<Supplier> DefineFilter()
  29. {
  30. return null;
  31. }
  32. public override SortOrder<Supplier> DefineSortOrder()
  33. {
  34. return new SortOrder<Supplier>(x => x.Code);
  35. }
  36. }
  37. }