RoleDataModel.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 RoleDataModel()
  15. {
  16. FunctionValues = new List<int>();
  17. FunctionDescriptions = new List<string>();
  18. }
  19. public static RoleDataModel FromRole(Core.Domain.User.Role roleEntity, bool newWhenIsNull)
  20. {
  21. if (roleEntity == null && newWhenIsNull)
  22. return new RoleDataModel
  23. {
  24. Id = -1
  25. };
  26. if (roleEntity == null && !newWhenIsNull)
  27. throw new ArgumentNullException("roleEntity", "Cannot create RoleDataModel from NULL role entity.");
  28. return new RoleDataModel
  29. {
  30. Id = roleEntity.Id,
  31. Description = roleEntity.Description,
  32. Level = roleEntity.Level,
  33. FunctionValues =
  34. roleEntity.Functions
  35. .Select(r => r.Id)
  36. .ToList(),
  37. FunctionDescriptions =
  38. roleEntity.Functions
  39. .Select(r => r.Description)
  40. .ToList()
  41. };
  42. }
  43. public Core.Domain.User.Role ToRole()
  44. {
  45. return new Core.Domain.User.Role
  46. {
  47. Id = this.Id,
  48. Description = this.Description,
  49. Level = this.Level
  50. };
  51. }
  52. }
  53. }