RoleDataModel.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 string UserDescription { get; set; }
  26. public RoleDataModel()
  27. {
  28. FunctionValues = new List<int>();
  29. FunctionDescriptions = new List<string>();
  30. }
  31. public static RoleDataModel FromRole(Core.Domain.User.Role roleEntity, bool newWhenIsNull)
  32. {
  33. if (roleEntity == null && newWhenIsNull)
  34. return new RoleDataModel
  35. {
  36. Id = -1
  37. };
  38. if (roleEntity == null && !newWhenIsNull)
  39. throw new ArgumentNullException("roleEntity", "Cannot create RoleDataModel from NULL role entity.");
  40. return new RoleDataModel
  41. {
  42. Id = roleEntity.Id,
  43. Description = roleEntity.Description,
  44. Level = roleEntity.Level,
  45. SeeOnlyAssigned = roleEntity.SeeOnlyAssigned,
  46. FunctionValues =
  47. roleEntity.Functions
  48. .Select(r => r.Id)
  49. .ToList(),
  50. FunctionDescriptions =
  51. roleEntity.Functions
  52. .Select(r => r.Description)
  53. .ToList(),
  54. UserDescription =
  55. String.Join(", ",
  56. roleEntity.Users
  57. .Select(u => u.Lastname))
  58. };
  59. }
  60. public Core.Domain.User.Role ToRole()
  61. {
  62. return new Core.Domain.User.Role
  63. {
  64. Id = this.Id,
  65. Description = this.Description,
  66. Level = this.Level
  67. };
  68. }
  69. }
  70. }