| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using GreenTree.Nachtragsmanagement.Services.Configuration;
- using GreenTree.Nachtragsmanagement.Web.Extensions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace GreenTree.Nachtragsmanagement.Web.Models.Config
- {
- public class ConfigItemDataModel
- {
- public static Dictionary<string, string> FullTypeTranslations = new Dictionary<string, string>
- {
- { 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" },
- { typeof(System.Drawing.Color).FullName, "Farbe" },
- };
- 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 bool IsValueCollection { get; set; }
- public string[] Values { 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.");
- var configItemModel = new ConfigItemDataModel
- {
- Id = configItemEntity.Id,
- Name = configItemEntity.Name,
- TypeFullName = configItemEntity.TypeFullName,
- Description = configItemEntity.Description
- };
- if (FullTypeTranslations.ContainsKey(configItemEntity.TypeFullName))
- {
- configItemModel.Value = configItemEntity.Value;
- configItemModel.TypeDescription = FullTypeTranslations[configItemEntity.TypeFullName];
- configItemModel.IsValueCollection = false;
- }
- else
- {
- var configurationReference = ConfigurationHelper.GetConfigurationReferenceByName(configItemEntity.TypeFullName);
- if (configurationReference != null)
- {
- configItemModel.TypeDescription = configurationReference.DisplayName;
- configItemModel.IsValueCollection = configurationReference.IsMultipleSelection;
- configItemModel.Value = configItemEntity.Value;
- if (configurationReference.IsMultipleSelection)
- configItemModel.Values = configurationReference.TransformValueToValueCollection(configItemEntity.Value);
- }
- else
- {
- configItemModel.TypeDescription = "Unbekannt";
- }
- }
- return configItemModel;
- }
- public Core.Domain.Config.ConfigItem ToConfigItem()
- {
- var configItem = new Core.Domain.Config.ConfigItem
- {
- Id = this.Id,
- Name = this.Name,
- TypeFullName = this.TypeFullName,
- Description = this.Description
- };
- if (FullTypeTranslations.ContainsKey(this.TypeFullName))
- {
- configItem.Value = this.Value;
- }
- else
- {
- var configurationReference = ConfigurationHelper.GetConfigurationReferenceByName(this.TypeFullName);
- if (configurationReference != null)
- {
- if (configurationReference.IsMultipleSelection)
- configItem.Value = configurationReference.TransformValueCollectionToValue(this.Values);
- else
- configItem.Value = this.Value;
- }
- }
- return configItem;
- }
- }
- }
|