using AutoMapper;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using IStation.Untity;
|
|
namespace IStation.Service
|
{
|
public partial class Station
|
{
|
//Entity to GetModel
|
private Model.Station Entity2Model(Entity.Station entity)
|
{
|
if (entity == null)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.Station, Model.Station>()
|
.ForMember(d => d.DesignParas, opt => opt.MapFrom(src => Model.Station.DesignParameters.ToModel(src.DesignParas)))
|
).CreateMapper();
|
var model = mapper.Map<Entity.Station, Model.Station>(entity);
|
return model;
|
}
|
//Entities to GetModels
|
private List<Model.Station> Entity2Models(List<Entity.Station> entities)
|
{
|
if (entities == null || entities.Count() < 1)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.Station, Model.Station>()
|
.ForMember(d => d.DesignParas, opt => opt.MapFrom(src => Model.Station.DesignParameters.ToModel(src.DesignParas)))
|
).CreateMapper();
|
var models = mapper.Map<List<Entity.Station>, List<Model.Station>>(entities);
|
return models;
|
}
|
|
//Model to Entity
|
private Entity.Station Model2Entity(Model.Station model)
|
{
|
if (model == null)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.Station, Entity.Station>()
|
.ForMember(d => d.DesignParas, opt => opt.MapFrom(src => src.DesignParas.ToJson()))
|
).CreateMapper();
|
var entity = mapper.Map<Model.Station, Entity.Station>(model);
|
return entity;
|
}
|
|
//Models to Entities
|
private List<Entity.Station> Model2Entities(List<Model.Station> models)
|
{
|
if (models == null || models.Count < 1)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.Station, Entity.Station>()
|
.ForMember(d => d.DesignParas, opt => opt.MapFrom(src => src.DesignParas.ToJson()))
|
).CreateMapper();
|
var entities = mapper.Map<List<Model.Station>, List<Entity.Station>>(models);
|
return entities;
|
}
|
|
//Model to Entity
|
private void Model2Entity(Model.Station model, Entity.Station entity)
|
{
|
if (model == null || entity == null)
|
return;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.Station, Entity.Station>()
|
.ForMember(d => d.DesignParas, opt => opt.MapFrom(src => src.DesignParas.ToJson()))
|
).CreateMapper();
|
mapper.Map(model, entity);
|
}
|
}
|
}
|