GroupTokenPage.xaml.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 DynamicEditorGrid EditorGrid { get; set; }
  22. public void AfterSave(object item)
  23. {
  24. var updates = new List<SecurityToken>();
  25. var deletes = new List<SecurityToken>();
  26. foreach (var token in grid.Tokens)
  27. {
  28. var gti = grid.Items.FirstOrDefault(x => x.Code.Equals(token.Descriptor));
  29. if (gti != null)
  30. {
  31. if (gti.HasValue)
  32. {
  33. if (token.IsChanged())
  34. updates.Add(token);
  35. }
  36. else
  37. {
  38. if (token.ID != Guid.Empty)
  39. deletes.Add(token);
  40. }
  41. }
  42. }
  43. if (updates.Any())
  44. new Client<SecurityToken>().Save(updates, "");
  45. foreach (var delete in deletes)
  46. new Client<SecurityToken>().Delete(delete, "");
  47. }
  48. public void BeforeSave(object item)
  49. {
  50. }
  51. public string Caption()
  52. {
  53. return "Security Tokens";
  54. }
  55. public void Load(object item, Func<Type, CoreTable> PageDataHandler)
  56. {
  57. var group = item as SecurityGroup;
  58. grid.GroupID = group.ID;
  59. grid.Refresh(true, true);
  60. Ready = true;
  61. }
  62. public Size MinimumSize()
  63. {
  64. return new Size(300, 600);
  65. }
  66. public int Order()
  67. {
  68. return 0;
  69. }
  70. }
  71. }