InvoiceDataModel.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 InvoiceDataModel
  8. {
  9. public int Id { get; set; }
  10. public string CustomNumber { get; set; }
  11. public decimal? Value { get; set; }
  12. public DateTime? DateTime { get; set; }
  13. public int? AppendixId { get; set; }
  14. public static InvoiceDataModel FromInvoice(Core.Domain.Invoice.Invoice invoiceEntity, bool newWhenIsNull)
  15. {
  16. if (invoiceEntity == null && newWhenIsNull)
  17. return new InvoiceDataModel
  18. {
  19. Id = -1
  20. };
  21. if (invoiceEntity == null && !newWhenIsNull)
  22. throw new ArgumentNullException("invoiceEntity", "Cannot create InvoiceDataModel from NULL invoice entity.");
  23. return new InvoiceDataModel
  24. {
  25. Id = invoiceEntity.Id,
  26. AppendixId = invoiceEntity.AppendixId,
  27. CustomNumber = invoiceEntity.CustomNumber,
  28. DateTime = invoiceEntity.Date,
  29. Value = invoiceEntity.Value
  30. };
  31. }
  32. public Core.Domain.Invoice.Invoice ToInvoice()
  33. {
  34. return new Core.Domain.Invoice.Invoice
  35. {
  36. Id = this.Id,
  37. AppendixId = this.AppendixId.Value,
  38. CustomNumber = this.CustomNumber,
  39. Date = this.DateTime.Value,
  40. Value = this.Value.Value
  41. };
  42. }
  43. }
  44. }