SiteDataModel.cs 4.2 KB

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