1234567891011121314151617181920212223242526272829303132333435 |
- using System;
- 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),
- new Columns<Job>(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));
- }
- }
- }
|