SiteDataModel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using GreenTree.Nachtragsmanagement.Web.Models.Admin.User;
  2. using GreenTree.Nachtragsmanagement.Web.Models.Appendix;
  3. using GreenTree.Nachtragsmanagement.Web.Models.Deviation;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Web;
  8. namespace GreenTree.Nachtragsmanagement.Web.Models.Site
  9. {
  10. public class SiteDataModel
  11. {
  12. public int Id { get; set; }
  13. public string CustomNumber { get; set; }
  14. public string Description { get; set; }
  15. public DateTime? Start { get; set; }
  16. public DateTime? End { get; set; }
  17. public string Comment { get; set; }
  18. public ICollection<int> DeviationValues { get; set; }
  19. public ICollection<string> DeviationDescriptions { get; set; }
  20. public ICollection<DeviationDataModel> Deviations { get; set; }
  21. public string DeviationDescription
  22. {
  23. get
  24. {
  25. if (DeviationDescriptions == null)
  26. return String.Empty;
  27. else
  28. return String.Join(", ", DeviationDescriptions);
  29. }
  30. }
  31. public decimal? DeviationValue { get; set; }
  32. public ICollection<int> AppendixValues { get; set; }
  33. public ICollection<string> AppendixDescriptions { get; set; }
  34. public ICollection<AppendixDataModel> Appendices { get; set; }
  35. public string AppendixDescription
  36. {
  37. get
  38. {
  39. if (AppendixDescriptions == null)
  40. return String.Empty;
  41. else
  42. return String.Join(", ", AppendixDescriptions);
  43. }
  44. }
  45. public ICollection<int> UserValues { get; set; }
  46. public ICollection<string> UserDescriptions { get; set; }
  47. public ICollection<UserDataModel> Users { get; set; }
  48. public string UserDescription
  49. {
  50. get
  51. {
  52. if (UserDescriptions == null)
  53. return String.Empty;
  54. else
  55. return String.Join(", ", UserDescriptions);
  56. }
  57. }
  58. public ICollection<SiteTreeDataModel> SiteTreeData { get; set; }
  59. public SiteDataModel()
  60. {
  61. DeviationValues = new List<int>();
  62. DeviationDescriptions = new List<string>();
  63. AppendixValues = new List<int>();
  64. AppendixDescriptions = new List<string>();
  65. UserValues = new List<int>();
  66. UserDescriptions = new List<string>();
  67. }
  68. public static SiteDataModel FromSite(Core.Domain.Site.Site siteEntity, bool newWhenIsNull)
  69. {
  70. if (siteEntity == null && newWhenIsNull)
  71. return new SiteDataModel
  72. {
  73. Id = -1,
  74. };
  75. if (siteEntity == null && !newWhenIsNull)
  76. throw new ArgumentNullException("siteEntity", "Cannot create SiteDataModel from NULL site entity.");
  77. return new SiteDataModel
  78. {
  79. Id = siteEntity.Id,
  80. CustomNumber = siteEntity.CustomNumber,
  81. Description = siteEntity.Description,
  82. Start = siteEntity.Start,
  83. End = siteEntity.End,
  84. DeviationValues =
  85. siteEntity.Deviations
  86. .Select(r => r.Id)
  87. .ToList(),
  88. DeviationDescriptions =
  89. siteEntity.Deviations
  90. .Select(r => r.Description)
  91. .ToList(),
  92. Deviations =
  93. siteEntity.Deviations
  94. .Select(r => DeviationDataModel.FromDeviation(r, false))
  95. .ToList(),
  96. DeviationValue =
  97. siteEntity.Deviations
  98. .Sum(r => r.Value * ((decimal)r.Percentage.Value / (decimal)100)),
  99. AppendixValues =
  100. siteEntity.Appendices
  101. .Select(r => r.Id)
  102. .ToList(),
  103. AppendixDescriptions =
  104. siteEntity.Appendices
  105. .Select(r => r.CustomNumber)
  106. .ToList(),
  107. Appendices =
  108. siteEntity.Appendices
  109. .Select(r => AppendixDataModel.FromAppendix(r, false))
  110. .ToList(),
  111. UserValues =
  112. siteEntity.Appendices
  113. .Select(r => r.Id)
  114. .ToList(),
  115. UserDescriptions =
  116. siteEntity.Users
  117. .Select(r => r.Lastname)
  118. .ToList(),
  119. Users =
  120. siteEntity.Users
  121. .Select(r => UserDataModel.FromUser(r, false))
  122. .ToList(),
  123. };
  124. }
  125. public Core.Domain.Site.Site ToSite()
  126. {
  127. return new Core.Domain.Site.Site
  128. {
  129. Id = this.Id,
  130. CustomNumber = this.CustomNumber,
  131. Description = Description,
  132. Comment = this.Comment
  133. };
  134. }
  135. }
  136. }