using Comal.Classes; using InABox.Core; namespace Comal.Stores; internal class JobScopeStatusStore : BaseStore { protected override void BeforeSave(JobScopeStatus entity) { base.BeforeSave(entity); var others = Provider.Query(new Filter(x => x.ID).IsNotEqualTo(entity.ID) .And(new Filter(x=>x.ContractDefault).IsEqualTo(true) .Or(x=>x.VariationDefault).IsEqualTo(true) .Or(x=>x.AdjustmentDefault).IsEqualTo(true) ) ).ToObjects().ToList(); var otherContracts = others.Where(x=>x.ContractDefault); if (entity.ContractDefault) { foreach (var otherContract in otherContracts) otherContract.ContractDefault = false; } else if (!otherContracts.Any()) entity.ContractDefault = true; var otherVariations = others.Where(x=>x.VariationDefault); if (entity.VariationDefault) { foreach (var otherVariation in otherVariations) otherVariation.VariationDefault = false; } else if (!otherVariations.Any()) entity.VariationDefault = true; var otherAdjustments = others.Where(x=>x.AdjustmentDefault); if (entity.AdjustmentDefault) { foreach (var otherAdjustment in otherAdjustments) otherAdjustment.AdjustmentDefault = false; } else if (!otherAdjustments.Any()) entity.AdjustmentDefault = true; Provider.Save(others.Where(x=>x.IsChanged())); } }