Shuxia Ning
2024-10-08 cf4967a0aebab18c5a37137f3e4c61b2d73a54bb
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
using AutoMapper;
using System.Collections.Generic;
using System.Linq;
 
 
namespace IStation.BLL
{
    public static class Sorter_Instance
    {
        //Entity to GetModel
        public static Model.Sorter Entity2Model(this Entity.Sorter entities)
        {
            if (entities == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.Sorter, Model.Sorter>()
            ).CreateMapper();
            var model = mapper.Map<Entity.Sorter, Model.Sorter>(entities);
            return model;
        }
 
        //Entities to GetModels
        public static List<Model.Sorter> Entity2Models(this List<Entity.Sorter> entities)
        {
            if (entities == null || entities.Count() < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.Sorter, Model.Sorter>()
            ).CreateMapper();
            var models = mapper.Map<List<Entity.Sorter>, List<Model.Sorter>>(entities);
            return models;
        }
 
        //Model to Entity
        public static Entity.Sorter Model2Entity(this Model.Sorter model)
        {
            if (model == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.Sorter, Entity.Sorter>()
            ).CreateMapper();
            var entities = mapper.Map<Model.Sorter, Entity.Sorter>(model);
            return entities;
        }
 
        //Models to Entities
        public static List<Entity.Sorter> Model2Entities(this List<Model.Sorter> models)
        {
            if (models == null || models.Count < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.Sorter, Entity.Sorter>()
            ).CreateMapper();
            var entities = mapper.Map<List<Model.Sorter>, List<Entity.Sorter>>(models);
            return entities;
        }
 
    }
}