InvoiceStore.cs 1.2 KB

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