重构代码:根据最新版Longbow.Data组件,更改DbManager属性为方法
This commit is contained in:
parent
9aab788ea7
commit
96b52478b9
|
@ -7,11 +7,6 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
public static class DbManager
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static IDatabase Db { get { return Create(); } }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
var ids = string.Join(",", value);
|
||||
string sql = $"where ID in ({ids})";
|
||||
DbManager.Db.Delete<BootstrapDict>(sql);
|
||||
DbManager.Create().Delete<BootstrapDict>(sql);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ namespace Bootstrap.DataAccess
|
|||
if (dict.Name.Length > 50) dict.Name = dict.Name.Substring(0, 50);
|
||||
if (dict.Code.Length > 50) dict.Code = dict.Code.Substring(0, 50);
|
||||
|
||||
DbManager.Db.Save(dict);
|
||||
DbManager.Create().Save(dict);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool SaveSettings(BootstrapDict dict)
|
||||
{
|
||||
DbManager.Db.Update<BootstrapDict>("set Code = @Code where Category = @Category and Name = @Name", dict);
|
||||
DbManager.Create().Update<BootstrapDict>("set Code = @Code where Category = @Category and Name = @Name", dict);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Bootstrap.DataAccess
|
|||
|
||||
private static void ClearExceptions() => System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
DbManager.Db.Execute("delete from Exceptions where LogTime < @0", DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepExceptionsPeriod"], 1)));
|
||||
DbManager.Create().Execute("delete from Exceptions where LogTime < @0", DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepExceptionsPeriod"], 1)));
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
|
@ -79,7 +79,7 @@ namespace Bootstrap.DataAccess
|
|||
if (ex == null) throw new ArgumentNullException(nameof(ex));
|
||||
|
||||
var errorPage = additionalInfo?["ErrorPage"] ?? (ex.GetType().Name.Length > 50 ? ex.GetType().Name.Substring(0, 50) : ex.GetType().Name);
|
||||
DbManager.Db.Insert(new Exceptions()
|
||||
DbManager.Create().Insert(new Exceptions()
|
||||
{
|
||||
AppDomainName = AppDomain.CurrentDomain.FriendlyName,
|
||||
ErrorPage = errorPage,
|
||||
|
@ -98,7 +98,7 @@ namespace Bootstrap.DataAccess
|
|||
/// 查询一周内所有异常
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Exceptions> Retrieves() => DbManager.Db.Fetch<Exceptions>("select * from Exceptions where LogTime > @0 order by LogTime desc", DateTime.Now.AddDays(-7));
|
||||
public virtual IEnumerable<Exceptions> Retrieves() => DbManager.Create().Fetch<Exceptions>("select * from Exceptions where LogTime > @0 order by LogTime desc", DateTime.Now.AddDays(-7));
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -116,7 +116,7 @@ namespace Bootstrap.DataAccess
|
|||
if (startTime == null && endTime == null) sql.Append("where LogTime > @0", DateTime.Today.AddDays(-7));
|
||||
sql.Append("order by @0", $"{po.Sort} {po.Order}");
|
||||
|
||||
return DbManager.Db.Page<Exceptions>(po.PageIndex, po.Limit, sql);
|
||||
return DbManager.Create().Page<Exceptions>(po.PageIndex, po.Limit, sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Bootstrap.Security.DataAccess;
|
||||
using Longbow.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -35,7 +36,7 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Group> Retrieves() => DbManager.Db.Fetch<Group>("select * from Groups");
|
||||
public virtual IEnumerable<Group> Retrieves() => DbManager.Create().Fetch<Group>("select * from Groups");
|
||||
|
||||
/// <summary>
|
||||
/// 删除群组信息
|
||||
|
@ -45,7 +46,7 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
bool ret = false;
|
||||
var ids = string.Join(",", value);
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
@ -70,7 +71,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool Save(Group p)
|
||||
{
|
||||
DbManager.Db.Save(p);
|
||||
DbManager.Create().Save(p);
|
||||
return !p.Id.IsNullOrEmpty();
|
||||
}
|
||||
|
||||
|
@ -79,14 +80,14 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Group> RetrievesByUserId(string userId) => DbManager.Db.Fetch<Group>("select g.ID, g.GroupName, g.Description, case ug.GroupID when g.ID then 'checked' else '' end Checked from Groups g left join UserGroup ug on g.ID = ug.GroupID and UserID = @0", userId);
|
||||
public virtual IEnumerable<Group> RetrievesByUserId(string userId) => DbManager.Create().Fetch<Group>("select g.ID, g.GroupName, g.Description, case ug.GroupID when g.ID then 'checked' else '' end Checked from Groups g left join UserGroup ug on g.ID = ug.GroupID and UserID = @0", userId);
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色ID指派部门
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Group> RetrievesByRoleId(string roleId) => DbManager.Db.Fetch<Group>("select g.ID, g.GroupName, g.Description, case rg.GroupID when g.ID then 'checked' else '' end Checked from Groups g left join RoleGroup rg on g.ID = rg.GroupID and RoleID = @0", roleId);
|
||||
public virtual IEnumerable<Group> RetrievesByRoleId(string roleId) => DbManager.Create().Fetch<Group>("select g.ID, g.GroupName, g.Description, case rg.GroupID when g.ID then 'checked' else '' end Checked from Groups g left join RoleGroup rg on g.ID = rg.GroupID and RoleID = @0", roleId);
|
||||
|
||||
/// <summary>
|
||||
/// 保存用户部门关系
|
||||
|
@ -97,13 +98,13 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool SaveByUserId(string userId, IEnumerable<string> groupIds)
|
||||
{
|
||||
var ret = false;
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
//删除用户部门表中该用户所有的部门关系
|
||||
db.Execute("delete from UserGroup where UserID = @0", userId);
|
||||
db.InsertBulk("UserGroup", groupIds.Select(g => new { UserID = userId, GroupID = g }));
|
||||
db.InsertBatch("UserGroup", groupIds.Select(g => new { UserID = userId, GroupID = g }));
|
||||
db.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
|
@ -124,13 +125,13 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool SaveByRoleId(string roleId, IEnumerable<string> groupIds)
|
||||
{
|
||||
bool ret = false;
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
//删除角色部门表该角色所有的部门
|
||||
db.Execute("delete from RoleGroup where RoleID = @0", roleId);
|
||||
db.InsertBulk("RoleGroup", groupIds.Select(g => new { RoleID = roleId, GroupID = g }));
|
||||
db.InsertBatch("RoleGroup", groupIds.Select(g => new { RoleID = roleId, GroupID = g }));
|
||||
db.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,6 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="startTime"></param>
|
||||
/// <param name="endTime"></param>
|
||||
/// <returns></returns>
|
||||
public static Page<Exceptions> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime) => CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => DbContextManager.Create<Exceptions>().RetrievePages(po, startTime, endTime));
|
||||
public static Page<Exceptions> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime) => DbContextManager.Create<Exceptions>().RetrievePages(po, startTime, endTime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="tId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Log> Retrieves() => DbManager.Db.Fetch<Log>();
|
||||
public virtual IEnumerable<Log> Retrieves() => DbManager.Create().Fetch<Log>("select * from Logs where LogTime > @0 order by LogTime desc", DateTime.Now.AddDays(-7));
|
||||
|
||||
/// <summary>
|
||||
/// 删除日志信息
|
||||
|
@ -62,7 +62,7 @@ namespace Bootstrap.DataAccess
|
|||
System.Threading.Tasks.Task.Run(() =>
|
||||
{
|
||||
var dtm = DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepLogsPeriod"], 1));
|
||||
DbManager.Db.Execute("delete from Logs where LogTime < @0", dtm);
|
||||
DbManager.Create().Execute("delete from Logs where LogTime < @0", dtm);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ namespace Bootstrap.DataAccess
|
|||
if (p == null) throw new ArgumentNullException(nameof(p));
|
||||
DeleteLogAsync();
|
||||
p.LogTime = DateTime.Now;
|
||||
DbManager.Db.Save(p);
|
||||
DbManager.Create().Save(p);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Bootstrap.Security;
|
||||
using Bootstrap.Security.DataAccess;
|
||||
using Longbow.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -18,7 +19,7 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool Delete(IEnumerable<string> value)
|
||||
{
|
||||
var ret = false;
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
|
@ -47,7 +48,7 @@ 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.Db.Save(p);
|
||||
DbManager.Create().Save(p);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -57,7 +58,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual IEnumerable<object> RetrieveMenusByRoleId(string roleId)
|
||||
{
|
||||
var menus = DbManager.Db.Fetch<BootstrapMenu>("select NavigationID as Id from NavigationRole where RoleID = @0", roleId);
|
||||
var menus = DbManager.Create().Fetch<BootstrapMenu>("select NavigationID as Id from NavigationRole where RoleID = @0", roleId);
|
||||
return menus.Select(m => new { m.Id });
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -69,12 +70,12 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
|
||||
{
|
||||
bool ret = false;
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
db.Execute("delete from NavigationRole where RoleID = @0", roleId);
|
||||
db.InsertBulk("NavigationRole", menuIds.Select(g => new { NavigationID = g, RoleID = roleId }));
|
||||
db.InsertBatch("NavigationRole", menuIds.Select(g => new { NavigationID = g, RoleID = roleId }));
|
||||
db.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
protected virtual IEnumerable<Message> Retrieves(string userName)
|
||||
{
|
||||
var db = DbManager.Db;
|
||||
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 = @Category and d.Define = 0 inner join Users u on m.{f} = u.UserName where {t} = @UserName or {f} = @UserName order by SendTime desc", new { UserName = userName, Category = "消息标签" });
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Bootstrap.Security.DataAccess;
|
||||
using Longbow.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -34,7 +35,7 @@ namespace Bootstrap.DataAccess
|
|||
/// 查询所有角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Role> Retrieves() => DbManager.Db.Fetch<Role>();
|
||||
public virtual IEnumerable<Role> Retrieves() => DbManager.Create().Fetch<Role>();
|
||||
|
||||
/// <summary>
|
||||
/// 保存用户角色关系
|
||||
|
@ -45,13 +46,13 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool SaveByUserId(string userId, IEnumerable<string> roleIds)
|
||||
{
|
||||
var ret = false;
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
// delete user from config table
|
||||
db.Execute("delete from UserRole where UserID = @0", userId);
|
||||
db.InsertBulk("UserRole", roleIds.Select(g => new { UserID = userId, RoleID = g }));
|
||||
db.InsertBatch("UserRole", roleIds.Select(g => new { UserID = userId, RoleID = g }));
|
||||
db.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
|
@ -67,7 +68,7 @@ namespace Bootstrap.DataAccess
|
|||
/// 查询某个用户所拥有的角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Role> RetrievesByUserId(string userId) => DbManager.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);
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// 删除角色表
|
||||
|
@ -77,7 +78,7 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
bool ret = false;
|
||||
var ids = string.Join(",", value);
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
@ -106,7 +107,7 @@ 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.Db.Save(p);
|
||||
DbManager.Create().Save(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -115,7 +116,7 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="menuId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Role> RetrievesByMenuId(string menuId) => DbManager.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);
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -126,13 +127,13 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool SavaByMenuId(string menuId, IEnumerable<string> roleIds)
|
||||
{
|
||||
var ret = false;
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
db.BeginTransaction();
|
||||
try
|
||||
{
|
||||
// delete role from config table
|
||||
db.Execute("delete from NavigationRole where NavigationID = @0", menuId);
|
||||
db.InsertBulk("NavigationRole", roleIds.Select(g => new { NavigationID = menuId, RoleID = g }));
|
||||
db.InsertBatch("NavigationRole", roleIds.Select(g => new { NavigationID = menuId, RoleID = g }));
|
||||
db.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
|
@ -149,7 +150,7 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Role> RetrievesByGroupId(string groupId) => DbManager.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);
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息
|
||||
|
@ -160,12 +161,12 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool SaveByGroupId(string groupId, IEnumerable<string> roleIds)
|
||||
{
|
||||
var ret = false;
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
// delete user from config table
|
||||
db.Execute("delete from RoleGroup where GroupID = @0", groupId);
|
||||
db.InsertBulk("RoleGroup", roleIds.Select(g => new { GroupID = groupId, RoleID = g }));
|
||||
db.InsertBatch("RoleGroup", roleIds.Select(g => new { GroupID = groupId, RoleID = g }));
|
||||
db.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
|
|
|
@ -52,6 +52,6 @@ namespace Bootstrap.DataAccess
|
|||
/// 查询所有任务
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<Task> Retrieves() => DbManager.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");
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Bootstrap.Security;
|
||||
using Bootstrap.Security.DataAccess;
|
||||
using Longbow.Data;
|
||||
using Longbow.Security.Cryptography;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -75,7 +76,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public virtual bool Authenticate(string userName, string password)
|
||||
{
|
||||
var user = DbManager.Db.SingleOrDefault<User>("select Password, PassSalt from Users where ApprovedTime is not null and UserName = @0", userName);
|
||||
var user = DbManager.Create().SingleOrDefault<User>("select Password, PassSalt from Users where ApprovedTime is not null and UserName = @0", userName);
|
||||
|
||||
return !string.IsNullOrEmpty(user.PassSalt) && user.Password == LgbCryptography.ComputeHash(password, user.PassSalt);
|
||||
}
|
||||
|
@ -95,7 +96,7 @@ 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.Db.Update<User>(sql, newPassword, passSalt, userName) == 1;
|
||||
ret = DbManager.Create().Update<User>(sql, newPassword, passSalt, userName) == 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -105,13 +106,13 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<User> Retrieves() => DbManager.Db.Fetch<User>("select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
|
||||
public virtual IEnumerable<User> Retrieves() => DbManager.Create().Fetch<User>("select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有的新注册用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<User> RetrieveNewUsers() => DbManager.Db.Fetch<User>("select ID, UserName, DisplayName, RegisterTime, Description from Users Where ApprovedTime is null order by RegisterTime desc");
|
||||
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");
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
|
@ -121,7 +122,7 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
if (!value.Any()) return true;
|
||||
bool ret = false;
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
var ids = string.Join(",", value);
|
||||
|
@ -154,7 +155,7 @@ namespace Bootstrap.DataAccess
|
|||
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
|
||||
p.RegisterTime = DateTime.Now;
|
||||
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
@ -185,7 +186,7 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
var passSalt = LgbCryptography.GenerateSalt();
|
||||
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
|
||||
return DbManager.Db.Update<User>("set Password = @1, PassSalt = @2, DisplayName = @3 where ID = @0", id, newPassword, passSalt, displayName) == 1;
|
||||
return DbManager.Create().Update<User>("set Password = @1, PassSalt = @2, DisplayName = @3 where ID = @0", id, newPassword, passSalt, displayName) == 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -194,7 +195,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="id"></param>
|
||||
/// <param name="approvedBy"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool Approve(string id, string approvedBy) => DbManager.Db.Update<User>("set ApprovedTime = @1, ApprovedBy = @2 where ID = @0", id, DateTime.Now, approvedBy) == 1;
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -205,7 +206,7 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool Reject(string id, string rejectBy)
|
||||
{
|
||||
var ret = false;
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
|
@ -229,7 +230,7 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<User> RetrievesByRoleId(string roleId) => DbManager.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);
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色ID保存当前授权用户(插入)
|
||||
|
@ -240,13 +241,13 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool SaveByRoleId(string roleId, IEnumerable<string> userIds)
|
||||
{
|
||||
bool ret = false;
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
//删除用户角色表该角色所有的用户
|
||||
db.Execute("delete from UserRole where RoleID = @0", roleId);
|
||||
db.InsertBulk("UserRole", userIds.Select(g => new { UserID = g, RoleID = roleId }));
|
||||
db.InsertBatch("UserRole", userIds.Select(g => new { UserID = g, RoleID = roleId }));
|
||||
db.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
|
@ -263,7 +264,7 @@ namespace Bootstrap.DataAccess
|
|||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
public virtual IEnumerable<User> RetrievesByGroupId(string groupId) => DbManager.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);
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// 通过部门ID保存当前授权用户(插入)
|
||||
|
@ -274,13 +275,13 @@ namespace Bootstrap.DataAccess
|
|||
public virtual bool SaveByGroupId(string groupId, IEnumerable<string> userIds)
|
||||
{
|
||||
bool ret = false;
|
||||
var db = DbManager.Db;
|
||||
var db = DbManager.Create();
|
||||
try
|
||||
{
|
||||
db.BeginTransaction();
|
||||
//删除用户角色表该角色所有的用户
|
||||
db.Execute("delete from UserGroup where GroupID = @0", groupId);
|
||||
db.InsertBulk("UserGroup", userIds.Select(g => new { UserID = g, GroupID = groupId }));
|
||||
db.InsertBatch("UserGroup", userIds.Select(g => new { UserID = g, GroupID = groupId }));
|
||||
db.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
|
@ -298,7 +299,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="userName"></param>
|
||||
/// <param name="iconName"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool SaveUserIconByName(string userName, string iconName) => DbManager.Db.Update<User>("set Icon = @1 where UserName = @0", userName, iconName) == 1;
|
||||
public virtual bool SaveUserIconByName(string userName, string iconName) => DbManager.Create().Update<User>("set Icon = @1 where UserName = @0", userName, iconName) == 1;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -306,7 +307,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="userName"></param>
|
||||
/// <param name="displayName"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool SaveDisplayName(string userName, string displayName) => DbManager.Db.Update<User>("set DisplayName = @1 where UserName = @0", userName, displayName) == 1;
|
||||
public virtual bool SaveDisplayName(string userName, string displayName) => DbManager.Create().Update<User>("set DisplayName = @1 where UserName = @0", userName, displayName) == 1;
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户名更改用户皮肤
|
||||
|
@ -314,7 +315,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="userName"></param>
|
||||
/// <param name="cssName"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool SaveUserCssByName(string userName, string cssName) => DbManager.Db.Update<User>("set Css = @1 where UserName = @0", userName, cssName) == 1;
|
||||
public virtual bool SaveUserCssByName(string userName, string cssName) => DbManager.Create().Update<User>("set Css = @1 where UserName = @0", userName, cssName) == 1;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue