tangxu
2023-04-12 ac2a648ea67669eab6de9a1864c07f6475511dd2
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
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 ProductInspectionContentValue
    {
        //Entity to GetModel
        private Model.ProductInspectionContentValue Entity2Model(Entity.ProductInspectionContentValue entity)
        {
            if (entity == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.ProductInspectionContentValue, Model.ProductInspectionContentValue>()
            //.ForMember(d => d.DesignParas, opt => opt.MapFrom(src => Model.ProductInspectionContentValue.DesignParameters.ToModel(src.DesignParas)))
            ).CreateMapper();
            var model = mapper.Map<Entity.ProductInspectionContentValue, Model.ProductInspectionContentValue>(entity);
            return model;
        }
        //Entities to GetModels
        private List<Model.ProductInspectionContentValue> Entity2Models(List<Entity.ProductInspectionContentValue> entities)
        {
            if (entities == null || entities.Count() < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.ProductInspectionContentValue, Model.ProductInspectionContentValue>()
            // .ForMember(d => d.DesignParas, opt => opt.MapFrom(src => Model.ProductInspectionContentValue.DesignParameters.ToModel(src.DesignParas)))
            ).CreateMapper();
            var models = mapper.Map<List<Entity.ProductInspectionContentValue>, List<Model.ProductInspectionContentValue>>(entities);
            return models;
        }
 
        //Model to Entity
        private Entity.ProductInspectionContentValue Model2Entity(Model.ProductInspectionContentValue model)
        {
            if (model == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.ProductInspectionContentValue, Entity.ProductInspectionContentValue>()
            // .ForMember(d => d.DesignParas, opt => opt.MapFrom(src => src.DesignParas.ToJson()))
            ).CreateMapper();
            var entity = mapper.Map<Model.ProductInspectionContentValue, Entity.ProductInspectionContentValue>(model);
            return entity;
        }
 
        //Models to Entities
        private List<Entity.ProductInspectionContentValue> Model2Entities(List<Model.ProductInspectionContentValue> models)
        {
            if (models == null || models.Count < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.ProductInspectionContentValue, Entity.ProductInspectionContentValue>()
            // .ForMember(d => d.DesignParas, opt => opt.MapFrom(src => src.DesignParas.ToJson()))
            ).CreateMapper();
            var entities = mapper.Map<List<Model.ProductInspectionContentValue>, List<Entity.ProductInspectionContentValue>>(models);
            return entities;
        }
 
        //Model to Entity
        private void Model2Entity(Model.ProductInspectionContentValue model, Entity.ProductInspectionContentValue entity)
        {
            if (model == null || entity == null)
                return;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.ProductInspectionContentValue, Entity.ProductInspectionContentValue>()
            // .ForMember(d => d.DesignParas, opt => opt.MapFrom(src => src.DesignParas.ToJson()))
             ).CreateMapper();
            mapper.Map(model, entity);
        }
    }
}