AppendixDataModel.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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
  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 DateTime? NegotiationDate { get; set; }
  16. public decimal? NegotiationValue { get; set; }
  17. public bool ProtocolExists { get; set; }
  18. public int? OrderNumber { get; set; }
  19. public DateTime? OrderDate { get; set; }
  20. public string Comment { get; set; }
  21. public int? SiteId { get; set; }
  22. public string SiteDescription { get; set; }
  23. public ICollection<int> CategoryValues { get; set; }
  24. public ICollection<string> CategoryDescriptions { get; set; }
  25. public ICollection<int> DeviationValues { get; set; }
  26. public ICollection<string> DeviationDescriptions { get; set; }
  27. public static AppendixDataModel FromAppendix(Core.Domain.Appendix.Appendix appendixEntity, bool newWhenIsNull)
  28. {
  29. if (appendixEntity == null && newWhenIsNull)
  30. return new AppendixDataModel
  31. {
  32. Id = -1
  33. };
  34. if (appendixEntity == null && !newWhenIsNull)
  35. throw new ArgumentNullException("appendixEntity", "Cannot create AppendixDataModel from NULL appendix entity.");
  36. return new AppendixDataModel
  37. {
  38. Id = appendixEntity.Id,
  39. CustomNumber = appendixEntity.CustomNumber,
  40. Description = appendixEntity.Description,
  41. Probability = appendixEntity.Probability,
  42. OfferingNumber = appendixEntity.OfferingNumber,
  43. OfferingDate = appendixEntity.OfferingDate,
  44. NegotiationDate = appendixEntity.NegotiationDate,
  45. NegotiationValue = appendixEntity.NegotiationValue,
  46. ProtocolExists = appendixEntity.ProtocolExists,
  47. OrderNumber = appendixEntity.OrderNumber,
  48. OrderDate = appendixEntity.OrderDate,
  49. Comment = appendixEntity.Comment,
  50. SiteId = appendixEntity.SiteId,
  51. SiteDescription = appendixEntity.Site == null
  52. ? null
  53. : appendixEntity.Site.Description,
  54. CategoryValues =
  55. appendixEntity.CategoryValues
  56. .Select(r => r.Id)
  57. .ToList(),
  58. CategoryDescriptions =
  59. appendixEntity.CategoryValues
  60. .Select(r => r.Category == null
  61. ? String.Empty
  62. : r.Category.Description)
  63. .ToList(),
  64. DeviationValues =
  65. appendixEntity.Deviations
  66. .Select(r => r.Id)
  67. .ToList(),
  68. DeviationDescriptions =
  69. appendixEntity.Deviations
  70. .Select(r => r.CustomNumber)
  71. .ToList()
  72. };
  73. }
  74. public Core.Domain.Appendix.Appendix ToAppendix()
  75. {
  76. return new Core.Domain.Appendix.Appendix
  77. {
  78. Id = this.Id,
  79. CustomNumber = this.CustomNumber,
  80. Description = this.Description,
  81. Probability = this.Probability,
  82. OfferingNumber = this.OfferingNumber,
  83. OfferingDate = this.OfferingDate,
  84. NegotiationDate = this.NegotiationDate,
  85. NegotiationValue = this.NegotiationValue,
  86. ProtocolExists = this.ProtocolExists,
  87. OrderNumber = this.OrderNumber,
  88. OrderDate = this.OrderDate,
  89. Comment = this.Comment,
  90. SiteId = this.SiteId
  91. };
  92. }
  93. }
  94. }