RoleDataModel.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 bool SeeOnlyAssigned { get; set; }
  13. public ICollection<int> FunctionValues { get; set; }
  14. public ICollection<string> FunctionDescriptions { get; set; }
  15. public string FunctionDescription
  16. {
  17. get
  18. {
  19. if (FunctionDescriptions == null)
  20. return String.Empty;
  21. else
  22. return String.Join(", ", FunctionDescriptions);
  23. }
  24. }
  25. public RoleDataModel()
  26. {
  27. FunctionValues = new List<int>();
  28. FunctionDescriptions = new List<string>();
  29. }
  30. public static RoleDataModel FromRole(Core.Domain.User.Role roleEntity, bool newWhenIsNull)
  31. {
  32. if (roleEntity == null && newWhenIsNull)
  33. return new RoleDataModel
  34. {
  35. Id = -1
  36. };
  37. if (roleEntity == null && !newWhenIsNull)
  38. throw new ArgumentNullException("roleEntity", "Cannot create RoleDataModel from NULL role entity.");
  39. return new RoleDataModel
  40. {
  41. Id = roleEntity.Id,
  42. Description = roleEntity.Description,
  43. Level = roleEntity.Level,
  44. SeeOnlyAssigned = roleEntity.SeeOnlyAssigned,
  45. FunctionValues =
  46. roleEntity.Functions
  47. .Select(r => r.Id)
  48. .ToList(),
  49. FunctionDescriptions =
  50. roleEntity.Functions
  51. .Select(r => r.Description)
  52. .ToList()
  53. };
  54. }
  55. public Core.Domain.User.Role ToRole()
  56. {
  57. return new Core.Domain.User.Role
  58. {
  59. Id = this.Id,
  60. Description = this.Description,
  61. Level = this.Level
  62. };
  63. }
  64. }
  65. }