diff --git a/Bootstrap.DataAccess/DbManager.cs b/Bootstrap.DataAccess/DbManager.cs index 87a07614..d7a1f075 100644 --- a/Bootstrap.DataAccess/DbManager.cs +++ b/Bootstrap.DataAccess/DbManager.cs @@ -7,11 +7,6 @@ namespace Bootstrap.DataAccess /// public static class DbManager { - /// - /// - /// - public static IDatabase Db { get { return Create(); } } - /// /// /// diff --git a/Bootstrap.DataAccess/Dict.cs b/Bootstrap.DataAccess/Dict.cs index 2c00ee7b..9eb457ed 100644 --- a/Bootstrap.DataAccess/Dict.cs +++ b/Bootstrap.DataAccess/Dict.cs @@ -20,7 +20,7 @@ namespace Bootstrap.DataAccess { var ids = string.Join(",", value); string sql = $"where ID in ({ids})"; - DbManager.Db.Delete(sql); + DbManager.Create().Delete(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 /// public virtual bool SaveSettings(BootstrapDict dict) { - DbManager.Db.Update("set Code = @Code where Category = @Category and Name = @Name", dict); + DbManager.Create().Update("set Code = @Code where Category = @Category and Name = @Name", dict); return true; } diff --git a/Bootstrap.DataAccess/Exceptions.cs b/Bootstrap.DataAccess/Exceptions.cs index aaafa455..b7a5b1c6 100644 --- a/Bootstrap.DataAccess/Exceptions.cs +++ b/Bootstrap.DataAccess/Exceptions.cs @@ -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))); }); /// @@ -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 /// 查询一周内所有异常 /// /// - public virtual IEnumerable Retrieves() => DbManager.Db.Fetch("select * from Exceptions where LogTime > @0 order by LogTime desc", DateTime.Now.AddDays(-7)); + public virtual IEnumerable Retrieves() => DbManager.Create().Fetch("select * from Exceptions where LogTime > @0 order by LogTime desc", DateTime.Now.AddDays(-7)); /// /// @@ -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(po.PageIndex, po.Limit, sql); + return DbManager.Create().Page(po.PageIndex, po.Limit, sql); } } } diff --git a/Bootstrap.DataAccess/Group.cs b/Bootstrap.DataAccess/Group.cs index 9350df75..b35db99d 100644 --- a/Bootstrap.DataAccess/Group.cs +++ b/Bootstrap.DataAccess/Group.cs @@ -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 /// /// /// - public virtual IEnumerable Retrieves() => DbManager.Db.Fetch("select * from Groups"); + public virtual IEnumerable Retrieves() => DbManager.Create().Fetch("select * from Groups"); /// /// 删除群组信息 @@ -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 /// 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 /// /// /// - public virtual IEnumerable RetrievesByUserId(string userId) => DbManager.Db.Fetch("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 RetrievesByUserId(string userId) => DbManager.Create().Fetch("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); /// /// 根据角色ID指派部门 /// /// /// - public virtual IEnumerable RetrievesByRoleId(string roleId) => DbManager.Db.Fetch("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 RetrievesByRoleId(string roleId) => DbManager.Create().Fetch("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); /// /// 保存用户部门关系 @@ -97,13 +98,13 @@ namespace Bootstrap.DataAccess public virtual bool SaveByUserId(string userId, IEnumerable 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 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; } diff --git a/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs b/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs index 8b06c08e..e3f54743 100644 --- a/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs +++ b/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs @@ -42,6 +42,6 @@ namespace Bootstrap.DataAccess /// /// /// - public static Page RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime) => CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => DbContextManager.Create().RetrievePages(po, startTime, endTime)); + public static Page RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime) => DbContextManager.Create().RetrievePages(po, startTime, endTime); } } diff --git a/Bootstrap.DataAccess/Log.cs b/Bootstrap.DataAccess/Log.cs index f37be3a7..36b7f18d 100644 --- a/Bootstrap.DataAccess/Log.cs +++ b/Bootstrap.DataAccess/Log.cs @@ -50,7 +50,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable Retrieves() => DbManager.Db.Fetch(); + public virtual IEnumerable Retrieves() => DbManager.Create().Fetch("select * from Logs where LogTime > @0 order by LogTime desc", DateTime.Now.AddDays(-7)); /// /// 删除日志信息 @@ -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; } } diff --git a/Bootstrap.DataAccess/Menu.cs b/Bootstrap.DataAccess/Menu.cs index f8f533c2..6dbfb40d 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -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 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; } /// @@ -57,7 +58,7 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveMenusByRoleId(string roleId) { - var menus = DbManager.Db.Fetch("select NavigationID as Id from NavigationRole where RoleID = @0", roleId); + var menus = DbManager.Create().Fetch("select NavigationID as Id from NavigationRole where RoleID = @0", roleId); return menus.Select(m => new { m.Id }); } /// @@ -69,12 +70,12 @@ namespace Bootstrap.DataAccess public virtual bool SaveMenusByRoleId(string roleId, IEnumerable 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; } diff --git a/Bootstrap.DataAccess/Message.cs b/Bootstrap.DataAccess/Message.cs index 155aa8b4..7d532c56 100644 --- a/Bootstrap.DataAccess/Message.cs +++ b/Bootstrap.DataAccess/Message.cs @@ -87,7 +87,7 @@ namespace Bootstrap.DataAccess /// protected virtual IEnumerable 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($"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 = "消息标签" }); diff --git a/Bootstrap.DataAccess/Role.cs b/Bootstrap.DataAccess/Role.cs index ebb2dcbd..947a0ba7 100644 --- a/Bootstrap.DataAccess/Role.cs +++ b/Bootstrap.DataAccess/Role.cs @@ -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 /// 查询所有角色 /// /// - public virtual IEnumerable Retrieves() => DbManager.Db.Fetch(); + public virtual IEnumerable Retrieves() => DbManager.Create().Fetch(); /// /// 保存用户角色关系 @@ -45,13 +46,13 @@ namespace Bootstrap.DataAccess public virtual bool SaveByUserId(string userId, IEnumerable 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 /// 查询某个用户所拥有的角色 /// /// - public virtual IEnumerable RetrievesByUserId(string userId) => DbManager.Db.Fetch("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 RetrievesByUserId(string userId) => DbManager.Create().Fetch("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); /// /// 删除角色表 @@ -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 /// /// /// - public virtual IEnumerable RetrievesByMenuId(string menuId) => DbManager.Db.Fetch("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 RetrievesByMenuId(string menuId) => DbManager.Create().Fetch("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); /// /// @@ -126,13 +127,13 @@ namespace Bootstrap.DataAccess public virtual bool SavaByMenuId(string menuId, IEnumerable 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 /// /// /// - public virtual IEnumerable RetrievesByGroupId(string groupId) => DbManager.Db.Fetch("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 RetrievesByGroupId(string groupId) => DbManager.Create().Fetch("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); /// /// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息 @@ -160,12 +161,12 @@ namespace Bootstrap.DataAccess public virtual bool SaveByGroupId(string groupId, IEnumerable 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; } diff --git a/Bootstrap.DataAccess/Task.cs b/Bootstrap.DataAccess/Task.cs index 0a796cfc..3ac594f5 100644 --- a/Bootstrap.DataAccess/Task.cs +++ b/Bootstrap.DataAccess/Task.cs @@ -52,6 +52,6 @@ namespace Bootstrap.DataAccess /// 查询所有任务 /// /// - public virtual IEnumerable Retrieves() => DbManager.Db.SkipTake(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 Retrieves() => DbManager.Create().SkipTake(0, 1000, "select t.*, u.DisplayName AssignDisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc"); } } diff --git a/Bootstrap.DataAccess/User.cs b/Bootstrap.DataAccess/User.cs index a67a42ce..be168c8f 100644 --- a/Bootstrap.DataAccess/User.cs +++ b/Bootstrap.DataAccess/User.cs @@ -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 /// public virtual bool Authenticate(string userName, string password) { - var user = DbManager.Db.SingleOrDefault("select Password, PassSalt from Users where ApprovedTime is not null and UserName = @0", userName); + var user = DbManager.Create().SingleOrDefault("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(sql, newPassword, passSalt, userName) == 1; + ret = DbManager.Create().Update(sql, newPassword, passSalt, userName) == 1; } return ret; } @@ -105,13 +106,13 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable Retrieves() => DbManager.Db.Fetch("select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null"); + public virtual IEnumerable Retrieves() => DbManager.Create().Fetch("select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null"); /// /// 查询所有的新注册用户 /// /// - public virtual IEnumerable RetrieveNewUsers() => DbManager.Db.Fetch("select ID, UserName, DisplayName, RegisterTime, Description from Users Where ApprovedTime is null order by RegisterTime desc"); + public virtual IEnumerable RetrieveNewUsers() => DbManager.Create().Fetch("select ID, UserName, DisplayName, RegisterTime, Description from Users Where ApprovedTime is null order by RegisterTime desc"); /// /// 删除用户 @@ -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("set Password = @1, PassSalt = @2, DisplayName = @3 where ID = @0", id, newPassword, passSalt, displayName) == 1; + return DbManager.Create().Update("set Password = @1, PassSalt = @2, DisplayName = @3 where ID = @0", id, newPassword, passSalt, displayName) == 1; } /// @@ -194,7 +195,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool Approve(string id, string approvedBy) => DbManager.Db.Update("set ApprovedTime = @1, ApprovedBy = @2 where ID = @0", id, DateTime.Now, approvedBy) == 1; + public virtual bool Approve(string id, string approvedBy) => DbManager.Create().Update("set ApprovedTime = @1, ApprovedBy = @2 where ID = @0", id, DateTime.Now, approvedBy) == 1; /// /// @@ -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 /// /// /// - public virtual IEnumerable RetrievesByRoleId(string roleId) => DbManager.Db.Fetch("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 RetrievesByRoleId(string roleId) => DbManager.Create().Fetch("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); /// /// 通过角色ID保存当前授权用户(插入) @@ -240,13 +241,13 @@ namespace Bootstrap.DataAccess public virtual bool SaveByRoleId(string roleId, IEnumerable 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 /// /// /// - public virtual IEnumerable RetrievesByGroupId(string groupId) => DbManager.Db.Fetch("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 RetrievesByGroupId(string groupId) => DbManager.Create().Fetch("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); /// /// 通过部门ID保存当前授权用户(插入) @@ -274,13 +275,13 @@ namespace Bootstrap.DataAccess public virtual bool SaveByGroupId(string groupId, IEnumerable 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 /// /// /// - public virtual bool SaveUserIconByName(string userName, string iconName) => DbManager.Db.Update("set Icon = @1 where UserName = @0", userName, iconName) == 1; + public virtual bool SaveUserIconByName(string userName, string iconName) => DbManager.Create().Update("set Icon = @1 where UserName = @0", userName, iconName) == 1; /// /// @@ -306,7 +307,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveDisplayName(string userName, string displayName) => DbManager.Db.Update("set DisplayName = @1 where UserName = @0", userName, displayName) == 1; + public virtual bool SaveDisplayName(string userName, string displayName) => DbManager.Create().Update("set DisplayName = @1 where UserName = @0", userName, displayName) == 1; /// /// 根据用户名更改用户皮肤 @@ -314,7 +315,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveUserCssByName(string userName, string cssName) => DbManager.Db.Update("set Css = @1 where UserName = @0", userName, cssName) == 1; + public virtual bool SaveUserCssByName(string userName, string cssName) => DbManager.Create().Update("set Css = @1 where UserName = @0", userName, cssName) == 1; /// ///