SiteTreeDataModel.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. namespace GreenTree.Nachtragsmanagement.Web.Models.Site
  6. {
  7. public class SiteTreeDataModel
  8. {
  9. public int Id { get; set; }
  10. public string TreeKey { get; set; }
  11. public string TreeParentKey { get; set; }
  12. public string CustomNumber { get; set; }
  13. public string Description { get; set; }
  14. public DateTime? ReceiptDate { get; set; }
  15. public decimal? Value { get; set; }
  16. public string KindDescription { get; set; }
  17. public int? StatusId { get; set; }
  18. public string StatusDescription { get; set; }
  19. public string StatusColor { get; set; }
  20. public ICollection<int> DistCatValues { get; set; }
  21. public ICollection<string> DistCatDescriptions { get; set; }
  22. public string DistCatDescription
  23. {
  24. get
  25. {
  26. if (DistCatDescriptions == null)
  27. return String.Empty;
  28. else
  29. return String.Join(", ", DistCatDescriptions);
  30. }
  31. }
  32. public string Comment { get; set; }
  33. public SiteTreeDataModel()
  34. {
  35. DistCatValues = new List<int>();
  36. DistCatDescriptions = new List<string>();
  37. }
  38. public static List<SiteTreeDataModel> TreeFromSite(Core.Domain.Site.Site siteEntity)
  39. {
  40. var result = new List<SiteTreeDataModel>();
  41. if (siteEntity == null)
  42. return result;
  43. var openDeviations = siteEntity.Deviations
  44. .Where(d => d.Appendix == null);
  45. var emptyAppendix = new SiteTreeDataModel
  46. {
  47. Id = 0,
  48. TreeKey = "a_0",
  49. TreeParentKey = String.Empty,
  50. CustomNumber = "Offene VA",
  51. Description = openDeviations.Count() > 0
  52. ? String.Format("{0} offene VAs", openDeviations.Count())
  53. : "Keine offenen VAs"
  54. };
  55. result.Add(emptyAppendix);
  56. foreach (var openDeviation in openDeviations)
  57. {
  58. result.Add(new SiteTreeDataModel
  59. {
  60. Id = openDeviation.Id,
  61. TreeKey = String.Format("d_{0}", openDeviation.Id),
  62. TreeParentKey = emptyAppendix.TreeKey,
  63. CustomNumber = openDeviation.CustomNumber,
  64. Description = openDeviation.Description,
  65. ReceiptDate = openDeviation.ReceiptDate,
  66. DistCatValues =
  67. openDeviation.DisturbanceValues
  68. .Select(d => d.Id)
  69. .ToList(),
  70. DistCatDescriptions =
  71. openDeviation.DisturbanceValues
  72. .Select(r => r.Disturbance == null
  73. ? String.Empty
  74. : r.Disturbance.Description)
  75. .ToList(),
  76. KindDescription = openDeviation.Kind == null
  77. ? String.Empty
  78. : openDeviation.Kind.Description,
  79. StatusId = openDeviation.StatusId,
  80. StatusDescription = openDeviation.Status == null
  81. ? String.Empty
  82. : openDeviation.Status.Description,
  83. Value = openDeviation.Value.Value * openDeviation.Percentage.Value,
  84. Comment = openDeviation.Comment
  85. });
  86. }
  87. foreach (var appendix in siteEntity.Appendices)
  88. {
  89. var parentAppendix = new SiteTreeDataModel
  90. {
  91. Id = appendix.Id,
  92. TreeKey = String.Format("a_{0}", appendix.Id),
  93. TreeParentKey = String.Empty,
  94. CustomNumber = appendix.CustomNumber,
  95. Description = appendix.Description,
  96. ReceiptDate = appendix.OfferingDate,
  97. DistCatValues =
  98. appendix.CategoryValues
  99. .Select(d => d.Id)
  100. .ToList(),
  101. DistCatDescriptions =
  102. appendix.CategoryValues
  103. .Select(r => r.Category == null
  104. ? String.Empty
  105. : r.Category.Description)
  106. .ToList(),
  107. StatusId = appendix.StateId,
  108. StatusDescription = appendix.State == null
  109. ? String.Empty
  110. : appendix.State.Description,
  111. StatusColor = appendix.State == null
  112. ? "#FFFFFF"
  113. : appendix.State.HexColor,
  114. Value = appendix.NegotiationValue,
  115. Comment = appendix.Comment
  116. };
  117. result.Add(parentAppendix);
  118. foreach (var deviation in appendix.Deviations)
  119. {
  120. var childDeviation = new SiteTreeDataModel
  121. {
  122. Id = deviation.Id,
  123. TreeKey = String.Format("d_{0}", deviation.Id),
  124. TreeParentKey = parentAppendix.TreeKey,
  125. CustomNumber = deviation.CustomNumber,
  126. Description = deviation.Description,
  127. ReceiptDate = deviation.ReceiptDate,
  128. DistCatValues =
  129. deviation.DisturbanceValues
  130. .Select(d => d.Id)
  131. .ToList(),
  132. DistCatDescriptions =
  133. deviation.DisturbanceValues
  134. .Select(r => r.Disturbance == null
  135. ? String.Empty
  136. : r.Disturbance.Description)
  137. .ToList(),
  138. KindDescription = deviation.Kind == null
  139. ? String.Empty
  140. : deviation.Kind.Description,
  141. StatusId = deviation.StatusId,
  142. StatusDescription = deviation.Status == null
  143. ? String.Empty
  144. : deviation.Status.Description,
  145. Value = deviation.Value.Value * deviation.Percentage.Value,
  146. Comment = deviation.Comment
  147. };
  148. result.Add(childDeviation);
  149. }
  150. }
  151. return result;
  152. }
  153. }
  154. }