mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-06-26 14:23:09 +08:00
🔄refactor: 调整为SqlSugar
This commit is contained in:
@@ -3,18 +3,16 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class CategoryTypeApp : BaseStringApp<CategoryType,OpenAuthDBContext>
|
||||
public class CategoryTypeApp : SqlSugarBaseApp<CategoryType>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
|
||||
@@ -24,7 +22,7 @@ namespace OpenAuth.App
|
||||
public async Task<PagedDynamicDataResp> Load(QueryCategoryTypeListReq request)
|
||||
{
|
||||
var result = new PagedDynamicDataResp();
|
||||
var objs = UnitWork.Find<CategoryType>(null);
|
||||
var objs = SugarClient.Queryable<CategoryType>();
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
objs = objs.Where(u => u.Id.Contains(request.key) || u.Name.Contains(request.key));
|
||||
@@ -42,39 +40,37 @@ namespace OpenAuth.App
|
||||
var obj = req.MapTo<CategoryType>();
|
||||
//todo:补充或调整自己需要的字段
|
||||
obj.CreateTime = DateTime.Now;
|
||||
Repository.Add(obj);
|
||||
Repository.Insert(obj);
|
||||
}
|
||||
|
||||
public void Update(AddOrUpdateCategoryTypeReq obj)
|
||||
{
|
||||
var user = _auth.GetCurrentUser().User;
|
||||
UnitWork.Update<CategoryType>(u => u.Id == obj.Id, u => new CategoryType
|
||||
Repository.Update(u => new CategoryType
|
||||
{
|
||||
Name = obj.Name,
|
||||
CreateTime = DateTime.Now
|
||||
//todo:补充或调整自己需要的字段
|
||||
});
|
||||
}, u => u.Id == obj.Id);
|
||||
|
||||
}
|
||||
|
||||
public new void Delete(string[] ids)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
UnitWork.Delete<CategoryType>(u=>ids.Contains(u.Id));
|
||||
UnitWork.Delete<Category>(u=>ids.Contains(u.TypeId));
|
||||
UnitWork.Save();
|
||||
});
|
||||
SugarClient.Ado.BeginTran();
|
||||
SugarClient.Deleteable<CategoryType>().Where(u=>ids.Contains(u.Id)).ExecuteCommand();
|
||||
SugarClient.Deleteable<Category>().Where(u=>ids.Contains(u.TypeId)).ExecuteCommand();
|
||||
SugarClient.Ado.CommitTran();
|
||||
|
||||
}
|
||||
|
||||
public List<CategoryType> AllTypes()
|
||||
{
|
||||
return UnitWork.Find<CategoryType>(null).ToList();
|
||||
return SugarClient.Queryable<CategoryType>().ToList();
|
||||
}
|
||||
|
||||
public CategoryTypeApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<CategoryType,OpenAuthDBContext> repository,
|
||||
RevelanceManagerApp app, IAuth auth) : base(unitWork, repository,auth)
|
||||
public CategoryTypeApp(ISqlSugarClient client,
|
||||
RevelanceManagerApp app, IAuth auth) : base(client, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user