CategoryDataModel.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 CategoryDataModel
  8. {
  9. public int Id { get; set; }
  10. public string Description { get; set; }
  11. public static CategoryDataModel FromCategory(Core.Domain.Appendix.Category categoryEntity, bool newWhenIsNull)
  12. {
  13. if (categoryEntity == null && newWhenIsNull)
  14. return new CategoryDataModel
  15. {
  16. Id = -1
  17. };
  18. if (categoryEntity == null && !newWhenIsNull)
  19. throw new ArgumentNullException("categoryEntity", "Cannot create CategoryDataModel from NULL category entity.");
  20. return new CategoryDataModel
  21. {
  22. Id = categoryEntity.Id,
  23. Description = categoryEntity.Description
  24. };
  25. }
  26. public Core.Domain.Appendix.Category ToCategory()
  27. {
  28. return new Core.Domain.Appendix.Category
  29. {
  30. Id = this.Id,
  31. Description = this.Description
  32. };
  33. }
  34. }
  35. }