GroupTokenPage.xaml.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using InABox.Clients;
  7. using InABox.Core;
  8. using InABox.DynamicGrid;
  9. namespace PRSDesktop
  10. {
  11. /// <summary>
  12. /// Interaction logic for SecurityTokenPanel.xaml
  13. /// </summary>
  14. public partial class GroupTokenPage : UserControl, IDynamicCustomEditorPage<SecurityGroup>
  15. {
  16. public GroupTokenPage()
  17. {
  18. InitializeComponent();
  19. }
  20. public bool Ready { get; set; }
  21. public PageType PageType => PageType.Other;
  22. public DynamicEditorGrid EditorGrid { get; set; }
  23. public void AfterSave(object item)
  24. {
  25. var updates = new List<SecurityToken>();
  26. var deletes = new List<SecurityToken>();
  27. foreach (var token in grid.Tokens)
  28. {
  29. var gti = grid.Items.FirstOrDefault(x => x.Code.Equals(token.Descriptor));
  30. if (gti != null)
  31. {
  32. if (gti.HasValue)
  33. {
  34. if (token.IsChanged())
  35. updates.Add(token);
  36. }
  37. else
  38. {
  39. if (token.ID != Guid.Empty)
  40. deletes.Add(token);
  41. }
  42. }
  43. }
  44. if (updates.Any())
  45. new Client<SecurityToken>().Save(updates, "");
  46. foreach (var delete in deletes)
  47. new Client<SecurityToken>().Delete(delete, "");
  48. }
  49. public void BeforeSave(object item)
  50. {
  51. }
  52. public string Caption()
  53. {
  54. return "Security Tokens";
  55. }
  56. public void Load(object item, Func<Type, CoreTable> PageDataHandler)
  57. {
  58. var group = item as SecurityGroup;
  59. grid.GroupID = group.ID;
  60. grid.Refresh(true, true);
  61. Ready = true;
  62. }
  63. public Size MinimumSize()
  64. {
  65. return new Size(300, 600);
  66. }
  67. public int Order()
  68. {
  69. return 0;
  70. }
  71. }
  72. }