tangxu
2024-05-04 39579aa528747af7ca7b17b04453095e2a27a009
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
using AutoMapper; 
using System.Collections.Generic;
using System.Linq;
 
namespace IStation.ChEr.BLL
{
    public partial class WaterPredict
    {
        //Entity to GetModel
        private Model.WaterPredict Entity2Model(Entity.WaterPredict entities)
        {
            if (entities == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.WaterPredict, Model.WaterPredict>()
             ).CreateMapper();
            var model = mapper.Map<Entity.WaterPredict, Model.WaterPredict>(entities);
            return model;
        }
 
        //Entities to GetModels
        private List<Model.WaterPredict> Entity2Models(List<Entity.WaterPredict> entities)
        {
            if (entities == null || entities.Count() < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Entity.WaterPredict, Model.WaterPredict>()
             ).CreateMapper();
            var models = mapper.Map<List<Entity.WaterPredict>, List<Model.WaterPredict>>(entities);
            return models;
        }
 
        //public class DbProduct
        //{
        //    public int ProductId { get; set; }
        //    public string Name { get; set; }
        //    public decimal Price { get; set; }
        //}
 
        //public class ProductViewModel
        //{
        //    public int ProductId { get; set; }
        //    public string DisplayName { get; set; }
        //    public string PriceString { get; set; }
        //}
 
        //Model to Entity
        private Entity.WaterPredict Model2Entity(Model.WaterPredict model)
        {
            if (model == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.WaterPredict, Entity.WaterPredict>()
             ).CreateMapper();
            var entities = mapper.Map<Model.WaterPredict, Entity.WaterPredict>(model);
            return entities;
        }
 
        //Models to Entities
        private List<Entity.WaterPredict> Model2Entities(List<Model.WaterPredict> models)
        {
            if (models == null || models.Count < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.WaterPredict, Entity.WaterPredict>()
             ).CreateMapper();
            var entities = mapper.Map<List<Model.WaterPredict>, List<Entity.WaterPredict>>(models);
            return entities;
        }
 
        //Model to Entity
        private void Model2Entity(Model.WaterPredict model, Entity.WaterPredict entities)
        {
            if (model == null || entities == null)
                return;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<Model.WaterPredict, Entity.WaterPredict>()
              ).CreateMapper();
            mapper.Map(model, entities);
        }
    }
}