using SqlSugar;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
namespace TProduct.DAL
|
{
|
public partial class BaseLiteSqlDAL_Sorter<T> : BaseLiteSqlDAL<T> where T : Entity.BaseEntity, Entity.ISorter, new()
|
{
|
/// <summary>
|
/// 更新排序码
|
/// </summary>
|
public virtual bool UpdateSortCode(long ID, int SortCode)
|
{
|
using (ISqlSugarClient db = Connection)
|
{
|
var result = db.Updateable<T>().SetColumns(x => x.SortCode == SortCode).Where(x => x.ID == ID).ExecuteCommandHasChange();
|
return result;
|
}
|
}
|
|
/// <summary>
|
/// 更新排序
|
/// </summary>
|
public virtual bool UpdateSorter(List<Entity.Sorter> Sorters)
|
{
|
if (Sorters == null || Sorters.Count() < 1)
|
return default;
|
using (ISqlSugarClient db = Connection)
|
{
|
db.Ado.BeginTran();
|
foreach (var item in Sorters)
|
{
|
var result = db.Updateable<T>().SetColumns(x => x.SortCode == item.SortCode).Where(x => x.ID == item.ID).ExecuteCommandHasChange();
|
if (!result)
|
{
|
db.Ado.RollbackTran();
|
return false;
|
}
|
}
|
db.Ado.CommitTran();
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// 获取最大排序码
|
/// </summary>
|
public int GetMaxSorter()
|
{
|
using (ISqlSugarClient db = Connection)
|
{
|
return db.Queryable<T>().Max(x => x.SortCode);
|
}
|
}
|
|
/// <summary>
|
/// 获取最小排序码
|
/// </summary>
|
public int GetMinSorter()
|
{
|
using (ISqlSugarClient db = Connection)
|
{
|
return db.Queryable<T>().Min(x => x.SortCode);
|
}
|
}
|
|
}
|
}
|