SiteTreeDataModel.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. .OrderBy(d => d.CustomNumber);
  46. var emptyAppendix = new SiteTreeDataModel
  47. {
  48. Id = 0,
  49. TreeKey = "a_0",
  50. TreeParentKey = String.Empty,
  51. CustomNumber = "Offene VA",
  52. Description = openDeviations.Count() > 0
  53. ? String.Format("{0} offene VAs", openDeviations.Count())
  54. : "Keine offenen VAs"
  55. };
  56. result.Add(emptyAppendix);
  57. foreach (var openDeviation in openDeviations)
  58. {
  59. result.Add(new SiteTreeDataModel
  60. {
  61. Id = openDeviation.Id,
  62. TreeKey = String.Format("d_{0}", openDeviation.Id),
  63. TreeParentKey = emptyAppendix.TreeKey,
  64. CustomNumber = openDeviation.CustomNumber,
  65. Description = openDeviation.Description,
  66. ReceiptDate = openDeviation.ReceiptDate,
  67. DistCatValues =
  68. openDeviation.DisturbanceValues
  69. .Select(d => d.Id)
  70. .ToList(),
  71. DistCatDescriptions =
  72. openDeviation.DisturbanceValues
  73. .Select(r => r.Disturbance == null
  74. ? String.Empty
  75. : r.Disturbance.Description)
  76. .ToList(),
  77. KindDescription = openDeviation.Kind == null
  78. ? String.Empty
  79. : openDeviation.Kind.Description,
  80. StatusId = openDeviation.StatusId,
  81. StatusDescription = openDeviation.Status == null
  82. ? String.Empty
  83. : openDeviation.Status.Description,
  84. Value = openDeviation.Value.Value * openDeviation.Percentage.Value,
  85. Comment = openDeviation.Comment
  86. });
  87. }
  88. var orderedAppendices = siteEntity
  89. .Appendices
  90. .OrderBy(a =>
  91. a.CustomNumber.Any(c => Char.IsLetter(c))
  92. ? 0
  93. : Convert.ToInt32(a.CustomNumber));
  94. foreach (var appendix in orderedAppendices)
  95. {
  96. var parentAppendix = new SiteTreeDataModel
  97. {
  98. Id = appendix.Id,
  99. TreeKey = String.Format("a_{0}", appendix.Id),
  100. TreeParentKey = String.Empty,
  101. CustomNumber = appendix.CustomNumber,
  102. Description = appendix.Description,
  103. ReceiptDate = appendix.OfferingDate,
  104. DistCatValues =
  105. appendix.CategoryValues
  106. .Select(d => d.Id)
  107. .ToList(),
  108. DistCatDescriptions =
  109. appendix.CategoryValues
  110. .Select(r => r.Category == null
  111. ? String.Empty
  112. : r.Category.Description)
  113. .ToList(),
  114. StatusId = appendix.StateId,
  115. StatusDescription = appendix.State == null
  116. ? String.Empty
  117. : appendix.State.Description,
  118. StatusColor = appendix.State == null
  119. ? "#FFFFFF"
  120. : appendix.State.HexColor,
  121. Value = appendix.NegotiationValue,
  122. Comment = appendix.Comment
  123. };
  124. result.Add(parentAppendix);
  125. foreach (var deviation in appendix.Deviations)
  126. {
  127. var childDeviation = new SiteTreeDataModel
  128. {
  129. Id = deviation.Id,
  130. TreeKey = String.Format("d_{0}", deviation.Id),
  131. TreeParentKey = parentAppendix.TreeKey,
  132. CustomNumber = deviation.CustomNumber,
  133. Description = deviation.Description,
  134. ReceiptDate = deviation.ReceiptDate,
  135. DistCatValues =
  136. deviation.DisturbanceValues
  137. .Select(d => d.Id)
  138. .ToList(),
  139. DistCatDescriptions =
  140. deviation.DisturbanceValues
  141. .Select(r => r.Disturbance == null
  142. ? String.Empty
  143. : r.Disturbance.Description)
  144. .ToList(),
  145. KindDescription = deviation.Kind == null
  146. ? String.Empty
  147. : deviation.Kind.Description,
  148. StatusId = deviation.StatusId,
  149. StatusDescription = deviation.Status == null
  150. ? String.Empty
  151. : deviation.Status.Description,
  152. Value = deviation.Value.Value * deviation.Percentage.Value,
  153. Comment = deviation.Comment
  154. };
  155. result.Add(childDeviation);
  156. }
  157. }
  158. return result;
  159. }
  160. }
  161. }