RoleDataModel.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. namespace GreenTree.Nachtragsmanagement.Web.Models.Admin.User
  6. {
  7. public class RoleDataModel
  8. {
  9. public int Id { get; set; }
  10. public string Description { get; set; }
  11. public int Level { get; set; }
  12. public ICollection<int> FunctionValues { get; set; }
  13. public ICollection<string> FunctionDescriptions { get; set; }
  14. public string FunctionDescription
  15. {
  16. get
  17. {
  18. if (FunctionDescriptions == null)
  19. return String.Empty;
  20. else
  21. return String.Join(", ", FunctionDescriptions);
  22. }
  23. }
  24. public RoleDataModel()
  25. {
  26. FunctionValues = new List<int>();
  27. FunctionDescriptions = new List<string>();
  28. }
  29. public static RoleDataModel FromRole(Core.Domain.User.Role roleEntity, bool newWhenIsNull)
  30. {
  31. if (roleEntity == null && newWhenIsNull)
  32. return new RoleDataModel
  33. {
  34. Id = -1
  35. };
  36. if (roleEntity == null && !newWhenIsNull)
  37. throw new ArgumentNullException("roleEntity", "Cannot create RoleDataModel from NULL role entity.");
  38. return new RoleDataModel
  39. {
  40. Id = roleEntity.Id,
  41. Description = roleEntity.Description,
  42. Level = roleEntity.Level,
  43. FunctionValues =
  44. roleEntity.Functions
  45. .Select(r => r.Id)
  46. .ToList(),
  47. FunctionDescriptions =
  48. roleEntity.Functions
  49. .Select(r => r.Description)
  50. .ToList()
  51. };
  52. }
  53. public Core.Domain.User.Role ToRole()
  54. {
  55. return new Core.Domain.User.Role
  56. {
  57. Id = this.Id,
  58. Description = this.Description,
  59. Level = this.Level
  60. };
  61. }
  62. }
  63. }