SiteTreeDataModel.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. var orderedAppendices = siteEntity
  88. .Appendices
  89. .OrderBy(a =>
  90. a.CustomNumber.Any(c => Char.IsLetter(c))
  91. ? 0
  92. : Convert.ToInt32(a.CustomNumber));
  93. foreach (var appendix in orderedAppendices)
  94. {
  95. var parentAppendix = new SiteTreeDataModel
  96. {
  97. Id = appendix.Id,
  98. TreeKey = String.Format("a_{0}", appendix.Id),
  99. TreeParentKey = String.Empty,
  100. CustomNumber = appendix.CustomNumber,
  101. Description = appendix.Description,
  102. ReceiptDate = appendix.OfferingDate,
  103. DistCatValues =
  104. appendix.CategoryValues
  105. .Select(d => d.Id)
  106. .ToList(),
  107. DistCatDescriptions =
  108. appendix.CategoryValues
  109. .Select(r => r.Category == null
  110. ? String.Empty
  111. : r.Category.Description)
  112. .ToList(),
  113. StatusId = appendix.StateId,
  114. StatusDescription = appendix.State == null
  115. ? String.Empty
  116. : appendix.State.Description,
  117. StatusColor = appendix.State == null
  118. ? "#FFFFFF"
  119. : appendix.State.HexColor,
  120. Value = appendix.NegotiationValue,
  121. Comment = appendix.Comment
  122. };
  123. result.Add(parentAppendix);
  124. foreach (var deviation in appendix.Deviations)
  125. {
  126. var childDeviation = new SiteTreeDataModel
  127. {
  128. Id = deviation.Id,
  129. TreeKey = String.Format("d_{0}", deviation.Id),
  130. TreeParentKey = parentAppendix.TreeKey,
  131. CustomNumber = deviation.CustomNumber,
  132. Description = deviation.Description,
  133. ReceiptDate = deviation.ReceiptDate,
  134. DistCatValues =
  135. deviation.DisturbanceValues
  136. .Select(d => d.Id)
  137. .ToList(),
  138. DistCatDescriptions =
  139. deviation.DisturbanceValues
  140. .Select(r => r.Disturbance == null
  141. ? String.Empty
  142. : r.Disturbance.Description)
  143. .ToList(),
  144. KindDescription = deviation.Kind == null
  145. ? String.Empty
  146. : deviation.Kind.Description,
  147. StatusId = deviation.StatusId,
  148. StatusDescription = deviation.Status == null
  149. ? String.Empty
  150. : deviation.Status.Description,
  151. Value = deviation.Value.Value * deviation.Percentage.Value,
  152. Comment = deviation.Comment
  153. };
  154. result.Add(childDeviation);
  155. }
  156. }
  157. return result;
  158. }
  159. }
  160. }