SiteTreeDataModel.cs 6.0 KB

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