namespace IStation.Service
|
{
|
public partial class LogicArea
|
{
|
//Entity to GetModel
|
private static Model.LogicArea Entity2Model(Entity.LogicArea entity)
|
{
|
if (entity == null)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.LogicArea, Model.LogicArea>()
|
.ForMember(d => d.Paras, opt => opt.MapFrom(src => ParasHelper.ToDictionary(src.Paras)))
|
.ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToList(src.Flags)))
|
).CreateMapper();
|
var model = mapper.Map<Entity.LogicArea, Model.LogicArea>(entity);
|
return model;
|
}
|
//Entities to GetModels
|
private static List<Model.LogicArea> Entity2Models(List<Entity.LogicArea> entities)
|
{
|
if (entities == null || entities.Count() < 1)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.LogicArea, Model.LogicArea>()
|
.ForMember(d => d.Paras, opt => opt.MapFrom(src => ParasHelper.ToDictionary(src.Paras)))
|
.ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToList(src.Flags)))
|
).CreateMapper();
|
var models = mapper.Map<List<Entity.LogicArea>, List<Model.LogicArea>>(entities);
|
return models;
|
}
|
|
//Model to Entity
|
private static Entity.LogicArea Model2Entity(Model.LogicArea model)
|
{
|
if (model == null)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.LogicArea, Entity.LogicArea>()
|
.ForMember(d => d.Paras, opt => opt.MapFrom(src => ParasHelper.ToString(src.Paras)))
|
.ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
|
).CreateMapper();
|
var entity = mapper.Map<Model.LogicArea, Entity.LogicArea>(model);
|
return entity;
|
}
|
|
//Models to Entities
|
private static List<Entity.LogicArea> Model2Entities(List<Model.LogicArea> models)
|
{
|
if (models == null || models.Count < 1)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.LogicArea, Entity.LogicArea>()
|
.ForMember(d => d.Paras, opt => opt.MapFrom(src => ParasHelper.ToString(src.Paras)))
|
.ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
|
).CreateMapper();
|
var entities = mapper.Map<List<Model.LogicArea>, List<Entity.LogicArea>>(models);
|
return entities;
|
}
|
|
//Model to Entity
|
private static void Model2Entity(Model.LogicArea model, Entity.LogicArea entity)
|
{
|
if (model == null || entity == null)
|
return;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.LogicArea, Entity.LogicArea>()
|
.ForMember(d => d.Paras, opt => opt.MapFrom(src => ParasHelper.ToString(src.Paras)))
|
.ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
|
).CreateMapper();
|
mapper.Map(model, entity);
|
}
|
}
|
}
|