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 Signal
|
{
|
//Entity to Model
|
private Model.Signal Entity2Model(Entity.Signal entity)
|
{
|
if (entity == null)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.Signal, Model.Signal>()
|
.ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToList(src.Flags)))
|
.ForMember(d => d.ConvertParas, opt => opt.MapFrom(src => Model.Monitor.ConvertParameters.ToModel(src.ConvertParas)))
|
.ForMember(d => d.FilterParas, opt => opt.MapFrom(src => Model.Monitor.FilterParameters.ToModel(src.FilterParas)))
|
.ForMember(d => d.CorrectParas, opt => opt.MapFrom(src => Model.Monitor.CorrectParameters.ToModel(src.CorrectParas)))
|
).CreateMapper();
|
var model = mapper.Map<Entity.Signal, Model.Signal>(entity);
|
return model;
|
}
|
//Entities to Models
|
private List<Model.Signal> Entity2Models(List<Entity.Signal> entities)
|
{
|
if (entities == null || entities.Count() < 1)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.Signal, Model.Signal>()
|
.ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToList(src.Flags)))
|
.ForMember(d => d.ConvertParas, opt => opt.MapFrom(src => Model.Monitor.ConvertParameters.ToModel(src.ConvertParas)))
|
.ForMember(d => d.FilterParas, opt => opt.MapFrom(src => Model.Monitor.FilterParameters.ToModel(src.FilterParas)))
|
.ForMember(d => d.CorrectParas, opt => opt.MapFrom(src => Model.Monitor.CorrectParameters.ToModel(src.CorrectParas)))
|
).CreateMapper();
|
var models = mapper.Map<List<Entity.Signal>, List<Model.Signal>>(entities);
|
return models;
|
}
|
|
//Model to Entity
|
private Entity.Signal Model2Entity(Model.Signal model)
|
{
|
if (model == null)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.Signal, Entity.Signal>()
|
.ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
|
.ForMember(d => d.ConvertParas, opt => opt.MapFrom(src => src.ConvertParas == null ? null : src.ConvertParas.ToJson()))
|
.ForMember(d => d.FilterParas, opt => opt.MapFrom(src => src.FilterParas==null?null:src.FilterParas.ToJson()))
|
.ForMember(d => d.CorrectParas, opt => opt.MapFrom(src => src.CorrectParas==null?null:src.CorrectParas.ToJson()))
|
).CreateMapper();
|
var entity = mapper.Map<Model.Signal, Entity.Signal>(model);
|
return entity;
|
}
|
|
//Models to Entities
|
private List<Entity.Signal> Model2Entities(List<Model.Signal> models)
|
{
|
if (models == null || models.Count < 1)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.Signal, Entity.Signal>()
|
.ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
|
.ForMember(d => d.ConvertParas, opt => opt.MapFrom(src => src.ConvertParas == null ? null : src.ConvertParas.ToJson()))
|
.ForMember(d => d.FilterParas, opt => opt.MapFrom(src => src.FilterParas == null ? null : src.FilterParas.ToJson()))
|
.ForMember(d => d.CorrectParas, opt => opt.MapFrom(src => src.CorrectParas == null ? null : src.CorrectParas.ToJson()))
|
).CreateMapper();
|
var entities = mapper.Map<List<Model.Signal>, List<Entity.Signal>>(models);
|
return entities;
|
}
|
|
//Model to Entity
|
private void Model2Entity(Model.Signal model, Entity.Signal entity)
|
{
|
if (model == null || entity == null)
|
return;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.Signal, Entity.Signal>()
|
.ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
|
.ForMember(d => d.ConvertParas, opt => opt.MapFrom(src => src.ConvertParas == null ? null : src.ConvertParas.ToJson()))
|
.ForMember(d => d.FilterParas, opt => opt.MapFrom(src => src.FilterParas == null ? null : src.FilterParas.ToJson()))
|
.ForMember(d => d.CorrectParas, opt => opt.MapFrom(src => src.CorrectParas == null ? null : src.CorrectParas.ToJson()))
|
).CreateMapper();
|
mapper.Map(model, entity);
|
}
|
|
}
|
}
|