ningshuxia
2023-02-24 1e4b358de58e36bfbf692ab2538ff9e7d60fd025
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 IStation.Untity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; 
 
 
namespace IStation.BLL
{
    public partial class AnalyzeStructure
    {
        //Entity to GetModel
        private Model.AnalyzeStructure Entity2Model(Entity.AnalyzeStructure entity)
        {
            if (entity == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.AnalyzeStructure, Model.AnalyzeStructure>()
            .ForMember(d => d.ParentIds, opt => opt.MapFrom(src => TreeParentIdsHelper.ToList(src.ParentIds)))
            ).CreateMapper();
            var model = mapper.Map<Entity.AnalyzeStructure, Model.AnalyzeStructure>(entity);
            return model;
        }
        //Entities to GetModels
        private List<Model.AnalyzeStructure> Entity2Models(List<Entity.AnalyzeStructure> entities)
        {
            if (entities == null || entities.Count() < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.AnalyzeStructure, Model.AnalyzeStructure>()
            .ForMember(d => d.ParentIds, opt => opt.MapFrom(src => TreeParentIdsHelper.ToList(src.ParentIds)))
            ).CreateMapper();
            var models = mapper.Map<List<Entity.AnalyzeStructure>, List<Model.AnalyzeStructure>>(entities);
            return models;
        }
 
        //Model to Entity
        private Entity.AnalyzeStructure Model2Entity(Model.AnalyzeStructure model)
        {
            if (model == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.AnalyzeStructure, Entity.AnalyzeStructure>()
            .ForMember(d => d.ParentIds, opt => opt.MapFrom(src => TreeParentIdsHelper.ToString(src.ParentIds)))
            ).CreateMapper();
            var entity = mapper.Map<Model.AnalyzeStructure, Entity.AnalyzeStructure>(model);
            return entity;
        }
 
        //Models to Entities
        private List<Entity.AnalyzeStructure> Model2Entities(List<Model.AnalyzeStructure> models)
        {
            if (models == null || models.Count < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.AnalyzeStructure, Entity.AnalyzeStructure>()
            .ForMember(d => d.ParentIds, opt => opt.MapFrom(src => TreeParentIdsHelper.ToString(src.ParentIds)))
            ).CreateMapper();
            var entities = mapper.Map<List<Model.AnalyzeStructure>, List<Entity.AnalyzeStructure>>(models);
            return entities;
        }
 
        //Model to Entity
        private void Model2Entity(Model.AnalyzeStructure model, Entity.AnalyzeStructure entity)
        {
            if (model == null || entity == null)
                return;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.AnalyzeStructure, Entity.AnalyzeStructure>()
             .ForMember(d => d.ParentIds, opt => opt.MapFrom(src => TreeParentIdsHelper.ToString(src.ParentIds)))
             ).CreateMapper();
            mapper.Map(model, entity);
        }
    }
}