using AutoMapper;
|
using IStation.Untity;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.Service
|
{
|
public partial class MonitorHourRecord
|
{
|
//Entity to Model
|
private Model.MonitorHourRecord Entity2Model(Entity.MonitorHourRecord entity)
|
{
|
if (entity == null)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.MonitorHourRecord, Model.MonitorHourRecord>()
|
.ForMember(d => d.DataStatus, opt => opt.MapFrom(src => DataStatusHelper.ToList(src.DataStatus)))
|
).CreateMapper();
|
var model = mapper.Map<Entity.MonitorHourRecord, Model.MonitorHourRecord>(entity);
|
return model;
|
}
|
|
//Entities to Models
|
private List<Model.MonitorHourRecord> Entity2Models(List<Entity.MonitorHourRecord> entities)
|
{
|
if (entities == null || entities.Count() < 1)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.MonitorHourRecord, Model.MonitorHourRecord>()
|
.ForMember(d => d.DataStatus, opt => opt.MapFrom(src => DataStatusHelper.ToList(src.DataStatus)))
|
).CreateMapper();
|
var models = mapper.Map<List<Entity.MonitorHourRecord>, List<Model.MonitorHourRecord>>(entities);
|
return models;
|
}
|
|
//Model to Entity
|
private Entity.MonitorHourRecord Model2Entity(Model.MonitorHourRecord model)
|
{
|
if (model == null)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorHourRecord, Entity.MonitorHourRecord>()
|
.ForMember(d => d.DataStatus, opt => opt.MapFrom(src => DataStatusHelper.ToString(src.DataStatus)))
|
).CreateMapper();
|
var entity = mapper.Map<Model.MonitorHourRecord, Entity.MonitorHourRecord>(model);
|
return entity;
|
}
|
|
//Models to Entities
|
private List<Entity.MonitorHourRecord> Model2Entities(List<Model.MonitorHourRecord> models)
|
{
|
if (models == null || models.Count < 1)
|
return default;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorHourRecord, Entity.MonitorHourRecord>()
|
.ForMember(d => d.DataStatus, opt => opt.MapFrom(src => DataStatusHelper.ToString(src.DataStatus)))
|
).CreateMapper();
|
var entities = mapper.Map<List<Model.MonitorHourRecord>, List<Entity.MonitorHourRecord>>(models);
|
return entities;
|
}
|
|
//Model to Entity
|
private void Model2Entity(Model.MonitorHourRecord model, Entity.MonitorHourRecord entity)
|
{
|
if (model == null || entity == null)
|
return;
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorHourRecord, Entity.MonitorHourRecord>()
|
.ForMember(d => d.DataStatus, opt => opt.MapFrom(src => DataStatusHelper.ToString(src.DataStatus)))
|
).CreateMapper();
|
mapper.Map(model, entity);
|
}
|
|
#region entity to basic content
|
|
private Model.MonitorBasicRecordContent Entity2BasicContent(Entity.MonitorHourRecord entity)
|
{
|
if (entity == null)
|
return default;
|
var model = new Model.MonitorBasicRecordContent();
|
model.SrcTime = entity.SrcTime;
|
model.SrcValue = entity.SrcValue;
|
model.DataTime = entity.DataTime;
|
model.DataValue = entity.DataValue;
|
model.DataStatus = DataStatusHelper.ToList(entity.DataStatus);
|
return model;
|
}
|
|
private List<Model.MonitorBasicRecordContent> Entity2BasicContents(List<Entity.MonitorHourRecord> list)
|
{
|
return list?.Select(x => Entity2BasicContent(x)).ToList();
|
|
}
|
|
#endregion
|
|
}
|
}
|