SiteTreeDataModel.cs 6.1 KB

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