ProductGroup.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using InABox.Clients;
  5. using InABox.Core;
  6. namespace Comal.Classes
  7. {
  8. [UserTracking(typeof(Product))]
  9. public class ProductGroup : Entity, IRemotable, IPersistent, ILicense<ProductManagementLicense>, IExportable, IImportable, IMergeable
  10. {
  11. [EditorSequence(1)]
  12. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  13. public string Code { get; set; }
  14. [EditorSequence(2)]
  15. [TextBoxEditor]
  16. public string Description { get; set; }
  17. private class ProductGroupLookup : LookupDefinitionGenerator<ProductGroup, ProductGroup>
  18. {
  19. public override Filter<ProductGroup> DefineFilter(ProductGroup[] items)
  20. {
  21. if (items?.Any() != true || items.All(x => x.ID == Guid.Empty))
  22. return LookupFactory.DefineFilter<ProductGroup>();
  23. var data = Client.Query(
  24. null,
  25. Columns.None<ProductGroup>().Add(x => x.ID).Add(x => x.Parent.ID));
  26. var nodes = new CoreTreeNodes();
  27. nodes.Load<ProductGroup>(data, x => x.ID, x => x.Parent.ID);
  28. var exclusions = items.SelectMany(x => nodes.GetChildren(x.ID)).ToArray();
  29. return new Filter<ProductGroup>(x => x.ID).NotInList(exclusions);
  30. }
  31. public override Columns<ProductGroup> DefineFilterColumns()
  32. => Columns.None<ProductGroup>().Add(x => x.ID).Add(x => x.Parent.ID).Add(x => x.Code);
  33. }
  34. [LookupDefinition(typeof(ProductGroupLookup))]
  35. [EditorSequence(3)]
  36. public ProductGroupLink Parent { get; set; }
  37. public override string ToString()
  38. {
  39. return string.Format("{0}: {1}", Code, Description);
  40. }
  41. }
  42. }