ConfigItemDataModel.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. namespace GreenTree.Nachtragsmanagement.Web.Models.Config
  6. {
  7. public class ConfigItemDataModel
  8. {
  9. public static Dictionary<string, string> FullTypeTranslations = new Dictionary<string, string>
  10. {
  11. { typeof(System.String).FullName, "Text" },
  12. { typeof(System.Int32).FullName, "Ganze Zahl" },
  13. { typeof(System.Int64).FullName, "Große ganze Zahl" },
  14. { typeof(System.Boolean).FullName, "Wahrheitswert" },
  15. { typeof(System.Double).FullName, "Kommazahl" },
  16. { typeof(System.DateTime).FullName, "Datum" }
  17. };
  18. public int Id { get; set; }
  19. public string Name { get; set; }
  20. public string TypeFullName { get; set; }
  21. public string TypeDescription { get; set; }
  22. public string Value { get; set; }
  23. public string Description { get; set; }
  24. public static ConfigItemDataModel FromConfigItem(Core.Domain.Config.ConfigItem configItemEntity, bool newWhenIsNull)
  25. {
  26. if (configItemEntity == null && newWhenIsNull)
  27. return new ConfigItemDataModel
  28. {
  29. Id = -1
  30. };
  31. if (configItemEntity == null && !newWhenIsNull)
  32. throw new ArgumentNullException("configItemEntity", "Cannot create ConfigItemDataModel from NULL configItem entity.");
  33. return new ConfigItemDataModel
  34. {
  35. Id = configItemEntity.Id,
  36. Name = configItemEntity.Name,
  37. TypeFullName = configItemEntity.TypeFullName,
  38. TypeDescription = FullTypeTranslations[configItemEntity.TypeFullName],
  39. Value = configItemEntity.Value,
  40. Description = configItemEntity.Description
  41. };
  42. }
  43. public Core.Domain.Config.ConfigItem ToConfigItem()
  44. {
  45. return new Core.Domain.Config.ConfigItem
  46. {
  47. Id = this.Id,
  48. Name = this.Name,
  49. TypeFullName = this.TypeFullName,
  50. Value = this.Value,
  51. Description = this.Description
  52. };
  53. }
  54. }
  55. }