lixiaojun
2022-09-05 b29e9fbda8096ce7255864cd2d63122cca60b952
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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 MonitorRecord
    {
        //Entity to Model
        private Model.MonitorRecord Entity2Model(Entity.MonitorRecord entity)
        {
            if (entity == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.MonitorRecord, Model.MonitorRecord>()
            ).CreateMapper();
            var model = mapper.Map<Entity.MonitorRecord, Model.MonitorRecord>(entity);
            return model;
        }
 
        //Entities to Models
        private List<Model.MonitorRecord> Entity2Models(List<Entity.MonitorRecord> entities)
        {
            if (entities == null || entities.Count() < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.MonitorRecord, Model.MonitorRecord>()
            ).CreateMapper();
            var models = mapper.Map<List<Entity.MonitorRecord>, List<Model.MonitorRecord>>(entities);
            return models;
        }
 
        //Model to Entity
        private Entity.MonitorRecord Model2Entity(Model.MonitorRecord model)
        {
            if (model == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorRecord, Entity.MonitorRecord>()
            ).CreateMapper();
            var entity = mapper.Map<Model.MonitorRecord, Entity.MonitorRecord>(model);
            return entity;
        }
 
        //Models to Entities
        private List<Entity.MonitorRecord> Model2Entities(List<Model.MonitorRecord> models)
        {
            if (models == null || models.Count < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorRecord, Entity.MonitorRecord>()
            ).CreateMapper();
            var entities = mapper.Map<List<Model.MonitorRecord>, List<Entity.MonitorRecord>>(models);
            return entities;
        }
 
        //Model to Entity
        private void Model2Entity(Model.MonitorRecord model, Entity.MonitorRecord entity)
        {
            if (model == null || entity == null)
                return;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorRecord, Entity.MonitorRecord>()
            ).CreateMapper();
            mapper.Map(model, entity);
        }
 
 
 
 
 
    }
}