diff --git a/OpenAuth.App/AppManager/AppManager.cs b/OpenAuth.App/AppManager/AppManager.cs
index af6213d6..8a72b408 100644
--- a/OpenAuth.App/AppManager/AppManager.cs
+++ b/OpenAuth.App/AppManager/AppManager.cs
@@ -8,45 +8,49 @@ using OpenAuth.App.Request;
using OpenAuth.Repository;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
+using SqlSugar;
namespace OpenAuth.App
{
///
- /// 分类管理
+ /// 应用管理
///
- public class AppManager : BaseStringApp
+ public class AppManager : SqlSugarBaseApp
{
- public AppManager(IUnitWork unitWork, IRepository repository) : base(unitWork, repository, null)
+ public AppManager(ISqlSugarClient client) : base(client, null)
{
}
-
- public void Add(Application Application)
+ public void Add(Application application)
{
- if (string.IsNullOrEmpty(Application.Id))
+ if (string.IsNullOrEmpty(application.Id))
{
- Application.Id = Guid.NewGuid().ToString();
+ application.Id = Guid.NewGuid().ToString();
}
- Repository.Add(Application);
+ Repository.Insert(application);
}
- public void Update(Application Application)
+ public void Update(Application application)
{
- Repository.Update(Application);
+ Repository.Update(application);
}
-
-
+
public async Task> GetList(QueryAppListReq request)
{
- var applications = UnitWork.Find(null);
+ var applications = Repository.GetListAsync();
- return await applications.ToListAsync();
+ return await applications;
}
public Application GetByAppKey(string modelAppKey)
{
- return Repository.FirstOrDefault(u => u.AppSecret == modelAppKey);
+ return Repository.GetFirst(u => u.AppSecret == modelAppKey);
+ }
+
+ public void Delete(string[] ids)
+ {
+ Repository.DeleteByIds(ids);
}
}
}
\ No newline at end of file
diff --git a/OpenAuth.App/Base/SqlSugarBaseApp.cs b/OpenAuth.App/Base/SqlSugarBaseApp.cs
index 918d288f..b4b77bdb 100644
--- a/OpenAuth.App/Base/SqlSugarBaseApp.cs
+++ b/OpenAuth.App/Base/SqlSugarBaseApp.cs
@@ -1,23 +1,25 @@
using System;
using System.Linq;
using Infrastructure;
-using Microsoft.EntityFrameworkCore;
using OpenAuth.App.Interface;
+using OpenAuth.Repository;
using OpenAuth.Repository.Core;
using OpenAuth.Repository.Domain;
-using OpenAuth.Repository.Interface;
using SqlSugar;
namespace OpenAuth.App
{
- public abstract class SqlSugarBaseApp
+ public abstract class SqlSugarBaseApp where T : class, new()
{
protected ISqlSugarClient SugarClient;
+ protected SqlSugarRepository Repository;
+
protected IAuth _auth;
public SqlSugarBaseApp(ISqlSugarClient client, IAuth auth)
{
+ Repository = new SqlSugarRepository(client); //这里用new而不用注入,可以保证client和repository用的是同一个client
SugarClient = client;
_auth = auth;
}
diff --git a/OpenAuth.App/Resources/ResourceApp.cs b/OpenAuth.App/Resources/ResourceApp.cs
index 3465e313..969e87d1 100644
--- a/OpenAuth.App/Resources/ResourceApp.cs
+++ b/OpenAuth.App/Resources/ResourceApp.cs
@@ -3,20 +3,18 @@ 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 ResourceApp:BaseStringApp
+ public class ResourceApp:SqlSugarBaseApp
{
private RevelanceManagerApp _revelanceApp;
@@ -28,13 +26,13 @@ namespace OpenAuth.App
var user = _auth.GetCurrentUser().User;
obj.CreateUserId = user.Id;
obj.CreateUserName = user.Name;
- Repository.Add(obj);
+ Repository.Insert(obj);
}
public void Update(AddOrUpdateResReq obj)
{
var user = _auth.GetCurrentUser().User;
- UnitWork.Update(u => u.Id == obj.Id, u => new Resource
+ Repository.Update(u => new Resource
{
Name = obj.Name,
Disable = obj.Disable,
@@ -50,13 +48,13 @@ namespace OpenAuth.App
UpdateUserId = user.Id,
UpdateUserName = user.Name
//todo:要修改的字段赋值
- });
+ },u => u.Id == obj.Id);
}
public IEnumerable LoadForRole(string appId, string roleId)
{
var elementIds = _revelanceApp.Get(Define.ROLERESOURCE, true, roleId);
- return UnitWork.Find(u => elementIds.Contains(u.Id) && (appId == null || appId =="" || u.AppId == appId));
+ return SugarClient.Queryable().Where(u => elementIds.Contains(u.Id) && (appId == null || appId =="" || u.AppId == appId)).ToArray();
}
public async Task Load(QueryResourcesReq request)
@@ -90,15 +88,18 @@ namespace OpenAuth.App
result.columnFields = columnFields;
result.data = resources.OrderBy(u => u.TypeId)
.Skip((request.page - 1) * request.limit)
- .Take(request.limit).Select($"new ({propertyStr})");
+ .Take(request.limit).Select($"{propertyStr}").ToList();
result.count = await resources.CountAsync();
return result;
}
- public ResourceApp(IUnitWork unitWork, IRepository repository
- ,RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
+ public ResourceApp(ISqlSugarClient client, IAuth auth) : base(client, auth)
{
- _revelanceApp = app;
+ }
+
+ public void Delete(string[] ids)
+ {
+ Repository.DeleteByIds(ids);
}
}
}
\ No newline at end of file
diff --git a/OpenAuth.Repository/SqlSugarRepository.cs b/OpenAuth.Repository/SqlSugarRepository.cs
new file mode 100644
index 00000000..b1d30b25
--- /dev/null
+++ b/OpenAuth.Repository/SqlSugarRepository.cs
@@ -0,0 +1,16 @@
+using System.Collections.Generic;
+using SqlSugar;
+
+namespace OpenAuth.Repository;
+
+///
+/// SqlSugar仓储
+/// 具体用法参考:https://www.donet5.com/Home/Doc?typeId=1228
+///
+public class SqlSugarRepository: SimpleClient where T : class, new()
+{
+ public SqlSugarRepository(ISqlSugarClient client)
+ {
+ base.Context=client;
+ }
+}
\ No newline at end of file