CustomerProduct.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. protected override void Init()
  30. {
  31. base.Init();
  32. Customer = new CustomerLink();
  33. Product = new ProductLink(() => this);
  34. Charge = new ProductCharge();
  35. }
  36. }
  37. public class CustomerProductUnionGenerator : AutoEntityUnionGenerator<ICustomerProduct>
  38. {
  39. protected override void Configure()
  40. {
  41. AddTable<CustomerProduct>();
  42. AddTable<Product>()
  43. .AddConstant(x => x.Customer.ID, Guid.Empty)
  44. .AddConstant(x=>x.Product.ID, new Column<Product>(x=>x.ID));
  45. }
  46. public override bool Distinct => false;
  47. public override Column<ICustomerProduct>[] IDColumns => new Column<ICustomerProduct>[]
  48. {
  49. new Column<ICustomerProduct>(x => x.Customer.ID),
  50. new Column<ICustomerProduct>(x => x.Product.ID)
  51. };
  52. }
  53. [AutoEntity(typeof(CustomerProductUnionGenerator))]
  54. public class CustomerProductSummary : Entity, IRemotable, IPersistent, ICustomerProduct, ILicense<CoreLicense>
  55. {
  56. public CustomerLink Customer { get; set; }
  57. public ProductLink Product { get; set; }
  58. public ProductCharge Charge { get; set; }
  59. protected override void Init()
  60. {
  61. base.Init();
  62. Customer = new CustomerLink();
  63. Product = new ProductLink(() => this);
  64. Charge = new ProductCharge();
  65. }
  66. }
  67. }