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
///
///
- 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;
///
///