JobStore.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. namespace Comal.Stores
  6. {
  7. public class JobStore : ScheduleActionStore<Job>
  8. {
  9. protected override void BeforeSave(Job entity)
  10. {
  11. base.BeforeSave(entity);
  12. if (!entity.Account.IsValid() && entity.Customer.IsValid())
  13. {
  14. Customer final = null;
  15. var customer = Provider.Load(new Filter<Customer>(x => x.ID).IsEqualTo(entity.Customer.ID)).FirstOrDefault();
  16. if (customer != null)
  17. {
  18. final = customer;
  19. if (customer.Account.IsValid())
  20. {
  21. var account = Provider.Load(new Filter<Customer>(x => x.ID).IsEqualTo(customer.Account.ID)).FirstOrDefault();
  22. if (account != null)
  23. final = account;
  24. }
  25. }
  26. entity.Account.Synchronise(final);
  27. }
  28. StoreUtils.Geocode(entity.SiteAddress);
  29. }
  30. protected override void AfterDelete(Job entity)
  31. {
  32. base.AfterDelete(entity);
  33. var setoutstore = FindSubStore<Setout>();
  34. var setouts = setoutstore.Load(new Filter<Setout>(x => x.JobLink.ID).IsEqualTo(entity.ID));
  35. foreach (var setout in setouts)
  36. setoutstore.Delete(setout, "Cascaded Delete from Job");
  37. }
  38. }
  39. }