JobStatusStore.cs 783 B

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