using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace GreenTree.Nachtragsmanagement.Web.Models.Config { public class ConfigItemDataModel { public static Dictionary FullTypeTranslations = new Dictionary { { typeof(System.String).FullName, "Text" }, { typeof(System.Int32).FullName, "Ganze Zahl" }, { typeof(System.Int64).FullName, "Große ganze Zahl" }, { typeof(System.Boolean).FullName, "Wahrheitswert" }, { typeof(System.Double).FullName, "Kommazahl" }, { typeof(System.DateTime).FullName, "Datum" } }; public int Id { get; set; } public string Name { get; set; } public string TypeFullName { get; set; } public string TypeDescription { get; set; } public string Value { get; set; } public string Description { get; set; } public static ConfigItemDataModel FromConfigItem(Core.Domain.Config.ConfigItem configItemEntity, bool newWhenIsNull) { if (configItemEntity == null && newWhenIsNull) return new ConfigItemDataModel { Id = -1 }; if (configItemEntity == null && !newWhenIsNull) throw new ArgumentNullException("configItemEntity", "Cannot create ConfigItemDataModel from NULL configItem entity."); return new ConfigItemDataModel { Id = configItemEntity.Id, Name = configItemEntity.Name, TypeFullName = configItemEntity.TypeFullName, TypeDescription = FullTypeTranslations[configItemEntity.TypeFullName], Value = configItemEntity.Value, Description = configItemEntity.Description }; } public Core.Domain.Config.ConfigItem ToConfigItem() { return new Core.Domain.Config.ConfigItem { Id = this.Id, Name = this.Name, TypeFullName = this.TypeFullName, Value = this.Value, Description = this.Description }; } } }