ConfigItemDataModel.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. TypeFullName = configItemEntity.TypeFullName,
  37. TypeDescription = FullTypeTranslations[configItemEntity.TypeFullName],
  38. Value = configItemEntity.Value,
  39. Description = configItemEntity.Description
  40. };
  41. }
  42. public Core.Domain.Config.ConfigItem ToConfigItem()
  43. {
  44. return new Core.Domain.Config.ConfigItem
  45. {
  46. Id = this.Id,
  47. TypeFullName = this.TypeFullName,
  48. Value = this.Value,
  49. Description = this.Description
  50. };
  51. }
  52. }
  53. }