lixiaojun
2022-08-12 424d2d20a24b76850b73fae8ecc9bc98505be4f5
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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 MonitorUnit
    {
        //Entity to Model
        private Model.MonitorUnit Entity2Model(Entity.MonitorUnit entity)
        {
            if (entity == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.MonitorUnit, Model.MonitorUnit>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToList(src.Flags)))
            ).CreateMapper();
            var model = mapper.Map<Entity.MonitorUnit, Model.MonitorUnit>(entity);
            return model;
        }
 
        //Entities to Models
        private List<Model.MonitorUnit> Entity2Models(List<Entity.MonitorUnit> entities)
        {
            if (entities == null || entities.Count() < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.MonitorUnit, Model.MonitorUnit>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToList(src.Flags)))
            ).CreateMapper();
            var models = mapper.Map<List<Entity.MonitorUnit>, List<Model.MonitorUnit>>(entities);
            return models;
        }
 
        //Model to Entity
        private Entity.MonitorUnit Model2Entity(Model.MonitorUnit model)
        {
            if (model == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorUnit, Entity.MonitorUnit>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
            ).CreateMapper();
 
            var entity = mapper.Map<Model.MonitorUnit, Entity.MonitorUnit>(model);
            return entity;
        }
 
        //Models to Entities
        private List<Entity.MonitorUnit> Model2Entities(List<Model.MonitorUnit> models)
        {
            if (models == null || models.Count < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorUnit, Entity.MonitorUnit>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
            ).CreateMapper();
            var entities = mapper.Map<List<Model.MonitorUnit>, List<Entity.MonitorUnit>>(models);
            return entities;
        }
 
        //Model to Entity
        private void Model2Entity(Model.MonitorUnit model, Entity.MonitorUnit entity)
        {
            if (model == null || entity == null)
                return;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorUnit, Entity.MonitorUnit>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
            ).CreateMapper();
            mapper.Map(model, entity);
        }
 
 
        //Entity to Model
        private Model.SignalUnit Entity2Model(Entity.SignalUnit entity)
        {
            if (entity == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.SignalUnit, Model.SignalUnit>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToList(src.Flags)))
            ).CreateMapper();
            var model = mapper.Map<Entity.SignalUnit, Model.SignalUnit>(entity);
            return model;
        }
 
        //Entities to Models
        private List<Model.SignalUnit> Entity2Models(List<Entity.SignalUnit> entities)
        {
            if (entities == null || entities.Count() < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.SignalUnit, Model.SignalUnit>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToList(src.Flags)))
            ).CreateMapper();
            var models = mapper.Map<List<Entity.SignalUnit>, List<Model.SignalUnit>>(entities);
            return models;
        }
 
        //Model to Entity
        private Entity.SignalUnit Model2Entity(Model.SignalUnit model)
        {
            if (model == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.SignalUnit, Entity.SignalUnit>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
            ).CreateMapper();
            var entity = mapper.Map<Model.SignalUnit, Entity.SignalUnit>(model);
            return entity;
        }
 
        //Models to Entities
        private List<Entity.SignalUnit> Model2Entities(List<Model.SignalUnit> models)
        {
            if (models == null || models.Count < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.SignalUnit, Entity.SignalUnit>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
            ).CreateMapper();
            var entities = mapper.Map<List<Model.SignalUnit>, List<Entity.SignalUnit>>(models);
            return entities;
        }
 
        //Model to Entity
        private void Model2Entity(Model.SignalUnit model, Entity.SignalUnit entity)
        {
            if (model == null || entity == null)
                return;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.SignalUnit, Entity.SignalUnit>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => FlagsHelper.ToString(src.Flags)))
            ).CreateMapper();
            mapper.Map(model, entity);
        }
 
 
 
 
 
 
    }
}