123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using InABox.Clients;
- using InABox.Core;
- namespace Comal.Classes
- {
- [UserTracking(typeof(Product))]
- public class ProductGroup : Entity, IRemotable, IPersistent, ILicense<ProductManagementLicense>, IExportable, IImportable, IMergeable
- {
-
- [EditorSequence(1)]
- [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
- public string Code { get; set; }
- [EditorSequence(2)]
- [TextBoxEditor]
- public string Description { get; set; }
-
- private class ProductGroupLookup : LookupDefinitionGenerator<ProductGroup, ProductGroup>
- {
- public override Filter<ProductGroup> DefineFilter(ProductGroup[] items)
- {
- if (items?.Any() != true || items.All(x => x.ID == Guid.Empty))
- return LookupFactory.DefineFilter<ProductGroup>();
- var data = Client.Query(
- null,
- Columns.None<ProductGroup>().Add(x => x.ID).Add(x => x.Parent.ID));
- var nodes = new CoreTreeNodes();
- nodes.Load<ProductGroup>(data, x => x.ID, x => x.Parent.ID);
- var exclusions = items.SelectMany(x => nodes.GetChildren(x.ID)).ToArray();
- var ids = exclusions.Select(x => x.ID).ToArray();
- return new Filter<ProductGroup>(x => x.ID).NotInList(ids);
- }
- public override Columns<ProductGroup> DefineFilterColumns()
- => Columns.None<ProductGroup>().Add(x => x.ID).Add(x => x.Parent.ID).Add(x => x.Code);
- }
-
- [LookupDefinition(typeof(ProductGroupLookup))]
- [EditorSequence(3)]
- public ProductGroupLink Parent { get; set; }
-
- public override string ToString()
- {
- return string.Format("{0}: {1}", Code, Description);
- }
- }
- }
|