mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 18:22:11 +08:00
refactor: 分类调整为sqlsugar
This commit is contained in:
@@ -3,18 +3,15 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using OpenAuth.App.Interface;
|
using OpenAuth.App.Interface;
|
||||||
using OpenAuth.App.Request;
|
using OpenAuth.App.Request;
|
||||||
using OpenAuth.App.Response;
|
using OpenAuth.App.Response;
|
||||||
using OpenAuth.Repository;
|
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
using OpenAuth.Repository.Interface;
|
using SqlSugar;
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAuth.App
|
namespace OpenAuth.App
|
||||||
{
|
{
|
||||||
public class CategoryApp : BaseStringApp<Category,OpenAuthDBContext>
|
public class CategoryApp : SqlSugarBaseApp<Category>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载列表
|
/// 加载列表
|
||||||
@@ -40,7 +37,7 @@ namespace OpenAuth.App
|
|||||||
}
|
}
|
||||||
|
|
||||||
var result = new TableData();
|
var result = new TableData();
|
||||||
var objs = UnitWork.Find<Category>(null);
|
var objs = SugarClient.Queryable<Category>();
|
||||||
if (!string.IsNullOrEmpty(request.TypeId))
|
if (!string.IsNullOrEmpty(request.TypeId))
|
||||||
{
|
{
|
||||||
objs = objs.Where(u => u.TypeId == request.TypeId);
|
objs = objs.Where(u => u.TypeId == request.TypeId);
|
||||||
@@ -60,7 +57,7 @@ namespace OpenAuth.App
|
|||||||
result.columnFields = columnFields;
|
result.columnFields = columnFields;
|
||||||
result.data = objs.OrderBy(u => u.DtCode)
|
result.data = objs.OrderBy(u => u.DtCode)
|
||||||
.Skip((request.page - 1) * request.limit)
|
.Skip((request.page - 1) * request.limit)
|
||||||
.Take(request.limit).Select($"new ({propertyStr})");
|
.Take(request.limit).Select($"{propertyStr}").ToList();
|
||||||
result.count = await objs.CountAsync();
|
result.count = await objs.CountAsync();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -72,13 +69,13 @@ namespace OpenAuth.App
|
|||||||
var user = _auth.GetCurrentUser().User;
|
var user = _auth.GetCurrentUser().User;
|
||||||
obj.CreateUserId = user.Id;
|
obj.CreateUserId = user.Id;
|
||||||
obj.CreateUserName = user.Name;
|
obj.CreateUserName = user.Name;
|
||||||
await Repository.AddAsync(obj);
|
await SugarClient.Insertable(obj).ExecuteCommandAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(AddOrUpdateCategoryReq obj)
|
public void Update(AddOrUpdateCategoryReq obj)
|
||||||
{
|
{
|
||||||
var user = _auth.GetCurrentUser().User;
|
var user = _auth.GetCurrentUser().User;
|
||||||
UnitWork.Update<Category>(u => u.Id == obj.Id, u => new Category
|
Repository.Update(u => new Category
|
||||||
{
|
{
|
||||||
Name = obj.Name,
|
Name = obj.Name,
|
||||||
Enable = obj.Enable,
|
Enable = obj.Enable,
|
||||||
@@ -89,7 +86,7 @@ namespace OpenAuth.App
|
|||||||
UpdateUserId = user.Id,
|
UpdateUserId = user.Id,
|
||||||
UpdateUserName = user.Name,
|
UpdateUserName = user.Name,
|
||||||
SortNo = obj.SortNo
|
SortNo = obj.SortNo
|
||||||
});
|
},u => u.Id == obj.Id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,10 +97,10 @@ namespace OpenAuth.App
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public List<Category> LoadByTypeId(string typeId)
|
public List<Category> LoadByTypeId(string typeId)
|
||||||
{
|
{
|
||||||
return Repository.Find(u => u.TypeId == typeId).ToList();
|
return SugarClient.Queryable<Category>().Where(u => u.TypeId == typeId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CategoryApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Category,OpenAuthDBContext> repository,IAuth auth) : base(unitWork, repository, auth)
|
public CategoryApp(ISqlSugarClient client, IAuth auth) : base(client, auth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user