namespace Yw.DAL
{
///
///
///
public partial class HealthDeterioration : BaseDAL_Sorter
{
///
///
///
public override ConnectionConfig ConnectionConfig
{
get { return ConfigHelper.DefaultConnectionConfig; }
}
///
/// 设置
///
public bool Set(List list)
{
if (list == null || list.Count < 1)
return false;
var deductionList = list.Select(x => x.Deduction).Distinct().ToList();
if (deductionList.Count != list.Count)
return false;
using (var db = new SqlSugarClient(ConnectionConfig))
{
try
{
db.BeginTran();
//删除
var ids = list.Where(x => x.ID > 0).Select(x => x.ID).Distinct().ToList();
db.Deleteable().Where(x => !ids.Contains(x.ID)).ExecuteCommand();
foreach (var item in list)
{
if (item.ID < 1)
{
var id = db.Insertable(item).ExecuteReturnSnowflakeId();
if (id < 1)
{
db.RollbackTran();
return false;
}
}
else
{
var bol = db.Updateable(item).ExecuteCommandHasChange();
if (!bol)
{
db.RollbackTran();
return false;
}
}
}
db.CommitTran();
return true;
}
catch
{
db.RollbackTran();
return false;
}
}
}
}
}