tx
2025-04-10 2538101febc78f525945da72c7cdcb2589f9e6ea
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using AutoMapper;
using System.Collections.Generic;
using System.Linq;
 
namespace TProduct.BLL
{
    public class TestNoticeRecord
    {
        private readonly DAL.TestNoticeRecord _dal = new DAL.TestNoticeRecord();
 
        public long Add(TProduct.Model.TestProjectItemView item, TProduct.Model.TestNoticeRecord model)
        {
            if (model == null)
                return default;
            if (item == null)
                return default;
 
            var entity = Model2Entity(model);
            var id = _dal.Insert(item.ItemCreateTime.Year, entity);
            return id;
        }
 
 
        public bool Update(TProduct.Model.TestProjectItemView item, TProduct.Model.TestNoticeRecord model)
        {
            if (model == null)
                return default;
            if (item == null)
                return default;
 
            var entity = Model2Entity(model);
            return _dal.Update(item.ItemCreateTime.Year, entity);
        }
 
        public bool ClearAllRecord(TProduct.Model.TestProjectItemView item)
        {
            if (item == null)
                return false;
            return _dal.ClearAllRecord(item.ItemCreateTime.Year, item.ItemID);
        }
        public bool ClearAllRecord(int Year, long ItemID)
        {
            return _dal.ClearAllRecord(Year, ItemID);
        }
        public List<TProduct.Model.TestNoticeRecord> GetByTestItem(TProduct.Model.TestProjectItemInfo item)
        {
            if (item == null)
                return default;
 
            var entitys = _dal.GetByTestItemID(item.CreateTime.Year, item.ItemID);
            return Entity2Models(entitys);
        }
        public List<TProduct.Model.TestNoticeRecord> GetByTestItem(
            TProduct.Model.TestProjectItemView item)
        {
            if (item == null)
                return default;
 
            var entitys = _dal.GetByTestItemID(item.ItemCreateTime.Year, item.ItemID);
            return Entity2Models(entitys);
        }
 
        #region Map
        //Model to Entity
        private TProduct.Entity.TestNoticeRecord Model2Entity(TProduct.Model.TestNoticeRecord model)
        {
            if (model == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<TProduct.Model.TestNoticeRecord, TProduct.Entity.TestNoticeRecord>()).CreateMapper();
            var entity = mapper.Map<TProduct.Model.TestNoticeRecord, TProduct.Entity.TestNoticeRecord>(model);
            return entity;
        }
 
        //Entity to Model
        private TProduct.Model.TestNoticeRecord Entity2Model(TProduct.Entity.TestNoticeRecord entity)
        {
            if (entity == null)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<TProduct.Entity.TestNoticeRecord, TProduct.Model.TestNoticeRecord>()).CreateMapper();
            var model = mapper.Map<TProduct.Entity.TestNoticeRecord, TProduct.Model.TestNoticeRecord>(entity);
            return model;
        }
        //Entities to Models
        private List<TProduct.Model.TestNoticeRecord> Entity2Models(List<TProduct.Entity.TestNoticeRecord> entities)
        {
            if (entities == null || entities.Count() < 1)
                return default;
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap<TProduct.Entity.TestNoticeRecord, TProduct.Model.TestNoticeRecord>()).CreateMapper();
            var models = mapper.Map<List<TProduct.Entity.TestNoticeRecord>, List<TProduct.Model.TestNoticeRecord>>(entities);
            return models;
        }
        #endregion
    }
}