SiteTreeDataModel.cs 7.0 KB

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