AppendixDataModel.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. namespace GreenTree.Nachtragsmanagement.Web.Models.Appendix
  6. {
  7. public class AppendixDataModel : IRequireStateDataModel
  8. {
  9. public int Id { get; set; }
  10. public string CustomNumber { get; set; }
  11. public string Description { get; set; }
  12. public decimal? Probability { get; set; }
  13. public int? OfferingNumber { get; set; }
  14. public DateTime? OfferingDate { get; set; }
  15. public decimal? OfferingValue { get; set; }
  16. public DateTime? NegotiationDate { get; set; }
  17. public decimal? NegotiationValue { get; set; }
  18. public bool ProtocolExists { get; set; }
  19. public int? OrderNumber { get; set; }
  20. public DateTime? OrderDate { get; set; }
  21. public bool OrderInvoiceCreated { get; set; }
  22. public string Comment { get; set; }
  23. public int? StateId { get; set; }
  24. public string StateDescription { get; set; }
  25. public int? SiteId { get; set; }
  26. public string SiteDescription { get; set; }
  27. public ICollection<int> DeviationValues { get; set; }
  28. public ICollection<string> DeviationDescriptions { get; set; }
  29. public string DeviationDescription { get; set; }
  30. public ICollection<string> CategoryEntities { get; set; }
  31. public ICollection<CategoryValueDataModel> CategoryValueEntities { get; set; }
  32. public string CategoryValuesDescription
  33. {
  34. get
  35. {
  36. if (CategoryValueEntities == null)
  37. return String.Empty;
  38. else
  39. return String.Join(", ", CategoryValueEntities.Select(d => d.Description));
  40. }
  41. }
  42. public AppendixDataModel()
  43. {
  44. DeviationValues = new List<int>();
  45. DeviationDescriptions = new List<string>();
  46. CategoryEntities = new List<string>();
  47. CategoryValueEntities = new List<CategoryValueDataModel>();
  48. }
  49. public static AppendixDataModel FromAppendix(Core.Domain.Appendix.Appendix appendixEntity, bool newWhenIsNull)
  50. {
  51. if (appendixEntity == null && newWhenIsNull)
  52. return new AppendixDataModel
  53. {
  54. Id = -1
  55. };
  56. if (appendixEntity == null && !newWhenIsNull)
  57. throw new ArgumentNullException("appendixEntity", "Cannot create AppendixDataModel from NULL appendix entity.");
  58. return new AppendixDataModel
  59. {
  60. Id = appendixEntity.Id,
  61. CustomNumber = appendixEntity.CustomNumber,
  62. Description = appendixEntity.Description,
  63. Probability = appendixEntity.Probability,
  64. OfferingNumber = appendixEntity.OfferingNumber,
  65. OfferingDate = appendixEntity.OfferingDate,
  66. OfferingValue = appendixEntity.Value,
  67. NegotiationDate = appendixEntity.NegotiationDate,
  68. NegotiationValue = appendixEntity.NegotiationValue,
  69. ProtocolExists = appendixEntity.ProtocolExists,
  70. OrderNumber = appendixEntity.OrderNumber,
  71. OrderDate = appendixEntity.OrderDate,
  72. Comment = appendixEntity.Comment,
  73. OrderInvoiceCreated = appendixEntity.OrderInvoiceCreated,
  74. StateId = appendixEntity.StateId,
  75. StateDescription = appendixEntity.State == null
  76. ? null
  77. : appendixEntity.State.Description,
  78. SiteId = appendixEntity.SiteId,
  79. SiteDescription = appendixEntity.Site == null
  80. ? null
  81. : appendixEntity.Site.Description,
  82. CategoryValueEntities =
  83. appendixEntity.CategoryValues
  84. .Select(r =>
  85. new CategoryValueDataModel
  86. {
  87. CategoryId = r.CategoryId,
  88. Description = String.Format("{0} - {1:c2}", r.Category.Description, r.Value),
  89. Value = r.Value
  90. })
  91. .ToList(),
  92. DeviationValues =
  93. appendixEntity.Deviations
  94. .Select(r => r.Id)
  95. .ToList(),
  96. DeviationDescriptions =
  97. appendixEntity.Deviations
  98. .Select(r => r.CustomNumber)
  99. .ToList(),
  100. DeviationDescription =
  101. String.Join(", ",
  102. appendixEntity.Deviations
  103. .Select(d => d.CustomNumber))
  104. };
  105. }
  106. public Core.Domain.Appendix.Appendix ToAppendix()
  107. {
  108. return new Core.Domain.Appendix.Appendix
  109. {
  110. Id = this.Id,
  111. CustomNumber = this.CustomNumber,
  112. Description = this.Description,
  113. Probability = this.Probability,
  114. OfferingNumber = this.OfferingNumber,
  115. OfferingDate = this.OfferingDate,
  116. NegotiationDate = this.NegotiationDate,
  117. NegotiationValue = this.NegotiationValue,
  118. ProtocolExists = this.ProtocolExists,
  119. OrderNumber = this.OrderNumber,
  120. OrderDate = this.OrderDate,
  121. Comment = this.Comment,
  122. SiteId = this.SiteId
  123. };
  124. }
  125. }
  126. }