using IStation.Untity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IStation.Service
{
///
/// 泵站
///
public partial class ProductInspectionContentItem
{
#region Query
///
/// 通过 ProductID 获取:管理端用,不走缓存
///
public List GetByProductID( long ProductID)
{
var dal = new DAL.ProductInspectionContentItem();
var all = dal.GetByProductID(ProductID);
if(all == null || all.Count == 0)
return null;
var all2 = Entity2Models(all);
return all2.OrderBy(x => x.SortCode).ToList();
}
///
/// 通过 CorpID 获取:管理端用,不走缓存
///
public List GetByCorpID(long CorpID)
{
var dal = new DAL.ProductInspectionContentItem();
var all = dal.GetByCorpID(CorpID);
if (all == null || all.Count == 0)
return null;
var all2 = Entity2Models(all);
return all2.OrderBy(x => x.SortCode).ToList();
}
#endregion
#region Insert
///
/// 插入一条数据
///
public long Insert(Model.ProductInspectionContentItem model,
List values)
{
if (model == null)
return default;
if (model.CorpID < 1)
return default;
var dal = new DAL.ProductInspectionContentItem();
var entity = Model2Entity(model);
entity.CreateTime = DateTime.Now;
List entitys_values = null;
if(values != null && values.Count > 0)
{
entitys_values = Model2Entities(values);
foreach (var ent in entitys_values)
ent.CreateTime = DateTime.Now;
}
var id = dal.Insert(entity, entitys_values);
if (id > 0)
{
IStation.Service.InspectionContentBundleCacheHelper.Remove (model.CorpID);
}
return id;
}
///
/// 插入多条
///
public bool Inserts(List list)
{
if (list == null || list.Count() < 1)
return default;
var corpIds = list.Select(x => x.CorpID).Distinct().ToList();
if (corpIds.Count != 1 || corpIds[0] < 1)
return default;
var dal = new DAL.ProductInspectionContentItem();
var entity_list = Model2Entities(list.ToList());
foreach(var entity in entity_list)
entity.CreateTime = DateTime.Now;
var ids = dal.InsertsR(entity_list);
if (ids != null && ids.Count > 0)
{
IStation.Service.InspectionContentBundleCacheHelper.Remove(corpIds[0]);
return true;
}
return false;
}
#endregion
#region Update
///
/// 更新一条
///
public bool Update(Model.ProductInspectionContentItem model,
List values)
{
if (model == null)
return default;
if (model.CorpID < 1)
return default;
if (model.ID < 1)
return default;
var dal = new DAL.ProductInspectionContentItem();
var entity = Model2Entity(model);
entity.UpdateTime = DateTime.Now;
List entitys_values = null;
if (values != null && values.Count > 0)
{
entitys_values = Model2Entities(values);
foreach (var ent in entitys_values)
{
ent.UpdateTime = DateTime.Now;
}
}
var bol = dal.Update(entity, entitys_values);
if (bol)
{
IStation.Service.InspectionContentBundleCacheHelper.Remove(model.CorpID);
}
return bol;
}
///
/// 更新多条
///
public bool Updates(List list)
{
if (list == null || list.Count() < 1)
return default;
var corpIds = list.Select(x => x.CorpID).Distinct().ToList();
if (corpIds.Count != 1 || corpIds[0] < 1)
return default;
if (list.ToList().Exists(x => x.ID < 1))
return default;
var dal = new DAL.ProductInspectionContentItem();
var entity_list = Model2Entities(list.ToList());
foreach (var entity in entity_list)
entity.UpdateTime = DateTime.Now;
var bol = dal.Updates(entity_list);
if (bol)
{
IStation.Service.InspectionContentBundleCacheHelper.Remove(corpIds[0]);
}
return bol;
}
///
/// 更新使用状态
///
public bool UpdateUseStatus(long CorpID, long ID, Model.eUseStatus UseStatus, long UpdateUserID )
{
var dal = new DAL.ProductInspectionContentItem();
var bol = dal.UpdateUseStatus(CorpID, ID, (int)UseStatus, UpdateUserID, DateTime.Now);
if (bol)
{
IStation.Service.InspectionContentBundleCacheHelper.Remove(CorpID);
}
return bol;
}
///
/// 更新排序码
///
public bool UpdateSortCode(long CorpID, long ID, int SortCode, long UpdateUserID )
{
var dal = new DAL.ProductInspectionContentItem();
var bol = dal.UpdateSortCode(CorpID, ID, SortCode, UpdateUserID, DateTime.Now);
if (bol)
{
IStation.Service.InspectionContentBundleCacheHelper.Remove(CorpID);
}
return bol;
}
///
/// 更新排序
///
public bool UpdateSorter(long CorpID, List sorters)
{
if (sorters == null || sorters.Count() < 1)
return default;
var dal = new DAL.ProductInspectionContentItem();
var bol = dal.UpdateSorter(CorpID, sorters.ToEntityList());
if (bol)
{
IStation.Service.InspectionContentBundleCacheHelper.Remove(CorpID );
}
return bol;
}
#endregion
#region Delete
///
/// 通过 ID 删除
///
public bool DeleteByID(long CorpID, long ID, out string Msg)
{
Msg = string.Empty;
var dal = new DAL.ProductInspectionContentItem();
var bol = dal.DeleteByID(CorpID, ID);
if (bol)
{
IStation.Service.InspectionContentBundleCacheHelper.Remove(CorpID);
}
return bol;
}
#endregion
}
}