SiteTreeDataModel.cs 6.3 KB

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