ConfigItemDataModel.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. { typeof(System.Drawing.Color).FullName, "Farbe" },
  18. };
  19. public int Id { get; set; }
  20. public string Name { get; set; }
  21. public string TypeFullName { get; set; }
  22. public string TypeDescription { get; set; }
  23. public string Value { get; set; }
  24. public string Description { get; set; }
  25. public static ConfigItemDataModel FromConfigItem(Core.Domain.Config.ConfigItem configItemEntity, bool newWhenIsNull)
  26. {
  27. if (configItemEntity == null && newWhenIsNull)
  28. return new ConfigItemDataModel
  29. {
  30. Id = -1
  31. };
  32. if (configItemEntity == null && !newWhenIsNull)
  33. throw new ArgumentNullException("configItemEntity", "Cannot create ConfigItemDataModel from NULL configItem entity.");
  34. return new ConfigItemDataModel
  35. {
  36. Id = configItemEntity.Id,
  37. Name = configItemEntity.Name,
  38. TypeFullName = configItemEntity.TypeFullName,
  39. TypeDescription = FullTypeTranslations[configItemEntity.TypeFullName],
  40. Value = configItemEntity.Value,
  41. Description = configItemEntity.Description
  42. };
  43. }
  44. public Core.Domain.Config.ConfigItem ToConfigItem()
  45. {
  46. return new Core.Domain.Config.ConfigItem
  47. {
  48. Id = this.Id,
  49. Name = this.Name,
  50. TypeFullName = this.TypeFullName,
  51. Value = this.Value,
  52. Description = this.Description
  53. };
  54. }
  55. }
  56. }