TaxCodeStore.cs 754 B

12345678910111213141516171819202122232425262728
  1. using Comal.Classes;
  2. using InABox.Core;
  3. namespace Comal.Stores;
  4. internal class TaxCodeStore : BaseStore<TaxCode>
  5. {
  6. protected override void BeforeSave(TaxCode entity)
  7. {
  8. base.BeforeSave(entity);
  9. var otherrows = Provider.Query(new Filter<TaxCode>(x => x.Default).IsEqualTo(true));
  10. if (entity.Default)
  11. {
  12. if (otherrows.Rows.Any())
  13. {
  14. var others = otherrows.Rows.Select(x => x.ToObject<TaxCode>()).ToArray();
  15. foreach (var other in others)
  16. other.Default = false;
  17. Provider.Save(others);
  18. }
  19. }
  20. else
  21. {
  22. if (!otherrows.Rows.Any())
  23. entity.Default = true;
  24. }
  25. }
  26. }