DeviationDataModel.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. namespace GreenTree.Nachtragsmanagement.Web.Models.Deviation
  6. {
  7. public class DeviationDataModel
  8. {
  9. public int Id { get; set; }
  10. public string CustomNumber { get; set; }
  11. public DateTime ReceiptDate { get; set; }
  12. public decimal Value { get; set; }
  13. public int StatusId { get; set; }
  14. public string StatusDescription { get; set; }
  15. public int DisturbanceId { get; set; }
  16. public string DisturbanceDescription { get; set; }
  17. public int KindId { get; set; }
  18. public string KindDescription { get; set; }
  19. public string Comment { get; set; }
  20. public string AppendixDescription { get; set; }
  21. public int? AppendixId { get; set; }
  22. public static DeviationDataModel FromDeviation(Core.Domain.Deviation.Deviation deviationEntity, bool newWhenIsNull)
  23. {
  24. if (deviationEntity == null && newWhenIsNull)
  25. return new DeviationDataModel
  26. {
  27. Id = -1
  28. };
  29. if (deviationEntity == null && !newWhenIsNull)
  30. throw new ArgumentNullException("deviationEntity", "Cannot create DeviationDataModel from NULL deviation entity.");
  31. return new DeviationDataModel
  32. {
  33. Id = deviationEntity.Id,
  34. CustomNumber = deviationEntity.CustomNumber,
  35. ReceiptDate = deviationEntity.ReceiptDate,
  36. Value = deviationEntity.Value.Value,
  37. AppendixId = deviationEntity.AppendixId,
  38. AppendixDescription = deviationEntity.Appendix == null
  39. ? null
  40. : deviationEntity.Appendix.CustomNumber,
  41. StatusId = deviationEntity.StatusId.Value,
  42. StatusDescription = deviationEntity.Status == null
  43. ? null
  44. : deviationEntity.Status.Description,
  45. DisturbanceId = deviationEntity.DisturbanceId.Value,
  46. DisturbanceDescription = deviationEntity.Disturbance == null
  47. ? null
  48. : deviationEntity.Disturbance.Description,
  49. KindId = deviationEntity.KindId.Value,
  50. KindDescription = deviationEntity.Kind == null
  51. ? null
  52. : deviationEntity.Kind.Description,
  53. Comment = deviationEntity.Comment
  54. };
  55. }
  56. public Core.Domain.Deviation.Deviation ToDeviation()
  57. {
  58. return new Core.Domain.Deviation.Deviation
  59. {
  60. Id = this.Id,
  61. CustomNumber = this.CustomNumber,
  62. ReceiptDate = this.ReceiptDate,
  63. Value = this.Value,
  64. AppendixId = this.AppendixId,
  65. StatusId = this.StatusId,
  66. DisturbanceId = this.DisturbanceId,
  67. KindId = this.KindId,
  68. Comment = this.Comment
  69. };
  70. }
  71. }
  72. }