SiteDataModel.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using GreenTree.Nachtragsmanagement.Web.Models.Admin.User;
  2. using GreenTree.Nachtragsmanagement.Web.Models.Appendix;
  3. using GreenTree.Nachtragsmanagement.Web.Models.Deviation;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Web;
  8. namespace GreenTree.Nachtragsmanagement.Web.Models.Site
  9. {
  10. public class SiteDataModel
  11. {
  12. public int Id { get; set; }
  13. public string CustomNumber { get; set; }
  14. public string Description { get; set; }
  15. public DateTime? Start { get; set; }
  16. public DateTime? End { get; set; }
  17. public string Comment { get; set; }
  18. public ICollection<int> DeviationValues { get; set; }
  19. public ICollection<string> DeviationDescriptions { get; set; }
  20. public ICollection<DeviationDataModel> Deviations { get; set; }
  21. public string DeviationDescription
  22. {
  23. get
  24. {
  25. if (DeviationDescriptions == null)
  26. return String.Empty;
  27. else
  28. return String.Join(", ", DeviationDescriptions);
  29. }
  30. }
  31. public decimal? DeviationValue { get; set; }
  32. public ICollection<int> AppendixValues { get; set; }
  33. public ICollection<string> AppendixDescriptions { get; set; }
  34. public ICollection<AppendixDataModel> Appendices { get; set; }
  35. public string AppendixDescription
  36. {
  37. get
  38. {
  39. if (AppendixDescriptions == null)
  40. return String.Empty;
  41. else
  42. return String.Join(", ", AppendixDescriptions);
  43. }
  44. }
  45. public ICollection<int> UserValues { get; set; }
  46. public ICollection<string> UserDescriptions { get; set; }
  47. public ICollection<UserDataModel> Users { get; set; }
  48. public string UserDescription
  49. {
  50. get
  51. {
  52. if (UserDescriptions == null)
  53. return String.Empty;
  54. else
  55. return String.Join(", ", UserDescriptions);
  56. }
  57. }
  58. public SiteDataModel()
  59. {
  60. DeviationValues = new List<int>();
  61. DeviationDescriptions = new List<string>();
  62. AppendixValues = new List<int>();
  63. AppendixDescriptions = new List<string>();
  64. UserValues = new List<int>();
  65. UserDescriptions = new List<string>();
  66. }
  67. public static SiteDataModel FromSite(Core.Domain.Site.Site siteEntity, bool newWhenIsNull)
  68. {
  69. if (siteEntity == null && newWhenIsNull)
  70. return new SiteDataModel
  71. {
  72. Id = -1,
  73. };
  74. if (siteEntity == null && !newWhenIsNull)
  75. throw new ArgumentNullException("siteEntity", "Cannot create SiteDataModel from NULL site entity.");
  76. return new SiteDataModel
  77. {
  78. Id = siteEntity.Id,
  79. CustomNumber = siteEntity.CustomNumber,
  80. Description = siteEntity.Description,
  81. Start = siteEntity.Start,
  82. End = siteEntity.End,
  83. DeviationValues =
  84. siteEntity.Deviations
  85. .Select(r => r.Id)
  86. .ToList(),
  87. DeviationDescriptions =
  88. siteEntity.Deviations
  89. .Select(r => r.Description)
  90. .ToList(),
  91. Deviations =
  92. siteEntity.Deviations
  93. .Select(r => DeviationDataModel.FromDeviation(r, false))
  94. .ToList(),
  95. DeviationValue =
  96. siteEntity.Deviations
  97. .Sum(r => r.Value * (r.Percentage.Value / 100)),
  98. AppendixValues =
  99. siteEntity.Appendices
  100. .Select(r => r.Id)
  101. .ToList(),
  102. AppendixDescriptions =
  103. siteEntity.Appendices
  104. .Select(r => r.CustomNumber)
  105. .ToList(),
  106. Appendices =
  107. siteEntity.Appendices
  108. .Select(r => AppendixDataModel.FromAppendix(r, false))
  109. .ToList(),
  110. UserValues =
  111. siteEntity.Appendices
  112. .Select(r => r.Id)
  113. .ToList(),
  114. UserDescriptions =
  115. siteEntity.Users
  116. .Select(r => r.Lastname)
  117. .ToList(),
  118. Users =
  119. siteEntity.Users
  120. .Select(r => UserDataModel.FromUser(r, false))
  121. .ToList(),
  122. };
  123. }
  124. public Core.Domain.Site.Site ToSite()
  125. {
  126. return new Core.Domain.Site.Site
  127. {
  128. Id = this.Id,
  129. CustomNumber = this.CustomNumber,
  130. Description = Description,
  131. Comment = this.Comment
  132. };
  133. }
  134. }
  135. }