SecurityGroupUserGrid.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Comal.Classes;
  2. using InABox.Clients;
  3. using InABox.Core;
  4. using InABox.DynamicGrid;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace PRSDesktop;
  11. public class SecurityGroupUserGrid : DynamicOneToManyGrid<SecurityGroup, User>
  12. {
  13. protected override void DoReconfigure(DynamicGridOptions options)
  14. {
  15. base.DoReconfigure(options);
  16. options.Clear();
  17. options.AddRows = true;
  18. options.DeleteRows = true;
  19. options.MultiSelect = true;
  20. }
  21. protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
  22. {
  23. var IDs = ExtractValues(x => x.ID, Selection.All).ToArray();
  24. var filters = new Filters<User>();
  25. filters.Add(LookupFactory.DefineFilter<User>());
  26. filters.Add(new Filter<User>(x => x.ID).NotInList(IDs));
  27. var dlg = new MultiSelectDialog<User>(filters.Combine(), null, true);
  28. if (dlg.ShowDialog())
  29. {
  30. DataComponent.SaveItems(dlg.Items());
  31. Refresh(false, true);
  32. }
  33. }
  34. protected override void OnDeleteItem(User item)
  35. {
  36. item.SecurityGroup.ID = Guid.Empty;
  37. Client.Save(item, "Cleared security group");
  38. }
  39. }