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
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; 
 
 
namespace IStation.BLL
{
    public partial class Station
    {
        //Entity to GetModel
        private Model.Station Entity2Model(Entity.Station entities)
        {
            if (entities == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.Station, Model.Station>()).CreateMapper();  
            var model = mapper.Map<Entity.Station, Model.Station>(entities);
            return model;
        }
 
        //Entities to GetModels
        private List<Model.Station> Entity2Models(List<Entity.Station> entities)
        {
            if (entities == null || entities.Count() < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.Station, Model.Station>()).CreateMapper();
            var models = mapper.Map<List<Entity.Station>, List<Model.Station>>(entities);
            return models;
        }
 
        //Model to Entity
        private Entity.Station Model2Entity(Model.Station model)
        {
            if (model == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.Station, Entity.Station>()).CreateMapper();
            var entities = mapper.Map<Model.Station, Entity.Station>(model);
            return entities;
        }
 
        //Models to Entities
        private List<Entity.Station> Model2Entities(List<Model.Station> models)
        {
            if (models == null || models.Count < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.Station, Entity.Station>()).CreateMapper();
            var entities = mapper.Map<List<Model.Station>, List<Entity.Station>>(models);
            return entities;
        }
 
        //Model to Entity
        private void Model2Entity(Model.Station model, Entity.Station entities)
        {
            if (model == null || entities == null)
                return;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.Station, Entity.Station>()).CreateMapper();
            mapper.Map(model, entities);
        }
    }
}