AppendixDataModel.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Lot { 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. Lot = appendixEntity.Lot,
  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.Categories
  56. .Select(r => r.Id)
  57. .ToList(),
  58. CategoryDescriptions =
  59. appendixEntity.Categories
  60. .Select(r => r.Description)
  61. .ToList(),
  62. DeviationValues =
  63. appendixEntity.Deviations
  64. .Select(r => r.Id)
  65. .ToList(),
  66. DeviationDescriptions =
  67. appendixEntity.Deviations
  68. .Select(r => r.CustomNumber)
  69. .ToList()
  70. };
  71. }
  72. public Core.Domain.Appendix.Appendix ToAppendix()
  73. {
  74. return new Core.Domain.Appendix.Appendix
  75. {
  76. Id = this.Id,
  77. CustomNumber = this.CustomNumber,
  78. Lot = this.Lot,
  79. Probability = this.Probability,
  80. OfferingNumber = this.OfferingNumber,
  81. OfferingDate = this.OfferingDate,
  82. NegotiationDate = this.NegotiationDate,
  83. NegotiationValue = this.NegotiationValue,
  84. ProtocolExists = this.ProtocolExists,
  85. OrderNumber = this.OrderNumber,
  86. OrderDate = this.OrderDate,
  87. Comment = this.Comment,
  88. SiteId = this.SiteId
  89. };
  90. }
  91. }
  92. }