using System; using System.Linq; using Comal.Classes; using InABox.Core; namespace Comal.Stores { public class InvoiceStore : BaseStore { 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(x => x.ID).IsEqualTo(entity.JobLink.ID), new Columns(x => x.Account.ID) .Add(x => x.Account.Deleted) .Add(x => x.Customer.ID)) .Rows.FirstOrDefault()?.ToObject(); if (job != null) { entity.CustomerLink.ID = job.Account.IsValid() ? job.Account.ID : job.Customer.ID; //var customer = Provider.Load(new Filter(x => x.ID).IsEqualTo(entity.CustomerLink.ID)).FirstOrDefault(); //entity.CustomerLink.Synchronise(customer); } } //UpdateAggregate(entity, entity.CustomerLink, Sum(x=>x.Balance, x=>x.Balance)); } } }