SecurityGroupUserGrid.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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(FluentList<DynamicGridOption> options)
  14. {
  15. base.DoReconfigure(options);
  16. options.BeginUpdate()
  17. .Clear()
  18. .AddRange(DynamicGridOption.AddRows)
  19. .AddRange(DynamicGridOption.DeleteRows)
  20. .AddRange(DynamicGridOption.MultiSelect)
  21. .EndUpdate();
  22. }
  23. protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
  24. {
  25. var IDs = Items.Select(x => x.ID).ToArray();
  26. var filters = new Filters<User>();
  27. filters.Add(LookupFactory.DefineFilter<User>());
  28. filters.Add(new Filter<User>(x => x.ID).NotInList(IDs));
  29. var dlg = new MultiSelectDialog<User>(filters.Combine(), null, true);
  30. if (dlg.ShowDialog())
  31. {
  32. SaveItems(dlg.Items());
  33. Refresh(false, true);
  34. }
  35. }
  36. protected override void OnDeleteItem(User item)
  37. {
  38. item.SecurityGroup.ID = Guid.Empty;
  39. Client.Save(item, "Cleared security group");
  40. }
  41. }