refactor: 重构代码消除提示信息
This commit is contained in:
parent
32baf7c72f
commit
9ca5a74c8a
|
@ -33,7 +33,8 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual IEnumerable<App> RetrievesByRoleId(string roleId)
|
||||
{
|
||||
var ret = DbManager.Create().Fetch<App>($"select d.Code as Id, d.Name as AppName, case ra.AppId when d.Code then 'checked' else '' end Checked from Dicts d left join RoleApp ra on d.Code = ra.AppId and ra.RoleId = @1 where d.Code > '0' and d.Category = @0", "应用程序", roleId);
|
||||
using var db = DbManager.Create();
|
||||
var ret = db.Fetch<App>($"select d.Code as Id, d.Name as AppName, case ra.AppId when d.Code then 'checked' else '' end Checked from Dicts d left join RoleApp ra on d.Code = ra.AppId and ra.RoleId = @1 where d.Code > '0' and d.Category = @0", "应用程序", roleId);
|
||||
|
||||
// 判断是否为Administrators
|
||||
var role = RoleHelper.Retrieves().FirstOrDefault(r => r.Id == roleId);
|
||||
|
|
|
@ -19,26 +19,24 @@ namespace Bootstrap.DataAccess
|
|||
public virtual void CheckDB(string folder)
|
||||
{
|
||||
_folder = folder;
|
||||
using (var db = Longbow.Data.DbManager.Create())
|
||||
using var db = Longbow.Data.DbManager.Create();
|
||||
db.CommandTimeout = 5000;
|
||||
switch (db.Provider.GetType().Name)
|
||||
{
|
||||
db.CommandTimeout = 5000;
|
||||
switch (db.Provider.GetType().Name)
|
||||
{
|
||||
case "SQLiteDatabaseProvider":
|
||||
if (db.ExecuteScalar<int>("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='Users'") == 0) GenerateSQLiteDB(db);
|
||||
break;
|
||||
case "SqlServerDatabaseProvider":
|
||||
using (var newDB = ModifyConnectionString(db))
|
||||
{
|
||||
if (newDB.ExecuteScalar<int?>("select COUNT(1) from sys.databases where name = N'BootstrapAdmin'") == 0) GenerateSqlServer();
|
||||
}
|
||||
break;
|
||||
case "MySqlDatabaseProvider":
|
||||
case "MariaDbDatabaseProvider":
|
||||
// UNDONE: 本地没有环境此处代码未测试
|
||||
if (db.ExecuteScalar<int>("select count(*) from information_schema.tables where table_name ='Users' and Table_Schema = 'BootstrapAdmin'") == 0) GenerateMySql();
|
||||
break;
|
||||
}
|
||||
case "SQLiteDatabaseProvider":
|
||||
if (db.ExecuteScalar<int>("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='Users'") == 0) GenerateSQLiteDB(db);
|
||||
break;
|
||||
case "SqlServerDatabaseProvider":
|
||||
using (var newDB = ModifyConnectionString(db))
|
||||
{
|
||||
if (newDB.ExecuteScalar<int?>("select COUNT(1) from sys.databases where name = N'BootstrapAdmin'") == 0) GenerateSqlServer();
|
||||
}
|
||||
break;
|
||||
case "MySqlDatabaseProvider":
|
||||
case "MariaDbDatabaseProvider":
|
||||
// UNDONE: 本地没有环境此处代码未测试
|
||||
if (db.ExecuteScalar<int>("select count(*) from information_schema.tables where table_name ='Users' and Table_Schema = 'BootstrapAdmin'") == 0) GenerateMySql();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,8 @@ namespace Bootstrap.DataAccess
|
|||
if (!string.IsNullOrEmpty(userName)) sql.Where("UserName = @0", userName);
|
||||
sql.OrderBy($"{po.Sort} {po.Order}");
|
||||
|
||||
return DbManager.Create().Page<DBLog>(po.PageIndex, po.Limit, sql);
|
||||
using var db = DbManager.Create();
|
||||
return db.Page<DBLog>(po.PageIndex, po.Limit, sql);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -75,7 +76,8 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
if (p == null) throw new ArgumentNullException(nameof(p));
|
||||
DeleteLogAsync();
|
||||
DbManager.Create(enableLog: false).Save(p);
|
||||
using var db = DbManager.Create(enableLog: false);
|
||||
db.Save(p);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ namespace Bootstrap.DataAccess
|
|||
if (!value.Any()) return true;
|
||||
var ids = string.Join(",", value);
|
||||
string sql = $"where ID in ({ids})";
|
||||
DbManager.Create().Delete<BootstrapDict>(sql);
|
||||
using var db = DbManager.Create();
|
||||
db.Delete<BootstrapDict>(sql);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -39,7 +40,8 @@ namespace Bootstrap.DataAccess
|
|||
if (dict.Name.Length > 50) dict.Name = dict.Name.Substring(0, 50);
|
||||
if (dict.Code.Length > 2000) dict.Code = dict.Code.Substring(0, 2000);
|
||||
|
||||
DbManager.Create().Save(dict);
|
||||
using var db = DbManager.Create();
|
||||
db.Save(dict);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -50,7 +52,8 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool SaveSettings(BootstrapDict dict)
|
||||
{
|
||||
DbManager.Create().Update<BootstrapDict>("set Code = @Code where Category = @Category and Name = @Name", dict);
|
||||
using var db = DbManager.Create();
|
||||
db.Update<BootstrapDict>("set Code = @Code where Category = @Category and Name = @Name", dict);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,11 @@ namespace Bootstrap.DataAccess
|
|||
/// 查询一周内所有异常
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Exceptions> Retrieves() => DbManager.Create().Fetch<Exceptions>("select * from Exceptions where LogTime > @0 order by LogTime desc", DateTime.Now.AddMonths(0 - DictHelper.RetrieveExceptionsLogPeriod()));
|
||||
public virtual IEnumerable<Exceptions> Retrieves()
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<Exceptions>("select * from Exceptions where LogTime > @0 order by LogTime desc", DateTime.Now.AddMonths(0 - DictHelper.RetrieveExceptionsLogPeriod()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -147,7 +151,8 @@ namespace Bootstrap.DataAccess
|
|||
if (startTime == null && endTime == null) sql.Append("where LogTime > @0", DateTime.Today.AddMonths(0 - DictHelper.RetrieveExceptionsLogPeriod()));
|
||||
sql.Append($"order by {po.Sort} {po.Order}");
|
||||
|
||||
return DbManager.Create().Page<Exceptions>(po.PageIndex, po.Limit, sql);
|
||||
using var db = DbManager.Create();
|
||||
return db.Page<Exceptions>(po.PageIndex, po.Limit, sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,11 @@ namespace Bootstrap.DataAccess
|
|||
/// 查询所有群组信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Group> Retrieves() => DbManager.Create().Fetch<Group>();
|
||||
public virtual IEnumerable<Group> Retrieves()
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<Group>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除群组信息
|
||||
|
@ -36,9 +40,9 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="value"></param>
|
||||
public virtual bool Delete(IEnumerable<string> value)
|
||||
{
|
||||
bool ret = false;
|
||||
var ids = string.Join(",", value);
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
bool ret;
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
@ -63,7 +67,8 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool Save(Group p)
|
||||
{
|
||||
DbManager.Create().Save(p);
|
||||
using var db = DbManager.Create();
|
||||
db.Save(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -74,7 +79,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual IEnumerable<Group> RetrievesByUserId(string userId)
|
||||
{
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<Group>($"select g.ID, g.GroupCode, g.GroupName, g.Description, case ug.GroupID when g.ID then 'checked' else '' end Checked from {db.Provider.EscapeSqlIdentifier("Groups")} g left join UserGroup ug on g.ID = ug.GroupID and UserID = @0", userId);
|
||||
}
|
||||
|
||||
|
@ -85,7 +90,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual IEnumerable<Group> RetrievesByRoleId(string roleId)
|
||||
{
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<Group>($"select g.ID, g.GroupCode, g.GroupName, g.Description, case rg.GroupID when g.ID then 'checked' else '' end Checked from {db.Provider.EscapeSqlIdentifier("Groups")} g left join RoleGroup rg on g.ID = rg.GroupID and RoleID = @0", roleId);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
|
||||
#region 数据库脚本执行日志相关代码
|
||||
private static BlockingCollection<DBLog> _messageQueue = new BlockingCollection<DBLog>(new ConcurrentQueue<DBLog>());
|
||||
private static readonly BlockingCollection<DBLog> _messageQueue = new BlockingCollection<DBLog>(new ConcurrentQueue<DBLog>());
|
||||
/// <summary>
|
||||
/// 添加数据库日志实体类到内部集合中
|
||||
/// </summary>
|
||||
|
@ -84,10 +84,8 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
if (logs.Any())
|
||||
{
|
||||
using (var db = DbManager.Create(enableLog: false))
|
||||
{
|
||||
db.InsertBatch(logs);
|
||||
}
|
||||
using var db = DbManager.Create(enableLog: false);
|
||||
db.InsertBatch(logs);
|
||||
}
|
||||
return System.Threading.Tasks.Task.CompletedTask;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="endTime"></param>
|
||||
/// <param name="opType"></param>
|
||||
/// <returns></returns>
|
||||
public virtual new Page<Log> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime, string? opType)
|
||||
public new virtual Page<Log> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime, string? opType)
|
||||
{
|
||||
if (string.IsNullOrEmpty(po.Order)) po.Order = "desc";
|
||||
if (string.IsNullOrEmpty(po.Sort)) po.Sort = "LogTime";
|
||||
|
@ -40,7 +40,8 @@ namespace Bootstrap.DataAccess
|
|||
if (!string.IsNullOrEmpty(opType)) sql.Where("CRUD = @0", opType);
|
||||
sql.OrderBy($"{po.Sort} {po.Order}");
|
||||
|
||||
return DbManager.Create().Page<Log>(po.PageIndex, po.Limit, sql);
|
||||
using var db = DbManager.Create();
|
||||
return db.Page<Log>(po.PageIndex, po.Limit, sql);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -50,7 +51,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="endTime"></param>
|
||||
/// <param name="opType"></param>
|
||||
/// <returns></returns>
|
||||
public virtual new IEnumerable<Log> RetrieveAll(DateTime? startTime, DateTime? endTime, string? opType)
|
||||
public new virtual IEnumerable<Log> RetrieveAll(DateTime? startTime, DateTime? endTime, string? opType)
|
||||
{
|
||||
var sql = new Sql("select CRUD, UserName, LogTime, Ip, Browser, OS, City, RequestUrl, RequestData from Logs");
|
||||
if (startTime.HasValue) sql.Where("LogTime >= @0", startTime.Value);
|
||||
|
@ -58,7 +59,8 @@ namespace Bootstrap.DataAccess
|
|||
if (!string.IsNullOrEmpty(opType)) sql.Where("CRUD = @0", opType);
|
||||
sql.OrderBy("LogTime");
|
||||
|
||||
return DbManager.Create().Fetch<Log>(sql);
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<Log>(sql);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -70,7 +72,8 @@ namespace Bootstrap.DataAccess
|
|||
System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
var dtm = DateTime.Now.AddMonths(0 - DictHelper.RetrieveLogsPeriod());
|
||||
DbManager.Create().Execute("delete from Logs where LogTime < @0", dtm);
|
||||
using var db = DbManager.Create();
|
||||
db.Execute("delete from Logs where LogTime < @0", dtm);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -83,7 +86,8 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
if (p == null) throw new ArgumentNullException(nameof(p));
|
||||
DeleteLogAsync();
|
||||
DbManager.Create().Save(p);
|
||||
using var db = DbManager.Create();
|
||||
db.Save(p);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool Delete(IEnumerable<string> value)
|
||||
{
|
||||
if (!value.Any()) return true;
|
||||
var ret = false;
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
bool ret;
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
@ -50,7 +50,8 @@ namespace Bootstrap.DataAccess
|
|||
if (p.Name.Length > 50) p.Name = p.Name.Substring(0, 50);
|
||||
if (p.Icon != null && p.Icon.Length > 50) p.Icon = p.Icon.Substring(0, 50);
|
||||
if (p.Url != null && p.Url.Length > 4000) p.Url = p.Url.Substring(0, 4000);
|
||||
DbManager.Create().Save(p);
|
||||
using var db = DbManager.Create();
|
||||
db.Save(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -61,7 +62,8 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual IEnumerable<string> RetrieveMenusByRoleId(string roleId)
|
||||
{
|
||||
var menus = DbManager.Create().Fetch<BootstrapMenu>("select NavigationID as Id from NavigationRole where RoleID = @0", roleId);
|
||||
using var db = DbManager.Create();
|
||||
var menus = db.Fetch<BootstrapMenu>("select NavigationID as Id from NavigationRole where RoleID = @0", roleId);
|
||||
#pragma warning disable CS8619 // 值中的引用类型的为 Null 性与目标类型不匹配。
|
||||
return menus.Select(m => m.Id);
|
||||
#pragma warning restore CS8619 // 值中的引用类型的为 Null 性与目标类型不匹配。
|
||||
|
@ -76,7 +78,7 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
|
||||
{
|
||||
bool ret = false;
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
protected virtual IEnumerable<Message> Retrieves(string userName)
|
||||
{
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
var t = db.Provider.EscapeSqlIdentifier("To");
|
||||
var f = db.Provider.EscapeSqlIdentifier("From");
|
||||
return db.Fetch<Message>($"select m.*, d.Name, u.DisplayName from Messages m left join Dicts d on m.Label = d.Code and d.Category = @0 and d.Define = 0 inner join Users u on m.{f} = u.UserName where {t} = @1 or {f} = @1 order by SendTime desc", "消息标签", userName);
|
||||
|
@ -167,7 +167,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool Save(Message msg)
|
||||
{
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
db.Save(msg);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,8 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool Save(ResetUser user)
|
||||
{
|
||||
DbManager.Create().Save(user);
|
||||
using var db = DbManager.Create();
|
||||
db.Save(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -51,13 +52,21 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public virtual ResetUser RetrieveUserByUserName(string userName) => DbManager.Create().FirstOrDefault<ResetUser>("where UserName = @0 order by ResetTime desc", userName);
|
||||
public virtual ResetUser RetrieveUserByUserName(string userName)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.FirstOrDefault<ResetUser>("where UserName = @0 order by ResetTime desc", userName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<KeyValuePair<DateTime, string>> RetrieveResetReasonsByUserName(string userName) => DbManager.Create().Fetch<ResetUser>("where UserName = @0 order by ResetTime desc", userName).Select(user => new KeyValuePair<DateTime, string>(user.ResetTime, user.Reason));
|
||||
public virtual IEnumerable<KeyValuePair<DateTime, string>> RetrieveResetReasonsByUserName(string userName)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<ResetUser>("where UserName = @0 order by ResetTime desc", userName).Select(user => new KeyValuePair<DateTime, string>(user.ResetTime, user.Reason));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,11 @@ namespace Bootstrap.DataAccess
|
|||
/// 查询所有角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Role> Retrieves() => DbManager.Create().Fetch<Role>();
|
||||
public virtual IEnumerable<Role> Retrieves()
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<Role>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存用户角色关系
|
||||
|
@ -48,7 +52,7 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool SaveByUserId(string userId, IEnumerable<string> roleIds)
|
||||
{
|
||||
var ret = false;
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
@ -70,7 +74,11 @@ namespace Bootstrap.DataAccess
|
|||
/// 查询某个用户所拥有的角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Role> RetrievesByUserId(string userId) => DbManager.Create().Fetch<Role>("select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end Checked from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @0", userId);
|
||||
public virtual IEnumerable<Role> RetrievesByUserId(string userId)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<Role>("select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end Checked from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @0", userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除角色表
|
||||
|
@ -79,9 +87,9 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool Delete(IEnumerable<string> value)
|
||||
{
|
||||
if (!value.Any()) return true;
|
||||
bool ret = false;
|
||||
var ret = false;
|
||||
var ids = string.Join(",", value);
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
@ -110,7 +118,8 @@ namespace Bootstrap.DataAccess
|
|||
if (!string.IsNullOrEmpty(p.RoleName) && p.RoleName.Length > 50) p.RoleName = p.RoleName.Substring(0, 50);
|
||||
if (!string.IsNullOrEmpty(p.Description) && p.Description.Length > 50) p.Description = p.Description.Substring(0, 500);
|
||||
|
||||
DbManager.Create().Save(p);
|
||||
using var db = DbManager.Create();
|
||||
db.Save(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -119,7 +128,11 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Role> RetrievesByMenuId(string menuId) => DbManager.Create().Fetch<Role>("select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end Checked from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @0", menuId);
|
||||
public virtual IEnumerable<Role> RetrievesByMenuId(string menuId)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<Role>("select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end Checked from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @0", menuId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -130,7 +143,7 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool SavaByMenuId(string menuId, IEnumerable<string> roleIds)
|
||||
{
|
||||
var ret = false;
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
db.BeginTransaction();
|
||||
try
|
||||
{
|
||||
|
@ -153,7 +166,11 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Role> RetrievesByGroupId(string groupId) => DbManager.Create().Fetch<Role>("select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end Checked from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @0", groupId);
|
||||
public virtual IEnumerable<Role> RetrievesByGroupId(string groupId)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<Role>("select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end Checked from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @0", groupId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息
|
||||
|
|
|
@ -55,7 +55,11 @@ namespace Bootstrap.DataAccess
|
|||
/// 查询所有任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Task> Retrieves() => DbManager.Create().SkipTake<Task>(0, 1000, "select t.*, u.DisplayName AssignDisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc");
|
||||
public virtual IEnumerable<Task> Retrieves()
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.SkipTake<Task>(0, 1000, "select t.*, u.DisplayName AssignDisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -64,7 +68,8 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool Save(Task task)
|
||||
{
|
||||
DbManager.Create().Save(task);
|
||||
using var db = DbManager.Create();
|
||||
db.Save(task);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,8 +67,8 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="p"></param>
|
||||
public virtual bool Save(Trace p)
|
||||
{
|
||||
if (p == null) throw new ArgumentNullException(nameof(p));
|
||||
DbManager.Create().Save(p);
|
||||
using var db = DbManager.Create();
|
||||
db.Save(p);
|
||||
ClearTraces();
|
||||
return true;
|
||||
}
|
||||
|
@ -92,7 +92,8 @@ namespace Bootstrap.DataAccess
|
|||
if (!string.IsNullOrEmpty(ip)) sql.Where("IP = @0", ip);
|
||||
sql.OrderBy($"{po.Sort} {po.Order}");
|
||||
|
||||
return DbManager.Create().Page<Trace>(po.PageIndex, po.Limit, sql);
|
||||
using var db = DbManager.Create();
|
||||
return db.Page<Trace>(po.PageIndex, po.Limit, sql);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -110,12 +111,14 @@ namespace Bootstrap.DataAccess
|
|||
if (!string.IsNullOrEmpty(ip)) sql.Where("IP = @0", ip);
|
||||
sql.OrderBy("LogTime");
|
||||
|
||||
return DbManager.Create().Fetch<Trace>(sql);
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<Trace>(sql);
|
||||
}
|
||||
|
||||
private static void ClearTraces() => System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
DbManager.Create().Execute("delete from Traces where LogTime < @0", DateTime.Now.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
||||
using var db = DbManager.Create();
|
||||
return db.Execute("delete from Traces where LogTime < @0", DateTime.Now.AddMonths(0 - DictHelper.RetrieveAccessLogPeriod()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,8 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool Authenticate(string userName, string password)
|
||||
{
|
||||
var user = DbManager.Create().SingleOrDefault<User>("select Password, PassSalt from Users where ApprovedTime is not null and UserName = @0", userName);
|
||||
using var db = DbManager.Create();
|
||||
var user = db.SingleOrDefault<User>("select Password, PassSalt from Users where ApprovedTime is not null and UserName = @0", userName);
|
||||
|
||||
return user != null && !string.IsNullOrEmpty(user.PassSalt) && user.Password == LgbCryptography.ComputeHash(password, user.PassSalt);
|
||||
}
|
||||
|
@ -98,7 +99,11 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="userName"></param>
|
||||
/// <param name="app"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool SaveApp(string userName, string app) => DbManager.Create().Update<User>("set App = @1 where UserName = @0", userName, app) == 1;
|
||||
public virtual bool SaveApp(string userName, string app)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Update<User>("set App = @1 where UserName = @0", userName, app) == 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更改密码方法
|
||||
|
@ -115,7 +120,8 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "set Password = @0, PassSalt = @1 where UserName = @2";
|
||||
var passSalt = LgbCryptography.GenerateSalt();
|
||||
var newPassword = LgbCryptography.ComputeHash(newPass, passSalt);
|
||||
ret = DbManager.Create().Update<User>(sql, newPassword, passSalt, userName) == 1;
|
||||
using var db = DbManager.Create();
|
||||
ret = db.Update<User>(sql, newPassword, passSalt, userName) == 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -124,13 +130,21 @@ namespace Bootstrap.DataAccess
|
|||
/// 查询所有用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<User> Retrieves() => DbManager.Create().Fetch<User>("select u.ID, u.UserName, u.DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description, ru.IsReset from Users u left join (select 1 as IsReset, UserName from ResetUsers group by UserName) ru on u.UserName = ru.UserName Where ApprovedTime is not null");
|
||||
public virtual IEnumerable<User> Retrieves()
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<User>("select u.ID, u.UserName, u.DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description, ru.IsReset from Users u left join (select 1 as IsReset, UserName from ResetUsers group by UserName) ru on u.UserName = ru.UserName Where ApprovedTime is not null");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有的新注册用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<User> RetrieveNewUsers() => DbManager.Create().Fetch<User>("select ID, UserName, DisplayName, RegisterTime, Description from Users Where ApprovedTime is null order by RegisterTime desc");
|
||||
public virtual IEnumerable<User> RetrieveNewUsers()
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<User>("select ID, UserName, DisplayName, RegisterTime, Description from Users Where ApprovedTime is null order by RegisterTime desc");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
|
@ -139,8 +153,8 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool Delete(IEnumerable<string> value)
|
||||
{
|
||||
if (!value.Any()) return true;
|
||||
bool ret = false;
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
bool ret;
|
||||
try
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
|
@ -174,7 +188,7 @@ namespace Bootstrap.DataAccess
|
|||
string sql = "set Password = @0, PassSalt = @1 where UserName = @2";
|
||||
var passSalt = LgbCryptography.GenerateSalt();
|
||||
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
@ -208,7 +222,7 @@ namespace Bootstrap.DataAccess
|
|||
user.Password = LgbCryptography.ComputeHash(user.Password, user.PassSalt);
|
||||
user.RegisterTime = DateTime.Now;
|
||||
|
||||
var db = DbManager.Create();
|
||||
using var db = DbManager.Create();
|
||||
bool ret;
|
||||
try
|
||||
{
|
||||
|
@ -240,7 +254,8 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
var passSalt = LgbCryptography.GenerateSalt();
|
||||
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
|
||||
return DbManager.Create().Update<User>("set Password = @1, PassSalt = @2, DisplayName = @3 where ID = @0", id, newPassword, passSalt, displayName) == 1;
|
||||
using var db = DbManager.Create();
|
||||
return db.Update<User>("set Password = @1, PassSalt = @2, DisplayName = @3 where ID = @0", id, newPassword, passSalt, displayName) == 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -249,7 +264,11 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="id"></param>
|
||||
/// <param name="approvedBy"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool Approve(string id, string approvedBy) => DbManager.Create().Update<User>("set ApprovedTime = @1, ApprovedBy = @2 where ID = @0", id, DateTime.Now, approvedBy) == 1;
|
||||
public virtual bool Approve(string id, string approvedBy)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Update<User>("set ApprovedTime = @1, ApprovedBy = @2 where ID = @0", id, DateTime.Now, approvedBy) == 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拒绝新用户方法
|
||||
|
@ -259,8 +278,8 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool Reject(string id, string rejectBy)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
var ret = false;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
@ -284,7 +303,11 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<User> RetrievesByRoleId(string roleId) => DbManager.Create().Fetch<User>("select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end Checked from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @0 where u.ApprovedTime is not null", roleId);
|
||||
public virtual IEnumerable<User> RetrievesByRoleId(string roleId)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<User>("select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end Checked from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @0 where u.ApprovedTime is not null", roleId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色ID保存当前授权用户(插入)
|
||||
|
@ -294,7 +317,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool SaveByRoleId(string roleId, IEnumerable<string> userIds)
|
||||
{
|
||||
bool ret = false;
|
||||
var ret = false;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
|
@ -318,7 +341,11 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<User> RetrievesByGroupId(string groupId) => DbManager.Create().Fetch<User>("select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end Checked from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID = @0 where u.ApprovedTime is not null", groupId);
|
||||
public virtual IEnumerable<User> RetrievesByGroupId(string groupId)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Fetch<User>("select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end Checked from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID = @0 where u.ApprovedTime is not null", groupId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过部门ID保存当前授权用户(插入)
|
||||
|
@ -328,8 +355,8 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool SaveByGroupId(string groupId, IEnumerable<string> userIds)
|
||||
{
|
||||
bool ret = false;
|
||||
var db = DbManager.Create();
|
||||
var ret = false;
|
||||
using var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
@ -353,7 +380,11 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="userName"></param>
|
||||
/// <param name="iconName"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool SaveUserIconByName(string userName, string iconName) => DbManager.Create().Update<User>("set Icon = @1 where UserName = @0", userName, iconName) == 1;
|
||||
public virtual bool SaveUserIconByName(string userName, string iconName)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Update<User>("set Icon = @1 where UserName = @0", userName, iconName) == 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存显示名称方法
|
||||
|
@ -361,7 +392,11 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="userName"></param>
|
||||
/// <param name="displayName"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool SaveDisplayName(string userName, string displayName) => DbManager.Create().Update<User>("set DisplayName = @1 where UserName = @0", userName, displayName) == 1;
|
||||
public virtual bool SaveDisplayName(string userName, string displayName)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Update<User>("set DisplayName = @1 where UserName = @0", userName, displayName) == 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户名更改用户皮肤
|
||||
|
@ -369,7 +404,11 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="userName"></param>
|
||||
/// <param name="cssName"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool SaveUserCssByName(string userName, string cssName) => DbManager.Create().Update<User>("set Css = @1 where UserName = @0", userName, cssName) == 1;
|
||||
public virtual bool SaveUserCssByName(string userName, string cssName)
|
||||
{
|
||||
using var db = DbManager.Create();
|
||||
return db.Update<User>("set Css = @1 where UserName = @0", userName, cssName) == 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得指定用户方法
|
||||
|
|
Loading…
Reference in New Issue