InvoiceStore.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. namespace Comal.Stores
  6. {
  7. public class InvoiceStore : BaseStore<Invoice>
  8. {
  9. protected override void BeforeSave(Invoice entity)
  10. {
  11. base.BeforeSave(entity);
  12. // Get the Customer Details for this Invoice
  13. if (!entity.CustomerLink.IsValid() & entity.JobLink.IsValid())
  14. {
  15. var job = Provider.Query(
  16. new Filter<Job>(x => x.ID).IsEqualTo(entity.JobLink.ID),
  17. new Columns<Job>(x => x.Account.ID)
  18. .Add(x => x.Account.Deleted)
  19. .Add(x => x.Customer.ID))
  20. .Rows.FirstOrDefault()?.ToObject<Job>();
  21. if (job != null)
  22. {
  23. entity.CustomerLink.ID = job.Account.IsValid() ? job.Account.ID : job.Customer.ID;
  24. //var customer = Provider.Load(new Filter<Customer>(x => x.ID).IsEqualTo(entity.CustomerLink.ID)).FirstOrDefault();
  25. //entity.CustomerLink.Synchronise(customer);
  26. }
  27. }
  28. //UpdateAggregate<Customer>(entity, entity.CustomerLink, Sum<Customer>(x=>x.Balance, x=>x.Balance));
  29. }
  30. protected override void BeforeDelete(Invoice entity)
  31. {
  32. base.BeforeDelete(entity);
  33. entity.CustomerLink.ID = Guid.Empty;
  34. //UpdateAggregate<Customer>(entity, entity.CustomerLink, Sum<Customer>(x => x.Balance, x => x.Balance));
  35. }
  36. }
  37. }