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
|
}
|
}
|