CustomerProduct.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using InABox.Core;
  3. namespace Comal.Classes
  4. {
  5. public interface ICustomerProduct
  6. {
  7. CustomerLink Customer { get; set; }
  8. ProductLink Product { get; set; }
  9. ProductCharge Charge { get; set; }
  10. }
  11. [UserTracking(typeof(Product))]
  12. public class CustomerProduct : Entity, IPersistent, IRemotable,
  13. ICustomerProduct,
  14. IManyToMany<Customer, Product>,
  15. IManyToMany<Product, Customer>,
  16. ILicense<ProductManagementLicense>,
  17. IExportable,
  18. IImportable
  19. {
  20. [EntityRelationship(DeleteAction.Cascade)]
  21. [EditorSequence(1)]
  22. public CustomerLink Customer { get; set; }
  23. [EntityRelationship(DeleteAction.Cascade)]
  24. [EditorSequence(2)]
  25. public ProductLink Product { get; set; }
  26. [ProductChargeEditor]
  27. [EditorSequence(3)]
  28. public ProductCharge Charge { get; set; }
  29. }
  30. public class CustomerProductUnionGenerator : AutoEntityUnionGenerator<ICustomerProduct>
  31. {
  32. protected override void Configure()
  33. {
  34. AddTable<CustomerProduct>();
  35. AddTable<Product>()
  36. .AddConstant(x => x.Customer.ID, Guid.Empty)
  37. .AddConstant(x=>x.Product.ID, new Column<Product>(x=>x.ID));
  38. }
  39. public override bool Distinct => false;
  40. public override Column<ICustomerProduct>[] IDColumns => new Column<ICustomerProduct>[]
  41. {
  42. new Column<ICustomerProduct>(x => x.Customer.ID),
  43. new Column<ICustomerProduct>(x => x.Product.ID)
  44. };
  45. }
  46. [AutoEntity(typeof(CustomerProductUnionGenerator))]
  47. public class CustomerProductSummary : Entity, IRemotable, IPersistent, ICustomerProduct, ILicense<CoreLicense>
  48. {
  49. public CustomerLink Customer { get; set; }
  50. public ProductLink Product { get; set; }
  51. public ProductCharge Charge { get; set; }
  52. }
  53. }