| 12345678910111213141516171819202122232425262728293031323334 | using System.Linq;using Comal.Classes;using InABox.Core;namespace Comal.Stores{    public class InvoiceStore : BaseStore<Invoice>    {        protected override void BeforeSave(Invoice entity)        {            base.BeforeSave(entity);            // Get the Customer Details for this Invoice            if (!entity.CustomerLink.IsValid() & entity.JobLink.IsValid())            {                var job = Provider.Query(                    new Filter<Job>(x => x.ID).IsEqualTo(entity.JobLink.ID),                    Columns.None<Job>().Add(x => x.Account.ID)                        .Add(x => x.Account.Deleted)                        .Add(x => x.Customer.ID))                    .Rows.FirstOrDefault()?.ToObject<Job>();                if (job != null)                {                    entity.CustomerLink.ID = job.Account.IsValid() ? job.Account.ID : job.Customer.ID;                    //var customer = Provider.Load(new Filter<Customer>(x => x.ID).IsEqualTo(entity.CustomerLink.ID)).FirstOrDefault();                    //entity.CustomerLink.Synchronise(customer);                }            }            //UpdateAggregate<Customer>(entity, entity.CustomerLink, Sum<Customer>(x=>x.Balance, x=>x.Balance));        }    }}
 |