|
@@ -1,22 +1,35 @@
|
|
|
using Comal.Classes;
|
|
|
+using InABox.Core;
|
|
|
using System;
|
|
|
|
|
|
-namespace Comal.Stores
|
|
|
+namespace Comal.Stores;
|
|
|
+
|
|
|
+internal class BillStore : BaseStore<Bill>
|
|
|
{
|
|
|
- internal class BillStore : BaseStore<Bill>
|
|
|
+ protected override void BeforeSave(Bill entity)
|
|
|
{
|
|
|
- protected override void BeforeSave(Bill entity)
|
|
|
+ base.BeforeSave(entity);
|
|
|
+
|
|
|
+ if(entity.HasOriginalValue(x => x.Number) || entity.SupplierLink.HasOriginalValue(x => x.ID))
|
|
|
{
|
|
|
- base.BeforeSave(entity);
|
|
|
- //UpdateAggregate<Supplier>(entity, entity.SupplierLink, Sum<Supplier>(b => b.Balance, s => s.Balance));
|
|
|
+ var existing = Provider.Query<Bill>(
|
|
|
+ new Filter<Bill>(x => x.Number).IsEqualTo(entity.Number)
|
|
|
+ .And(x => x.SupplierLink.ID).IsEqualTo(entity.SupplierLink.ID)
|
|
|
+ .And(x => x.ID).IsNotEqualTo(entity.ID),
|
|
|
+ Columns.None<Bill>().Add(x => x.ID));
|
|
|
+ if(existing.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ throw new DuplicateCodeException(typeof(Bill), new Dictionary<string, object> {{ nameof(Bill.Number), entity.Number }});
|
|
|
+ }
|
|
|
}
|
|
|
+ //UpdateAggregate<Supplier>(entity, entity.SupplierLink, Sum<Supplier>(b => b.Balance, s => s.Balance));
|
|
|
+ }
|
|
|
|
|
|
- protected override void BeforeDelete(Bill entity)
|
|
|
- {
|
|
|
- base.BeforeDelete(entity);
|
|
|
+ protected override void BeforeDelete(Bill entity)
|
|
|
+ {
|
|
|
+ base.BeforeDelete(entity);
|
|
|
|
|
|
- entity.SupplierLink.ID = Guid.Empty;
|
|
|
- //UpdateAggregate<Supplier>(entity, entity.SupplierLink, Sum<Supplier>(b => b.Balance, s => s.Balance));
|
|
|
- }
|
|
|
+ entity.SupplierLink.ID = Guid.Empty;
|
|
|
+ //UpdateAggregate<Supplier>(entity, entity.SupplierLink, Sum<Supplier>(b => b.Balance, s => s.Balance));
|
|
|
}
|
|
|
}
|