RolePermissionMapper.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using OpenSEMI.ClientBase;
  4. namespace VirgoUI.Client.Models.Utility.RolePage
  5. {
  6. public class RolePermissionMapper
  7. {
  8. private RolePermissionMapper()
  9. {
  10. _DicPermission.Add(new PermissionType()
  11. { EnumPermission = MenuPermissionEnum.MP_NONE,
  12. StringPermission = "NONE"
  13. });
  14. _DicPermission.Add(new PermissionType()
  15. {
  16. EnumPermission = MenuPermissionEnum.MP_READ,
  17. StringPermission = "Read"
  18. });
  19. _DicPermission.Add(new PermissionType()
  20. {
  21. EnumPermission = MenuPermissionEnum.MP_READ_WRITE,
  22. StringPermission = "Read & Write"
  23. });
  24. }
  25. private static RolePermissionMapper _Instance = null;
  26. public static RolePermissionMapper Instance
  27. {
  28. get
  29. {
  30. if (_Instance == null)
  31. {
  32. _Instance = new RolePermissionMapper();
  33. }
  34. return _Instance;
  35. }
  36. }
  37. private ObservableCollection<PermissionType> _DicPermission = new ObservableCollection<PermissionType>();
  38. public ObservableCollection<PermissionType> PermissionDictionary
  39. {
  40. get { return _DicPermission; }
  41. }
  42. public int ToInt(MenuPermissionEnum enumPermistion)
  43. {
  44. return (int)enumPermistion;
  45. }
  46. public string ToString(MenuPermissionEnum enumPermistion)
  47. {
  48. foreach (PermissionType pd in _DicPermission)
  49. {
  50. if (pd.EnumPermission == enumPermistion)
  51. {
  52. return pd.StringPermission;
  53. }
  54. }
  55. return "";
  56. }
  57. }
  58. public class PermissionType
  59. {
  60. public MenuPermissionEnum EnumPermission{get;set;}
  61. public string StringPermission { get; set; }
  62. }
  63. }