SupplierLookups.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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.ProductLink.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. public override Columns<Supplier> DefineColumns()
  19. {
  20. return new Columns<Supplier>(
  21. x => x.ID,
  22. x => x.Code,
  23. x => x.Name
  24. );
  25. }
  26. public override Filter<Supplier> DefineFilter()
  27. {
  28. return null;
  29. }
  30. public override SortOrder<Supplier> DefineSortOrder()
  31. {
  32. return new SortOrder<Supplier>(x => x.Code);
  33. }
  34. }
  35. }