| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 | using System;using System.Linq;using Comal.Classes;using InABox.Core;namespace Comal.Stores{    public class JobStore : ScheduleActionStore<Job>    {        protected override void BeforeSave(Job entity)        {            base.BeforeSave(entity);            if (!entity.Account.IsValid() && entity.Customer.IsValid())            {                Customer final = null;                var customer = Provider.Load(new Filter<Customer>(x => x.ID).IsEqualTo(entity.Customer.ID)).FirstOrDefault();                if (customer != null)                {                    final = customer;                    if (customer.Account.IsValid())                    {                        var account = Provider.Load(new Filter<Customer>(x => x.ID).IsEqualTo(customer.Account.ID)).FirstOrDefault();                        if (account != null)                            final = account;                    }                }                entity.Account.Synchronise(final);            }            StoreUtils.Geocode(entity.SiteAddress);        }                protected override void AfterDelete(Job entity)        {            base.AfterDelete(entity);            var setoutstore = FindSubStore<Setout>();            var setouts = setoutstore.Load(new Filter<Setout>(x => x.JobLink.ID).IsEqualTo(entity.ID));            foreach (var setout in setouts)                setoutstore.Delete(setout, "Cascaded Delete from Job");        }    }}
 |