ningshuxia
2023-02-06 1fc0b4ed96d4c4b1ff7142926239998de32b2ada
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.BLL
{
    public partial class MonitorPoint
    {
        //Entity to Model
        private Model.MonitorPoint Entity2Model(Entity.MonitorPoint entity)
        {
            if (entity == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.MonitorPoint, Model.MonitorPoint>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => StringListHelper.ToList(src.Flags)))
            ).CreateMapper();
            var model = mapper.Map<Entity.MonitorPoint, Model.MonitorPoint>(entity);
            return model;
        }
 
        //Entities to Models
        private List<Model.MonitorPoint> Entity2Models(List<Entity.MonitorPoint> entities)
        {
            if (entities == null || entities.Count() < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.MonitorPoint, Model.MonitorPoint>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => StringListHelper.ToList(src.Flags)))
            ).CreateMapper();
            var models = mapper.Map<List<Entity.MonitorPoint>, List<Model.MonitorPoint>>(entities);
            return models;
        }
 
        //Model to Entity
        private Entity.MonitorPoint Model2Entity(Model.MonitorPoint model)
        {
            if (model == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorPoint, Entity.MonitorPoint>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => StringListHelper.ToString(src.Flags)))
            ).CreateMapper();
 
            var entity = mapper.Map<Model.MonitorPoint, Entity.MonitorPoint>(model);
            return entity;
        }
 
        //Models to Entities
        private List<Entity.MonitorPoint> Model2Entities(List<Model.MonitorPoint> models)
        {
            if (models == null || models.Count < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorPoint, Entity.MonitorPoint>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => StringListHelper.ToString(src.Flags)))
            ).CreateMapper();
            var entities = mapper.Map<List<Model.MonitorPoint>, List<Entity.MonitorPoint>>(models);
            return entities;
        }
 
        //Model to Entity
        private void Model2Entity(Model.MonitorPoint model, Entity.MonitorPoint entity)
        {
            if (model == null || entity == null)
                return;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.MonitorPoint, Entity.MonitorPoint>()
            .ForMember(d => d.Flags, opt => opt.MapFrom(src => StringListHelper.ToString(src.Flags)))
            ).CreateMapper();
            mapper.Map(model, entity);
        }
 
 
        //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))) 
            ).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))) 
            ).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))) 
            ).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))) 
            ).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)))
            ).CreateMapper();
            mapper.Map(model, entity);
        }
 
 
 
 
 
 
 
    }
}