diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index d2f07f4e..b03f96ad 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/Bootstrap.Admin/Controllers/Api/DictsController.cs b/Bootstrap.Admin/Controllers/Api/DictsController.cs index a88f89e1..f047226c 100644 --- a/Bootstrap.Admin/Controllers/Api/DictsController.cs +++ b/Bootstrap.Admin/Controllers/Api/DictsController.cs @@ -32,7 +32,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpPost] public bool Post([FromBody]BootstrapDict value) { - return DictHelper.SaveDict(value); + return DictHelper.Save(value); } /// /// @@ -42,7 +42,7 @@ namespace Bootstrap.Admin.Controllers.Api [Authorize(Roles = "Administrators")] public bool Delete([FromBody]IEnumerable value) { - return DictHelper.DeleteDict(value); + return DictHelper.Delete(value); } } } \ No newline at end of file diff --git a/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs b/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs index aeb509ce..582617ad 100644 --- a/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs +++ b/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs @@ -24,8 +24,9 @@ namespace Bootstrap.Admin.Controllers.Api [HttpGet] public QueryData Get([FromQuery]QueryExceptionOption value) { - return value.RetrieveData(); + return value.Retrieves(); } + /// /// /// @@ -39,6 +40,7 @@ namespace Bootstrap.Admin.Controllers.Api .Where(f => Path.GetExtension(f).Equals(".log", StringComparison.OrdinalIgnoreCase)) .Select(f => Path.GetFileNameWithoutExtension(f)).OrderByDescending(s => s); } + /// /// /// @@ -67,6 +69,7 @@ namespace Bootstrap.Admin.Controllers.Api } return new JsonResult(sb.ToString()); } + /// /// /// diff --git a/Bootstrap.Admin/Controllers/Api/GroupsController.cs b/Bootstrap.Admin/Controllers/Api/GroupsController.cs index 1590edde..46b9389a 100644 --- a/Bootstrap.Admin/Controllers/Api/GroupsController.cs +++ b/Bootstrap.Admin/Controllers/Api/GroupsController.cs @@ -33,7 +33,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpGet("{id}")] public Group Get(string id) { - return GroupHelper.RetrieveGroups().FirstOrDefault(t => t.Id == id); + return GroupHelper.Retrieves().FirstOrDefault(t => t.Id == id); } /// @@ -43,7 +43,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpPost] public bool Post([FromBody]Group value) { - return GroupHelper.SaveGroup(value); + return GroupHelper.Save(value); } /// @@ -53,7 +53,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpDelete] public bool Delete([FromBody]IEnumerable value) { - return GroupHelper.DeleteGroup(value); + return GroupHelper.Delete(value); } /// @@ -69,10 +69,10 @@ namespace Bootstrap.Admin.Controllers.Api switch (type) { case "user": - ret = GroupHelper.RetrieveGroupsByUserId(id); + ret = GroupHelper.RetrievesByUserId(id); break; case "role": - ret = GroupHelper.RetrieveGroupsByRoleId(id); + ret = GroupHelper.RetrievesByRoleId(id); break; default: break; @@ -94,10 +94,10 @@ namespace Bootstrap.Admin.Controllers.Api switch (type) { case "user": - ret = GroupHelper.SaveGroupsByUserId(id, groupIds); + ret = GroupHelper.SaveByUserId(id, groupIds); break; case "role": - ret = GroupHelper.SaveGroupsByRoleId(id, groupIds); + ret = GroupHelper.SaveByRoleId(id, groupIds); break; default: break; diff --git a/Bootstrap.Admin/Controllers/Api/LogsController.cs b/Bootstrap.Admin/Controllers/Api/LogsController.cs index f0fdb56b..f7d177d2 100644 --- a/Bootstrap.Admin/Controllers/Api/LogsController.cs +++ b/Bootstrap.Admin/Controllers/Api/LogsController.cs @@ -31,7 +31,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpGet("{id}")] public Log Get(string id) { - return LogHelper.RetrieveLogs().FirstOrDefault(t => t.Id == id); + return LogHelper.Retrieves().FirstOrDefault(t => t.Id == id); } /// /// @@ -44,7 +44,7 @@ namespace Bootstrap.Admin.Controllers.Api value.ClientAgent = Request.Headers["User-Agent"]; value.ClientIp = HttpContext.Connection.RemoteIpAddress.ToString(); value.UserName = User.Identity.Name; - return LogHelper.SaveLog(value); + return LogHelper.Save(value); } } } \ No newline at end of file diff --git a/Bootstrap.Admin/Controllers/Api/MenusController.cs b/Bootstrap.Admin/Controllers/Api/MenusController.cs index 5ea99569..c38dc5a5 100644 --- a/Bootstrap.Admin/Controllers/Api/MenusController.cs +++ b/Bootstrap.Admin/Controllers/Api/MenusController.cs @@ -32,7 +32,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpPost] public bool Post([FromBody]BootstrapMenu value) { - return MenuHelper.SaveMenu(value); + return MenuHelper.Save(value); } /// @@ -42,7 +42,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpDelete] public bool Delete([FromBody]IEnumerable value) { - return MenuHelper.DeleteMenu(value); + return MenuHelper.Delete(value); } /// diff --git a/Bootstrap.Admin/Controllers/Api/NewController.cs b/Bootstrap.Admin/Controllers/Api/NewController.cs index aeac82a0..cfc59926 100644 --- a/Bootstrap.Admin/Controllers/Api/NewController.cs +++ b/Bootstrap.Admin/Controllers/Api/NewController.cs @@ -38,11 +38,11 @@ namespace Bootstrap.Admin.Controllers var ret = false; if (value.UserStatus == UserStates.ApproveUser) { - ret = UserHelper.ApproveUser(value.Id, User.Identity.Name); + ret = UserHelper.Approve(value.Id, User.Identity.Name); } else if (value.UserStatus == UserStates.RejectUser) { - ret = UserHelper.RejectUser(value.Id, User.Identity.Name); + ret = UserHelper.Reject(value.Id, User.Identity.Name); } return ret; } diff --git a/Bootstrap.Admin/Controllers/Api/NotificationsController.cs b/Bootstrap.Admin/Controllers/Api/NotificationsController.cs index 886ab404..0b85ce60 100644 --- a/Bootstrap.Admin/Controllers/Api/NotificationsController.cs +++ b/Bootstrap.Admin/Controllers/Api/NotificationsController.cs @@ -36,18 +36,18 @@ namespace Bootstrap.Admin.Controllers.Api }); // Tasks - var task = TaskHelper.RetrieveTasks(); + var task = TaskHelper.Retrieves(); var tasksCount = task.Count(); //Message - var message = MessageHelper.RetrieveMessagesHeader(User.Identity.Name); + var message = MessageHelper.Retrieves(User.Identity.Name); var messagesCount = message.Count(); message = message.Take(6); message.AsParallel().ForAll(m => m.FromIcon = Url.Content(m.FromIcon)); //Apps - var apps = ExceptionsHelper.RetrieveExceptions().Where(n => n.ExceptionType != "Longbow.Data.DBAccessException"); + var apps = ExceptionsHelper.Retrieves().Where(n => n.ExceptionType != "Longbow.Data.DBAccessException"); var appExceptionsCount = apps.Count(); apps = apps.Take(6); @@ -62,7 +62,7 @@ namespace Bootstrap.Admin.Controllers.Api }); //Dbs - var dbs = ExceptionsHelper.RetrieveExceptions().Where(n => n.ExceptionType == "Longbow.Data.DBAccessException"); + var dbs = ExceptionsHelper.Retrieves().Where(n => n.ExceptionType == "Longbow.Data.DBAccessException"); var dbExceptionsCount = dbs.Count(); dbs = dbs.Take(6); diff --git a/Bootstrap.Admin/Controllers/Api/ProfilesController.cs b/Bootstrap.Admin/Controllers/Api/ProfilesController.cs index 82d06c22..dc83e54e 100644 --- a/Bootstrap.Admin/Controllers/Api/ProfilesController.cs +++ b/Bootstrap.Admin/Controllers/Api/ProfilesController.cs @@ -33,7 +33,7 @@ namespace Bootstrap.Admin.Controllers.Api if (files.Files.Count > 0) { var uploadFile = files.Files[0]; - var webSiteUrl = DictHelper.RetrieveIconFolderPath().Code; + var webSiteUrl = DictHelper.RetrieveIconFolderPath(); fileName = string.Format("{0}{1}", userName, Path.GetExtension(uploadFile.FileName)); var fileUrl = string.Format("{0}{1}", webSiteUrl, fileName); var filePath = Path.Combine(env.WebRootPath, webSiteUrl.Replace("~", string.Empty).Replace("/", "\\").TrimStart('\\') + fileName); diff --git a/Bootstrap.Admin/Controllers/Api/RegisterController.cs b/Bootstrap.Admin/Controllers/Api/RegisterController.cs index fab2b2f8..0c593c4b 100644 --- a/Bootstrap.Admin/Controllers/Api/RegisterController.cs +++ b/Bootstrap.Admin/Controllers/Api/RegisterController.cs @@ -3,7 +3,6 @@ using Longbow.Web.SignalR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; -using System; using System.Linq; using System.Threading.Tasks; @@ -36,7 +35,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpPost] public async Task Post([FromServices]IHubContext hub, [FromBody]User user) { - var ret = UserHelper.SaveUser(user); + var ret = UserHelper.Save(user); if (ret) await SignalRManager.Send(hub.Clients.All, new MessageBody() { Category = "Users", Message = string.Format("{0}-{1}", user.UserName, user.Description) }); return ret; } diff --git a/Bootstrap.Admin/Controllers/Api/RolesController.cs b/Bootstrap.Admin/Controllers/Api/RolesController.cs index 0fc7d618..2520c280 100644 --- a/Bootstrap.Admin/Controllers/Api/RolesController.cs +++ b/Bootstrap.Admin/Controllers/Api/RolesController.cs @@ -38,13 +38,13 @@ namespace Bootstrap.Admin.Controllers.Api switch (type) { case "user": - ret = RoleHelper.RetrieveRolesByUserId(id); + ret = RoleHelper.RetrievesByUserId(id); break; case "group": - ret = RoleHelper.RetrieveRolesByGroupId(id); + ret = RoleHelper.RetrievesByGroupId(id); break; case "menu": - ret = RoleHelper.RetrieveRolesByMenuId(id); + ret = RoleHelper.RetrievesByMenuId(id); break; default: break; @@ -65,13 +65,13 @@ namespace Bootstrap.Admin.Controllers.Api switch (type) { case "user": - ret = RoleHelper.SaveRolesByUserId(id, roleIds); + ret = RoleHelper.SaveByUserId(id, roleIds); break; case "group": - ret = RoleHelper.SaveRolesByGroupId(id, roleIds); + ret = RoleHelper.SaveByGroupId(id, roleIds); break; case "menu": - ret = RoleHelper.SavaRolesByMenuId(id, roleIds); + ret = RoleHelper.SavaByMenuId(id, roleIds); break; default: break; @@ -85,7 +85,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpPost] public bool Post([FromBody]Role value) { - return RoleHelper.SaveRole(value); + return RoleHelper.Save(value); } /// /// @@ -94,7 +94,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpDelete] public bool Delete([FromBody]IEnumerable value) { - return RoleHelper.DeleteRole(value); + return RoleHelper.Delete(value); } } } diff --git a/Bootstrap.Admin/Controllers/Api/TasksController.cs b/Bootstrap.Admin/Controllers/Api/TasksController.cs index 02fdd788..ef5296d6 100644 --- a/Bootstrap.Admin/Controllers/Api/TasksController.cs +++ b/Bootstrap.Admin/Controllers/Api/TasksController.cs @@ -18,7 +18,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpGet] public IEnumerable Get() { - return TaskHelper.RetrieveTasks(); + return TaskHelper.Retrieves(); } } } \ No newline at end of file diff --git a/Bootstrap.Admin/Controllers/Api/UsersController.cs b/Bootstrap.Admin/Controllers/Api/UsersController.cs index 7d076a9d..70c812d0 100644 --- a/Bootstrap.Admin/Controllers/Api/UsersController.cs +++ b/Bootstrap.Admin/Controllers/Api/UsersController.cs @@ -61,7 +61,7 @@ namespace Bootstrap.Admin.Controllers.Api switch (type) { case "role": - return UserHelper.RetrieveUsersByRoleId(id).Select(p => new + return UserHelper.RetrievesByRoleId(id).Select(p => new { p.Id, p.DisplayName, @@ -69,7 +69,7 @@ namespace Bootstrap.Admin.Controllers.Api p.Checked }); case "group": - return UserHelper.RetrieveUsersByGroupId(id).ToList(); + return UserHelper.RetrievesByGroupId(id).ToList(); default: return null; } @@ -87,11 +87,11 @@ namespace Bootstrap.Admin.Controllers.Api value.Description = string.Format("管理员{0}创建用户", User.Identity.Name); value.ApprovedBy = User.Identity.Name; value.ApprovedTime = DateTime.Now; - ret = UserHelper.SaveUser(value); + ret = UserHelper.Save(value); } else { - ret = UserHelper.UpdateUser(value.Id, value.Password, value.DisplayName); + ret = UserHelper.Update(value.Id, value.Password, value.DisplayName); } return ret; } @@ -109,10 +109,10 @@ namespace Bootstrap.Admin.Controllers.Api switch (type) { case "role": - ret = UserHelper.SaveUsersByRoleId(id, userIds); + ret = UserHelper.SaveByRoleId(id, userIds); break; case "group": - ret = UserHelper.SaveUsersByGroupId(id, userIds); + ret = UserHelper.SaveByGroupId(id, userIds); break; default: break; @@ -126,7 +126,7 @@ namespace Bootstrap.Admin.Controllers.Api [HttpDelete] public bool Delete([FromBody]IEnumerable value) { - return UserHelper.DeleteUser(value); + return UserHelper.Delete(value); } /// /// diff --git a/Bootstrap.Admin/Models/HeaderBarModel.cs b/Bootstrap.Admin/Models/HeaderBarModel.cs index 57c67a34..72da4437 100644 --- a/Bootstrap.Admin/Models/HeaderBarModel.cs +++ b/Bootstrap.Admin/Models/HeaderBarModel.cs @@ -1,4 +1,5 @@ using Bootstrap.DataAccess; +using System.IO; using System.Security.Principal; namespace Bootstrap.Admin.Models @@ -15,7 +16,7 @@ namespace Bootstrap.Admin.Models public HeaderBarModel(IIdentity identity) { var user = UserHelper.RetrieveUserByUserName(identity.Name); - Icon = user.Icon; + Icon = Path.Combine(DictHelper.RetrieveIconFolderPath(), string.IsNullOrEmpty(user.Icon) ? DictHelper.RetrieveDefaultIcon() : user.Icon); DisplayName = user.DisplayName; UserName = user.UserName; if (!string.IsNullOrEmpty(user.Css)) Theme = user.Css; diff --git a/Bootstrap.Admin/Query/QueryExceptionOption.cs b/Bootstrap.Admin/Query/QueryExceptionOption.cs index d41556fe..60f768fb 100644 --- a/Bootstrap.Admin/Query/QueryExceptionOption.cs +++ b/Bootstrap.Admin/Query/QueryExceptionOption.cs @@ -22,37 +22,12 @@ namespace Bootstrap.Admin.Query /// /// /// - public QueryData RetrieveData() + public QueryData Retrieves() { - var data = ExceptionsHelper.RetrieveExceptions(); - if (StartTime > DateTime.MinValue) - { - data = data.Where(t => t.LogTime > StartTime.Value); - } - if (EndTime > DateTime.MinValue) - { - data = data.Where(t => t.LogTime < EndTime.Value.AddDays(1)); - } + var data = ExceptionsHelper.RetrievePages(this, StartTime, EndTime); var ret = new QueryData(); - ret.total = data.Count(); - switch (Sort) - { - case "ErrorPage": - data = Order == "asc" ? data.OrderBy(t => t.ErrorPage) : data.OrderByDescending(t => t.ErrorPage); - break; - case "UserID": - data = Order == "asc" ? data.OrderBy(t => t.UserId) : data.OrderByDescending(t => t.UserId); - break; - case "UserIp": - data = Order == "asc" ? data.OrderBy(t => t.UserIp) : data.OrderByDescending(t => t.UserIp); - break; - case "LogTime": - data = Order == "asc" ? data.OrderBy(t => t.LogTime) : data.OrderByDescending(t => t.LogTime); - break; - default: - break; - } - ret.rows = data.Skip(Offset).Take(Limit).Select(ex => new { ex.UserId, ex.UserIp, ex.LogTime, ex.Message, ex.ErrorPage, ex.ExceptionType }); + ret.total = (int)data.TotalItems; + ret.rows = data.Items.Select(ex => new { ex.UserId, ex.UserIp, ex.LogTime, ex.Message, ex.ErrorPage, ex.ExceptionType }); return ret; } } diff --git a/Bootstrap.Admin/Query/QueryGroupOption.cs b/Bootstrap.Admin/Query/QueryGroupOption.cs index e09d4cfb..66c95645 100644 --- a/Bootstrap.Admin/Query/QueryGroupOption.cs +++ b/Bootstrap.Admin/Query/QueryGroupOption.cs @@ -24,7 +24,7 @@ namespace Bootstrap.Admin.Query public QueryData RetrieveData() { // int limit, int offset, string name, string price, string sort, string order - var data = GroupHelper.RetrieveGroups(); + var data = GroupHelper.Retrieves(); if (!string.IsNullOrEmpty(GroupName)) { data = data.Where(t => t.GroupName.Contains(GroupName)); diff --git a/Bootstrap.Admin/Query/QueryLogOption.cs b/Bootstrap.Admin/Query/QueryLogOption.cs index 6c718bff..926c7775 100644 --- a/Bootstrap.Admin/Query/QueryLogOption.cs +++ b/Bootstrap.Admin/Query/QueryLogOption.cs @@ -28,7 +28,7 @@ namespace Bootstrap.Admin.Query /// public QueryData RetrieveData() { - var data = LogHelper.RetrieveLogs(); + var data = LogHelper.Retrieves(); if (!string.IsNullOrEmpty(OperateType)) { data = data.Where(t => t.CRUD.ToString().Contains(OperateType)); diff --git a/Bootstrap.Admin/Query/QueryMenuOption.cs b/Bootstrap.Admin/Query/QueryMenuOption.cs index 014731c6..c696cf64 100644 --- a/Bootstrap.Admin/Query/QueryMenuOption.cs +++ b/Bootstrap.Admin/Query/QueryMenuOption.cs @@ -71,8 +71,8 @@ namespace Bootstrap.Admin.Query case "IsResource": data = Order == "asc" ? data.OrderBy(t => t.IsResource) : data.OrderByDescending(t => t.IsResource); break; - case "ApplicationCode": - data = Order == "asc" ? data.OrderBy(t => t.ApplicationCode) : data.OrderByDescending(t => t.ApplicationCode); + case "Application": + data = Order == "asc" ? data.OrderBy(t => t.Application) : data.OrderByDescending(t => t.Application); break; default: break; @@ -90,7 +90,7 @@ namespace Bootstrap.Admin.Query p.CategoryName, p.Target, p.IsResource, - p.ApplicationCode + p.Application }); return ret; } diff --git a/Bootstrap.Admin/Query/QueryRoleOption.cs b/Bootstrap.Admin/Query/QueryRoleOption.cs index bc13350c..036ac003 100644 --- a/Bootstrap.Admin/Query/QueryRoleOption.cs +++ b/Bootstrap.Admin/Query/QueryRoleOption.cs @@ -24,7 +24,7 @@ namespace Bootstrap.Admin.Query public QueryData RetrieveData() { // int limit, int offset, string name, string price, string sort, string order - var data = RoleHelper.RetrieveRoles(); + var data = RoleHelper.Retrieves(); if (!string.IsNullOrEmpty(RoleName)) { data = data.Where(t => t.RoleName.Contains(RoleName)); diff --git a/Bootstrap.Admin/Query/QueryUserOption.cs b/Bootstrap.Admin/Query/QueryUserOption.cs index 379daec7..274f2e12 100644 --- a/Bootstrap.Admin/Query/QueryUserOption.cs +++ b/Bootstrap.Admin/Query/QueryUserOption.cs @@ -24,7 +24,7 @@ namespace Bootstrap.Admin.Query public QueryData RetrieveData() { // int limit, int offset, string name, string price, string sort, string order - var data = UserHelper.RetrieveUsers(); + var data = UserHelper.Retrieves(); if (!string.IsNullOrEmpty(Name)) { data = data.Where(t => t.UserName.Contains(Name)); diff --git a/Bootstrap.Admin/Startup.cs b/Bootstrap.Admin/Startup.cs index 668c2558..0dc2e85d 100644 --- a/Bootstrap.Admin/Startup.cs +++ b/Bootstrap.Admin/Startup.cs @@ -56,7 +56,7 @@ namespace Bootstrap.Admin services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionsHelper.Log)); services.AddConfigurationManager(Configuration); services.AddCacheManager(Configuration); - services.AddDbAdapter(Configuration); + services.AddDbAdapter(); var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"]) .SetApplicationName(Configuration["ApplicationName"]) .PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"])); diff --git a/Bootstrap.Admin/wwwroot/js/menus.js b/Bootstrap.Admin/wwwroot/js/menus.js index 137b4d3f..2679e313 100644 --- a/Bootstrap.Admin/wwwroot/js/menus.js +++ b/Bootstrap.Admin/wwwroot/js/menus.js @@ -37,7 +37,7 @@ Category: "#category", Target: "#target", IsResource: "#isRes", - ApplicationCode: "#app" + Application: "#app" }, events: { '#btn_assignRole': function (row) { @@ -120,7 +120,7 @@ } }, { - title: "所属应用", field: "ApplicationCode", sortable: true, formatter: function (value, row, index) { + title: "所属应用", field: "Application", sortable: true, formatter: function (value, row, index) { return $('#app').next().find('[data-val="' + value + '"]:first').text(); } } diff --git a/Bootstrap.DataAccess.MongoDB/Dict.cs b/Bootstrap.DataAccess.MongoDB/Dict.cs index 0659a42f..44bdc06c 100644 --- a/Bootstrap.DataAccess.MongoDB/Dict.cs +++ b/Bootstrap.DataAccess.MongoDB/Dict.cs @@ -21,7 +21,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool DeleteDict(IEnumerable value) + public override bool Delete(IEnumerable value) { var list = new List>(); foreach (var id in value) @@ -37,7 +37,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveDict(BootstrapDict p) + public override bool Save(BootstrapDict p) { if (p.Id == "0") { diff --git a/Bootstrap.DataAccess.MongoDB/Exceptions.cs b/Bootstrap.DataAccess.MongoDB/Exceptions.cs index f15482c3..8cb0570d 100644 --- a/Bootstrap.DataAccess.MongoDB/Exceptions.cs +++ b/Bootstrap.DataAccess.MongoDB/Exceptions.cs @@ -22,7 +22,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveExceptions() + public override IEnumerable Retrieves() { return MongoDbAccessManager.Exceptions.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList(); } diff --git a/Bootstrap.DataAccess.MongoDB/Group.cs b/Bootstrap.DataAccess.MongoDB/Group.cs index b94ae701..1440b693 100644 --- a/Bootstrap.DataAccess.MongoDB/Group.cs +++ b/Bootstrap.DataAccess.MongoDB/Group.cs @@ -18,7 +18,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveGroups() + public override IEnumerable Retrieves() { return MongoDbAccessManager.Groups.Find(FilterDefinition.Empty).ToList(); } @@ -28,7 +28,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveGroup(DataAccess.Group p) + public override bool Save(DataAccess.Group p) { if (p.Id == "0") { @@ -52,7 +52,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool DeleteGroup(IEnumerable value) + public override bool Delete(IEnumerable value) { var list = new List>(); foreach (var id in value) @@ -68,10 +68,10 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveGroupsByUserId(string userId) + public override IEnumerable RetrievesByUserId(string userId) { - var groups = GroupHelper.RetrieveGroups(); - var user = UserHelper.RetrieveUsers().Cast().FirstOrDefault(u => u.Id == userId); + var groups = GroupHelper.Retrieves(); + var user = UserHelper.Retrieves().Cast().FirstOrDefault(u => u.Id == userId); groups.ToList().ForEach(g => g.Checked = user.Groups.Any(id => id == g.Id) ? "checked" : ""); return groups; } @@ -82,7 +82,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveGroupsByUserId(string userId, IEnumerable groupIds) + public override bool SaveByUserId(string userId, IEnumerable groupIds) { MongoDbAccessManager.Users.FindOneAndUpdate(u => u.Id == userId, Builders.Update.Set(u => u.Groups, groupIds)); return true; @@ -93,9 +93,9 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveGroupsByRoleId(string roleId) + public override IEnumerable RetrievesByRoleId(string roleId) { - var groups = GroupHelper.RetrieveGroups().Cast().ToList(); + var groups = GroupHelper.Retrieves().Cast().ToList(); groups.ForEach(p => p.Checked = (p.Roles != null && p.Roles.Contains(roleId)) ? "checked" : ""); return groups; } @@ -106,7 +106,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveGroupsByRoleId(string roleId, IEnumerable groupIds) + public override bool SaveByRoleId(string roleId, IEnumerable groupIds) { var groups = MongoDbAccessManager.Groups.Find(md => md.Roles != null && md.Roles.Contains(roleId)).ToList(); @@ -134,11 +134,11 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveGroupsByUserName(string userName) + public override IEnumerable RetrievesByUserName(string userName) { var groups = new List(); - var user = UserHelper.RetrieveUsers().Cast().FirstOrDefault(u => u.UserName == userName); - var group = GroupHelper.RetrieveGroups(); + var user = UserHelper.Retrieves().Cast().FirstOrDefault(u => u.UserName == userName); + var group = GroupHelper.Retrieves(); groups.AddRange(user.Groups.Select(r => group.FirstOrDefault(rl => rl.Id == r).GroupName)); if (groups.Count == 0) groups.Add("Default"); diff --git a/Bootstrap.DataAccess.MongoDB/Log.cs b/Bootstrap.DataAccess.MongoDB/Log.cs index e3324603..af8b8974 100644 --- a/Bootstrap.DataAccess.MongoDB/Log.cs +++ b/Bootstrap.DataAccess.MongoDB/Log.cs @@ -13,7 +13,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveLogs() => MongoDbAccessManager.Logs.Find(l => l.LogTime >= DateTime.Now.AddDays(-7)).ToList(); + public override IEnumerable Retrieves() => MongoDbAccessManager.Logs.Find(l => l.LogTime >= DateTime.Now.AddDays(-7)).ToList(); /// /// 删除日志信息 /// @@ -25,7 +25,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveLog(DataAccess.Log log) + public override bool Save(DataAccess.Log log) { log.LogTime = DateTime.Now; MongoDbAccessManager.Logs.InsertOne(log); diff --git a/Bootstrap.DataAccess.MongoDB/Menu.cs b/Bootstrap.DataAccess.MongoDB/Menu.cs index 86d4ede7..b793eb6f 100644 --- a/Bootstrap.DataAccess.MongoDB/Menu.cs +++ b/Bootstrap.DataAccess.MongoDB/Menu.cs @@ -33,7 +33,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveMenu(BootstrapMenu p) + public override bool Save(BootstrapMenu p) { if (p.Id == "0") { @@ -51,7 +51,7 @@ namespace Bootstrap.DataAccess.MongoDB .Set(md => md.Category, p.Category) .Set(md => md.Target, p.Target) .Set(md => md.IsResource, p.IsResource) - .Set(md => md.ApplicationCode, p.ApplicationCode); + .Set(md => md.Application, p.Application); MongoDbAccessManager.Menus.UpdateOne(md => md.Id == p.Id, update); return true; } @@ -62,7 +62,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool DeleteMenu(IEnumerable value) + public override bool Delete(IEnumerable value) { var list = new List>(); foreach (var id in value) diff --git a/Bootstrap.DataAccess.MongoDB/Message.cs b/Bootstrap.DataAccess.MongoDB/Message.cs index 6ff7e50b..6d22b8a1 100644 --- a/Bootstrap.DataAccess.MongoDB/Message.cs +++ b/Bootstrap.DataAccess.MongoDB/Message.cs @@ -13,7 +13,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - protected override IEnumerable RetrieveMessages(string userName) + protected override IEnumerable Retrieves(string userName) { var msg = MongoDbAccessManager.DBAccess.GetCollection("Messages"); return msg.Find(message => message.To == userName || message.From == userName).ToList(); diff --git a/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs b/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs index 04de0224..99684f3e 100644 --- a/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs +++ b/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs @@ -1,6 +1,5 @@ using Bootstrap.Security; using Longbow.Configuration; -using Longbow.Data; using Microsoft.Extensions.Primitives; using MongoDB.Bson; using MongoDB.Bson.Serialization; diff --git a/Bootstrap.DataAccess.MongoDB/Role.cs b/Bootstrap.DataAccess.MongoDB/Role.cs index 8b8473a9..02fce094 100644 --- a/Bootstrap.DataAccess.MongoDB/Role.cs +++ b/Bootstrap.DataAccess.MongoDB/Role.cs @@ -19,7 +19,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveRoles() + public override IEnumerable Retrieves() { return MongoDbAccessManager.Roles.Find(FilterDefinition.Empty).ToList(); } @@ -29,7 +29,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveRole(DataAccess.Role p) + public override bool Save(DataAccess.Role p) { if (p.Id == "0") { @@ -54,7 +54,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool DeleteRole(IEnumerable value) + public override bool Delete(IEnumerable value) { var list = new List>(); foreach (var id in value) @@ -73,8 +73,8 @@ namespace Bootstrap.DataAccess.MongoDB public override IEnumerable RetrieveRolesByUserName(string userName) { var roles = new List(); - var user = UserHelper.RetrieveUsers().Cast().FirstOrDefault(u => u.UserName == userName); - var role = RoleHelper.RetrieveRoles(); + var user = UserHelper.Retrieves().Cast().FirstOrDefault(u => u.UserName == userName); + var role = RoleHelper.Retrieves(); roles.AddRange(user.Roles.Select(r => role.FirstOrDefault(rl => rl.Id == r).RoleName)); if (roles.Count == 0) roles.Add("Default"); @@ -86,10 +86,10 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveRolesByUserId(string userId) + public override IEnumerable RetrievesByUserId(string userId) { - var roles = RoleHelper.RetrieveRoles(); - var user = UserHelper.RetrieveUsers().Cast().FirstOrDefault(u => u.Id == userId); + var roles = RoleHelper.Retrieves(); + var user = UserHelper.Retrieves().Cast().FirstOrDefault(u => u.Id == userId); roles.ToList().ForEach(r => r.Checked = user.Roles.Any(id => id == r.Id) ? "checked" : ""); return roles; } @@ -100,7 +100,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveRolesByUserId(string userId, IEnumerable roleIds) + public override bool SaveByUserId(string userId, IEnumerable roleIds) { MongoDbAccessManager.Users.FindOneAndUpdate(u => u.Id == userId, Builders.Update.Set(u => u.Roles, roleIds)); return true; @@ -111,9 +111,9 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveRolesByMenuId(string menuId) + public override IEnumerable RetrievesByMenuId(string menuId) { - var roles = RoleHelper.RetrieveRoles().Cast().ToList(); + var roles = RoleHelper.Retrieves().Cast().ToList(); roles.ForEach(r => r.Checked = (r.Menus != null && r.Menus.Contains(menuId)) ? "checked" : ""); roles.ForEach(r => r.Menus = null); return roles; @@ -125,7 +125,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SavaRolesByMenuId(string menuId, IEnumerable roleIds) + public override bool SavaByMenuId(string menuId, IEnumerable roleIds) { var roles = MongoDbAccessManager.Roles.Find(md => md.Menus != null && md.Menus.Contains(menuId)).ToList(); @@ -155,10 +155,10 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveRolesByGroupId(string groupId) + public override IEnumerable RetrievesByGroupId(string groupId) { - var roles = RoleHelper.RetrieveRoles(); - var group = GroupHelper.RetrieveGroups().Cast().FirstOrDefault(u => u.Id == groupId); + var roles = RoleHelper.Retrieves(); + var group = GroupHelper.Retrieves().Cast().FirstOrDefault(u => u.Id == groupId); roles.ToList().ForEach(r => r.Checked = group.Roles.Any(id => id == r.Id) ? "checked" : ""); return roles; } @@ -169,7 +169,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveRolesByGroupId(string groupId, IEnumerable roleIds) + public override bool SaveByGroupId(string groupId, IEnumerable roleIds) { MongoDbAccessManager.Groups.FindOneAndUpdate(u => u.Id == groupId, Builders.Update.Set(u => u.Roles, roleIds)); return true; @@ -183,7 +183,7 @@ namespace Bootstrap.DataAccess.MongoDB public override IEnumerable RetrieveRolesByUrl(string url) { var menu = MongoDbAccessManager.Menus.Find(md => md.Url.StartsWith(url)).FirstOrDefault(); - var ret = RoleHelper.RetrieveRoles().Cast().Where(md => md.Menus != null && md.Menus.Contains(menu.Id)).Select(m => m.RoleName).ToList(); + var ret = RoleHelper.Retrieves().Cast().Where(md => md.Menus != null && md.Menus.Contains(menu.Id)).Select(m => m.RoleName).ToList(); if (!ret.Contains("Administrators")) ret.Add("Administrators"); return ret; } diff --git a/Bootstrap.DataAccess.MongoDB/Task.cs b/Bootstrap.DataAccess.MongoDB/Task.cs index de6b0083..7a42dd05 100644 --- a/Bootstrap.DataAccess.MongoDB/Task.cs +++ b/Bootstrap.DataAccess.MongoDB/Task.cs @@ -12,7 +12,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveTasks() + public override IEnumerable Retrieves() { var users = MongoDbAccessManager.DBAccess.GetCollection("Tasks"); return users.Find(FilterDefinition.Empty).SortByDescending(task => task.AssignTime).ToList(); diff --git a/Bootstrap.DataAccess.MongoDB/User.cs b/Bootstrap.DataAccess.MongoDB/User.cs index bc961f0e..6e0288b8 100644 --- a/Bootstrap.DataAccess.MongoDB/User.cs +++ b/Bootstrap.DataAccess.MongoDB/User.cs @@ -61,7 +61,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveUsers() + public override IEnumerable Retrieves() { var project = Builders.Projection.Include(u => u.Id) .Include(u => u.UserName) @@ -80,7 +80,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveUser(DataAccess.User user) + public override bool Save(DataAccess.User user) { // 已经存在或者已经在新用户中了 if (UserHelper.RetrieveUserByUserName(user.UserName) != null || UserHelper.RetrieveNewUsers().Any(u => u.UserName == user.UserName)) return false; @@ -98,7 +98,7 @@ namespace Bootstrap.DataAccess.MongoDB ApprovedBy = user.ApprovedBy, Roles = new List(), Groups = new List(), - Icon = $"{DictHelper.RetrieveIconFolderPath().Code}default.jpg", + Icon = $"{DictHelper.RetrieveIconFolderPath()}default.jpg", Description = user.Description }); return true; @@ -111,7 +111,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool UpdateUser(string id, string password, string displayName) + public override bool Update(string id, string password, string displayName) { var passSalt = LgbCryptography.GenerateSalt(); var newPassword = LgbCryptography.ComputeHash(password, passSalt); @@ -145,7 +145,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool DeleteUser(IEnumerable value) + public override bool Delete(IEnumerable value) { var list = new List>(); foreach (var id in value) @@ -161,9 +161,9 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveUsersByRoleId(string roleId) + public override IEnumerable RetrievesByRoleId(string roleId) { - var users = UserHelper.RetrieveUsers().Cast().ToList(); + var users = UserHelper.Retrieves().Cast().ToList(); users.ForEach(p => p.Checked = (p.Roles != null && p.Roles.Contains(roleId)) ? "checked" : ""); return users; } @@ -174,7 +174,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveUsersByRoleId(string roleId, IEnumerable userIds) + public override bool SaveByRoleId(string roleId, IEnumerable userIds) { var users = MongoDbAccessManager.Users.Find(md => md.Roles != null && md.Roles.Contains(roleId)).ToList(); @@ -202,9 +202,9 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveUsersByGroupId(string groupId) + public override IEnumerable RetrievesByGroupId(string groupId) { - var users = UserHelper.RetrieveUsers().Cast().ToList(); + var users = UserHelper.Retrieves().Cast().ToList(); users.ForEach(p => p.Checked = (p.Groups != null && p.Groups.Contains(groupId)) ? "checked" : ""); return users; } @@ -215,7 +215,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override bool SaveUsersByGroupId(string groupId, IEnumerable userIds) + public override bool SaveByGroupId(string groupId, IEnumerable userIds) { var users = MongoDbAccessManager.Users.Find(md => md.Groups != null && md.Groups.Contains(groupId)).ToList(); diff --git a/Bootstrap.DataAccess.MySQL/Bootstrap.DataAccess.MySQL.csproj b/Bootstrap.DataAccess.MySQL/Bootstrap.DataAccess.MySQL.csproj deleted file mode 100644 index 31fad426..00000000 --- a/Bootstrap.DataAccess.MySQL/Bootstrap.DataAccess.MySQL.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - netstandard2.0 - true - ..\Keys\Longbow.Utility.snk - - - - - - - - - - - - - - - diff --git a/Bootstrap.DataAccess.MySQL/Dict.cs b/Bootstrap.DataAccess.MySQL/Dict.cs deleted file mode 100644 index 563d03d9..00000000 --- a/Bootstrap.DataAccess.MySQL/Dict.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Bootstrap.DataAccess.MySQL -{ - /// - /// - /// - public class Dict : DataAccess.Dict - { - - } -} diff --git a/Bootstrap.DataAccess.MySQL/Exceptions.cs b/Bootstrap.DataAccess.MySQL/Exceptions.cs deleted file mode 100644 index 140d6b5b..00000000 --- a/Bootstrap.DataAccess.MySQL/Exceptions.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Bootstrap.DataAccess.MySQL -{ - /// - /// - /// - public class Exceptions : DataAccess.Exceptions - { - - } -} diff --git a/Bootstrap.DataAccess.MySQL/Group.cs b/Bootstrap.DataAccess.MySQL/Group.cs deleted file mode 100644 index f6571f38..00000000 --- a/Bootstrap.DataAccess.MySQL/Group.cs +++ /dev/null @@ -1,228 +0,0 @@ -using Longbow.Data; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; - -namespace Bootstrap.DataAccess.MySQL -{ - /// - /// - /// - public class Group : DataAccess.Group - { - /// - /// - /// - /// - public override IEnumerable RetrieveGroups() - { - string sql = "select * from `Groups`"; - List groups = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - groups.Add(new Group() - { - Id = reader[0].ToString(), - GroupName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2] - }); - } - } - return groups; - } - - /// - /// - /// - /// - /// - public override bool SaveGroup(DataAccess.Group p) - { - bool ret = false; - if (p.GroupName.Length > 50) p.GroupName = p.GroupName.Substring(0, 50); - if (!string.IsNullOrEmpty(p.Description) && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500); - string sql = string.IsNullOrEmpty(p.Id) ? - "Insert Into `Groups` (GroupName, Description) Values (@GroupName, @Description)" : - "Update `Groups` set GroupName = @GroupName, Description = @Description where ID = @ID"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description))); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; - } - - /// - /// - /// 删除群组信息 - /// - /// - public override bool DeleteGroup(IEnumerable value) - { - bool ret = false; - var ids = string.Join(",", value); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from UserGroup where GroupID in ({ids})")) - { - try - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from RoleGroup where GroupID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from `Groups` where ID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - transaction.CommitTransaction(); - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - } - return ret; - } - - /// - /// - /// - /// - /// - public override IEnumerable RetrieveGroupsByUserId(string userId) - { - string sql = "select g.ID,g.GroupName,g.Description,case ug.GroupID when g.ID then 'checked' else '' end status from `Groups` g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID"; - List groups = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - groups.Add(new Group() - { - Id = reader[0].ToString(), - GroupName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } - } - return groups; - } - - /// - /// 保存用户部门关系 - /// - /// - /// - /// - public override bool SaveGroupsByUserId(string userId, IEnumerable groupIds) - { - var ret = false; - - //判断用户是否选定角色 - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - //删除用户部门表中该用户所有的部门关系 - string sql = $"delete from UserGroup where UserID = {userId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - groupIds.ToList().ForEach(gId => - { - cmd.CommandText = $"Insert Into UserGroup (UserID, GroupID) Values ({userId}, {gId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - - /// - /// - /// - /// - /// - public override IEnumerable RetrieveGroupsByRoleId(string roleId) - { - List groups = new List(); - string sql = "select g.ID,g.GroupName,g.Description,case rg.GroupID when g.ID then 'checked' else '' end status from `Groups` g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - groups.Add(new Group() - { - Id = reader[0].ToString(), - GroupName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } - } - return groups; - } - - /// - /// 根据角色ID以及选定的部门ID,保到角色部门表 - /// - /// - /// - /// - public override bool SaveGroupsByRoleId(string roleId, IEnumerable groupIds) - { - bool ret = false; - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - //删除角色部门表该角色所有的部门 - string sql = $"delete from RoleGroup where RoleID = {roleId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入角色部门表 - groupIds.ToList().ForEach(gId => - { - cmd.CommandText = $"Insert Into RoleGroup (RoleID, GroupID) Values ({roleId}, {gId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - } -} diff --git a/Bootstrap.DataAccess.MySQL/Log.cs b/Bootstrap.DataAccess.MySQL/Log.cs deleted file mode 100644 index 1b313ab0..00000000 --- a/Bootstrap.DataAccess.MySQL/Log.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Bootstrap.DataAccess.MySQL -{ - /// - /// - /// - public class Log : DataAccess.Log - { - - } -} diff --git a/Bootstrap.DataAccess.MySQL/Menu.cs b/Bootstrap.DataAccess.MySQL/Menu.cs deleted file mode 100644 index 78a2068b..00000000 --- a/Bootstrap.DataAccess.MySQL/Menu.cs +++ /dev/null @@ -1,124 +0,0 @@ -using Bootstrap.Security; -using Longbow.Data; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; - -namespace Bootstrap.DataAccess.MySQL -{ - /// - /// - /// - public class Menu : DataAccess.Menu - { - /// - /// - /// - /// - /// - public override IEnumerable RetrieveAllMenus(string userName) - { - var menus = new List(); - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select n.ID, n.ParentId, n.Name, n.Order, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID")) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", "菜单")); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleName", "Administrators")); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - menus.Add(new BootstrapMenu - { - Id = reader[0].ToString(), - ParentId = reader[1].ToString(), - Name = (string)reader[2], - Order = reader.IsDBNull(3) ? 0 : (int)reader[3], - Icon = reader.IsDBNull(4) ? string.Empty : (string)reader[4], - Url = reader.IsDBNull(5) ? string.Empty : (string)reader[5], - Category = (string)reader[6], - Target = (string)reader[7], - IsResource = reader.IsDBNull(8) ? 0 : (int)reader[8] > 0 ? 1 : 0, - ApplicationCode = reader.IsDBNull(9) ? string.Empty : (string)reader[9], - CategoryName = (string)reader[10], - ParentName = reader.IsDBNull(11) ? string.Empty : (string)reader[11], - }); - } - } - } - return menus; - } - - /// - /// Saves the menu. - /// - /// true, if menu was saved, false otherwise. - /// P. - public override bool SaveMenu(BootstrapMenu p) - { - if (string.IsNullOrEmpty(p.Name)) return false; - bool ret = false; - 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); - string sql = string.IsNullOrEmpty(p.Id) ? - "Insert Into Navigations (ParentId, Name, `Order`, Icon, Url, Category, Target, IsResource, Application) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource, @ApplicationCode)" : - "Update Navigations set ParentId = @ParentId, Name = @Name, `Order` = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource, Application = @ApplicationCode where ID = @ID"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", p.Name)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Order", p.Order)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Icon", DbAdapterManager.ToDBValue(p.Icon))); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Url", DbAdapterManager.ToDBValue(p.Url))); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", p.Category)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Target", p.Target)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; - } - - /// - /// - /// 通过角色ID保存当前授权菜单 - /// - /// - /// - /// - public override bool SaveMenusByRoleId(string roleId, IEnumerable menuIds) - { - bool ret = false; - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - //删除菜单角色表该角色所有的菜单 - string sql = $"delete from NavigationRole where RoleID = {roleId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入菜单角色表 - menuIds.ToList().ForEach(mId => - { - cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {mId}, {roleId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - } -} diff --git a/Bootstrap.DataAccess.MySQL/Message.cs b/Bootstrap.DataAccess.MySQL/Message.cs deleted file mode 100644 index 9621fce6..00000000 --- a/Bootstrap.DataAccess.MySQL/Message.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Longbow; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; - -namespace Bootstrap.DataAccess.MySQL -{ - /// - /// - /// - public class Message : DataAccess.Message - { - /// - /// 所有有关userName所有消息列表 - /// - /// - /// - protected override IEnumerable RetrieveMessages(string userName) - { - string sql = "select m.*, d.Name, ifnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from Messages m left join Dicts d on m.Label = d.Code and d.Category = '消息标签' and d.Define = 0 left join Dicts i on i.Category = '头像地址' and i.Name = '头像路径' and i.Define = 0 inner join Users u on m.`From` = u.UserName where `To` = @UserName or `From` = @UserName order by m.SendTime desc"; - List messages = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - messages.Add(new DataAccess.Message() - { - Id = reader[0].ToString(), - Title = (string)reader[1], - Content = (string)reader[2], - From = (string)reader[3], - To = (string)reader[4], - SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue), - Status = (string)reader[6], - Mark = LgbConvert.ReadValue(reader[7], 0), - IsDelete = LgbConvert.ReadValue(reader[8], 0), - Label = (string)reader[9], - LabelName = LgbConvert.ReadValue(reader[10], string.Empty), - FromIcon = (string)reader[11], - FromDisplayName = (string)reader[12] - }); - } - } - return messages; - } - } -} diff --git a/Bootstrap.DataAccess.MySQL/Role.cs b/Bootstrap.DataAccess.MySQL/Role.cs deleted file mode 100644 index bc146056..00000000 --- a/Bootstrap.DataAccess.MySQL/Role.cs +++ /dev/null @@ -1,174 +0,0 @@ -using Longbow.Data; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; - -namespace Bootstrap.DataAccess.MySQL -{ - /// - /// - /// - public class Role : DataAccess.Role - { - /// - /// - /// - /// - /// - public override IEnumerable RetrieveRolesByUserName(string userName) - { - var entities = new List(); - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select r.RoleName from Roles r inner join UserRole ur on r.ID=ur.RoleID inner join Users u on ur.UserID = u.ID and u.UserName = @UserName union select r.RoleName from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join `Groups` g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID and u.UserName=@UserName")) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - entities.Add((string)reader[0]); - } - } - } - return entities; - } - - /// - /// - /// - /// - /// - public override IEnumerable RetrieveRolesByUrl(string url) - { - string sql = "select distinct r.RoleName, r.Description from Roles r inner join NavigationRole nr on r.ID = nr.RoleID inner join Navigations n on nr.NavigationID = n.ID and n.Application = '0' and n.Url like @Url"; - var ret = new List(); - var cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Url", $"{url}%")); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - ret.Add((string)reader[0]); - } - } - if (ret.Count == 0) ret.Add("Administrators"); - return ret; - } - - /// - /// - /// 保存用户角色关系 - /// - /// - /// - /// - public override bool SaveRolesByUserId(string userId, IEnumerable roleIds) - { - var ret = false; - //判断用户是否选定角色 - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - // delete user from config table - string sql = $"delete from UserRole where UserID = {userId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - roleIds.ToList().ForEach(rId => - { - cmd.CommandText = $"Insert Into UserRole (UserID, RoleID) Values ( {userId}, {rId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - - /// - /// - /// - /// - /// - /// - public override bool SavaRolesByMenuId(string menuId, IEnumerable roleIds) - { - var ret = false; - //判断用户是否选定角色 - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - // delete role from config table - string sql = $"delete from NavigationRole where NavigationID = {menuId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - // insert batch data into config table - roleIds.ToList().ForEach(rId => - { - cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {menuId}, {rId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - - /// - /// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息 - /// - /// - /// - /// - public override bool SaveRolesByGroupId(string groupId, IEnumerable roleIds) - { - var ret = false; - //构造表格 - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - // delete user from config table - string sql = $"delete from RoleGroup where GroupID = {groupId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - // insert batch data into config table - roleIds.ToList().ForEach(rId => - { - cmd.CommandText = $"Insert Into RoleGroup (GroupID, RoleID) Values ( {groupId}, {rId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - } -} \ No newline at end of file diff --git a/Bootstrap.DataAccess.MySQL/Task.cs b/Bootstrap.DataAccess.MySQL/Task.cs deleted file mode 100644 index abc4cd42..00000000 --- a/Bootstrap.DataAccess.MySQL/Task.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Longbow; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; - -namespace Bootstrap.DataAccess.MySQL -{ - public class Task : DataAccess.Task - { - /// - /// 查询所有任务 - /// - /// - public override IEnumerable RetrieveTasks() - { - string sql = "select t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc limit 1000"; - List tasks = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - tasks.Add(new DataAccess.Task() - { - Id = reader[0].ToString(), - TaskName = (string)reader[1], - AssignName = (string)reader[2], - UserName = (string)reader[3], - TaskTime = LgbConvert.ReadValue(reader[4], 0), - TaskProgress = (double)reader[5], - AssignTime = LgbConvert.ReadValue(reader[6], DateTime.MinValue), - AssignDisplayName = (string)reader[7] - }); - } - } - return tasks; - } - } -} diff --git a/Bootstrap.DataAccess.MySQL/User.cs b/Bootstrap.DataAccess.MySQL/User.cs deleted file mode 100644 index 338458ea..00000000 --- a/Bootstrap.DataAccess.MySQL/User.cs +++ /dev/null @@ -1,116 +0,0 @@ -using Bootstrap.Security; -using Longbow.Data; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; - -namespace Bootstrap.DataAccess.MySQL -{ - /// - /// 用户表实体类 - /// - public class User : DataAccess.User - { - /// - /// 通过角色ID保存当前授权用户(插入) - /// - /// 角色ID - /// 用户ID数组 - /// - public override bool SaveUsersByRoleId(string roleId, IEnumerable userIds) - { - bool ret = false; - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - //删除用户角色表该角色所有的用户 - string sql = $"delete from UserRole where RoleID = {roleId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入用户角色表 - userIds.ToList().ForEach(uId => - { - cmd.CommandText = $"Insert Into UserRole (UserID, RoleID) Values ( {uId}, {roleId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - /// - /// 通过部门ID保存当前授权用户(插入) - /// - /// GroupID - /// 用户ID数组 - /// - public override bool SaveUsersByGroupId(string groupId, IEnumerable userIds) - { - bool ret = false; - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - //删除用户角色表该角色所有的用户 - string sql = $"delete from UserGroup where GroupID = {groupId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入用户角色表 - userIds.ToList().ForEach(uId => - { - cmd.CommandText = $"Insert Into UserGroup (UserID, GroupID) Values ( {uId}, {groupId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - /// - /// - /// - /// - /// - public override BootstrapUser RetrieveUserByUserName(string userName) - { - BootstrapUser user = null; - var sql = "select UserName, DisplayName, CONCAT(case ifnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end, ifnull(Icon, 'default.jpg')) Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = '头像地址' and Name = '头像路径' where ApprovedTime is not null and UserName = @UserName"; - var db = DbAccessManager.DBAccess; - var cmd = db.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(db.CreateParameter("@UserName", userName)); - using (DbDataReader reader = db.ExecuteReader(cmd)) - { - if (reader.Read()) - { - user = new BootstrapUser - { - UserName = (string)reader[0], - DisplayName = (string)reader[1], - Icon = (string)reader[2], - Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3] - }; - } - } - return user; - } - } -} diff --git a/Bootstrap.DataAccess.SQLite/Bootstrap.DataAccess.SQLite.csproj b/Bootstrap.DataAccess.SQLite/Bootstrap.DataAccess.SQLite.csproj deleted file mode 100644 index 7dc06d48..00000000 --- a/Bootstrap.DataAccess.SQLite/Bootstrap.DataAccess.SQLite.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - netstandard2.0 - true - ..\Keys\Longbow.Utility.snk - - - - - - - - - - - - - - - - - - - diff --git a/Bootstrap.DataAccess.SQLite/Dict.cs b/Bootstrap.DataAccess.SQLite/Dict.cs deleted file mode 100644 index 5a52557b..00000000 --- a/Bootstrap.DataAccess.SQLite/Dict.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Bootstrap.DataAccess.SQLite -{ - /// - /// - /// - public class Dict : DataAccess.Dict - { - - } -} diff --git a/Bootstrap.DataAccess.SQLite/Exceptions.cs b/Bootstrap.DataAccess.SQLite/Exceptions.cs deleted file mode 100644 index 896aed3f..00000000 --- a/Bootstrap.DataAccess.SQLite/Exceptions.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Bootstrap.DataAccess.SQLite -{ - /// - /// - /// - public class Exceptions : DataAccess.Exceptions - { - - } -} diff --git a/Bootstrap.DataAccess.SQLite/Group.cs b/Bootstrap.DataAccess.SQLite/Group.cs deleted file mode 100644 index adb3374d..00000000 --- a/Bootstrap.DataAccess.SQLite/Group.cs +++ /dev/null @@ -1,90 +0,0 @@ -using Longbow.Data; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; - -namespace Bootstrap.DataAccess.SQLite -{ - /// - /// - /// - public class Group : DataAccess.Group - { - /// - /// 保存用户部门关系 - /// - /// - /// - /// - public override bool SaveGroupsByUserId(string userId, IEnumerable groupIds) - { - var ret = false; - - //判断用户是否选定角色 - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - //删除用户部门表中该用户所有的部门关系 - string sql = $"delete from UserGroup where UserID = {userId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - groupIds.ToList().ForEach(gId => - { - cmd.CommandText = $"Insert Into UserGroup (UserID, GroupID) Values ({userId}, {gId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - /// - /// 根据角色ID以及选定的部门ID,保到角色部门表 - /// - /// - /// - /// - public override bool SaveGroupsByRoleId(string roleId, IEnumerable groupIds) - { - bool ret = false; - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - //删除角色部门表该角色所有的部门 - string sql = $"delete from RoleGroup where RoleID = {roleId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入角色部门表 - groupIds.ToList().ForEach(gId => - { - cmd.CommandText = $"Insert Into RoleGroup (RoleID, GroupID) Values ({roleId}, {gId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - } -} diff --git a/Bootstrap.DataAccess.SQLite/Log.cs b/Bootstrap.DataAccess.SQLite/Log.cs deleted file mode 100644 index 315d353d..00000000 --- a/Bootstrap.DataAccess.SQLite/Log.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Bootstrap.DataAccess.SQLite -{ - /// - /// - /// - public class Log : DataAccess.Log - { - - } -} diff --git a/Bootstrap.DataAccess.SQLite/Menu.cs b/Bootstrap.DataAccess.SQLite/Menu.cs deleted file mode 100644 index abbf093b..00000000 --- a/Bootstrap.DataAccess.SQLite/Menu.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Longbow.Data; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; - -namespace Bootstrap.DataAccess.SQLite -{ - /// - /// - /// - public class Menu : DataAccess.Menu - { - /// - /// - /// 通过角色ID保存当前授权菜单 - /// - /// - /// - /// - public override bool SaveMenusByRoleId(string roleId, IEnumerable menuIds) - { - bool ret = false; - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - //删除菜单角色表该角色所有的菜单 - string sql = $"delete from NavigationRole where RoleID = {roleId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入菜单角色表 - menuIds.ToList().ForEach(mId => - { - cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ({mId}, {roleId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - } -} diff --git a/Bootstrap.DataAccess.SQLite/Message.cs b/Bootstrap.DataAccess.SQLite/Message.cs deleted file mode 100644 index 43bde2fb..00000000 --- a/Bootstrap.DataAccess.SQLite/Message.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Longbow; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; - -namespace Bootstrap.DataAccess.SQLite -{ - /// - /// - /// - public class Message : DataAccess.Message - { - /// - /// 所有有关userName所有消息列表 - /// - /// - /// - protected override IEnumerable RetrieveMessages(string userName) - { - string sql = "select m.*, d.Name, ifnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = '消息标签' and d.Define = 0 left join Dicts i on i.Category = '头像地址' and i.Name = '头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc"; - List messages = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - messages.Add(new DataAccess.Message() - { - Id = reader[0].ToString(), - Title = (string)reader[1], - Content = (string)reader[2], - From = (string)reader[3], - To = (string)reader[4], - SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue), - Status = (string)reader[6], - Mark = LgbConvert.ReadValue(reader[7], 0), - IsDelete = LgbConvert.ReadValue(reader[8], 0), - Label = (string)reader[9], - LabelName = LgbConvert.ReadValue(reader[10], string.Empty), - FromIcon = (string)reader[11], - FromDisplayName = (string)reader[12] - }); - } - } - return messages; - } - } -} diff --git a/Bootstrap.DataAccess.SQLite/Role.cs b/Bootstrap.DataAccess.SQLite/Role.cs deleted file mode 100644 index 109fb23c..00000000 --- a/Bootstrap.DataAccess.SQLite/Role.cs +++ /dev/null @@ -1,130 +0,0 @@ -using Longbow.Data; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; - -namespace Bootstrap.DataAccess.SQLite -{ - /// - /// - /// - public class Role : DataAccess.Role - { - /// - /// - /// 保存用户角色关系 - /// - /// - /// - /// - public override bool SaveRolesByUserId(string userId, IEnumerable roleIds) - { - var ret = false; - //判断用户是否选定角色 - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - // delete user from config table - string sql = $"delete from UserRole where UserID = {userId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - roleIds.ToList().ForEach(rId => - { - cmd.CommandText = $"Insert Into UserRole (UserID, RoleID) Values ( {userId}, {rId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - - /// - /// - /// - /// - /// - /// - public override bool SavaRolesByMenuId(string menuId, IEnumerable roleIds) - { - var ret = false; - //判断用户是否选定角色 - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - // delete role from config table - string sql = $"delete from NavigationRole where NavigationID = {menuId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - // insert batch data into config table - roleIds.ToList().ForEach(rId => - { - cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {menuId}, {rId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - - /// - /// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息 - /// - /// - /// - /// - public override bool SaveRolesByGroupId(string groupId, IEnumerable roleIds) - { - var ret = false; - //构造表格 - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - // delete user from config table - string sql = $"delete from RoleGroup where GroupID = {groupId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - // insert batch data into config table - roleIds.ToList().ForEach(rId => - { - cmd.CommandText = $"Insert Into RoleGroup (GroupID, RoleID) Values ( {groupId}, {rId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - } -} \ No newline at end of file diff --git a/Bootstrap.DataAccess.SQLite/Task.cs b/Bootstrap.DataAccess.SQLite/Task.cs deleted file mode 100644 index c269ac36..00000000 --- a/Bootstrap.DataAccess.SQLite/Task.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Longbow; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; - -namespace Bootstrap.DataAccess.SQLite -{ - public class Task : DataAccess.Task - { - /// - /// 查询所有任务 - /// - /// - public override IEnumerable RetrieveTasks() - { - string sql = "select t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc limit 1000"; - List tasks = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - tasks.Add(new DataAccess.Task() - { - Id = reader[0].ToString(), - TaskName = (string)reader[1], - AssignName = (string)reader[2], - UserName = (string)reader[3], - TaskTime = LgbConvert.ReadValue(reader[4], 0), - TaskProgress = (double)reader[5], - AssignTime = LgbConvert.ReadValue(reader[6], DateTime.MinValue), - AssignDisplayName = (string)reader[7] - }); - } - } - return tasks; - } - } -} diff --git a/Bootstrap.DataAccess.SQLite/User.cs b/Bootstrap.DataAccess.SQLite/User.cs deleted file mode 100644 index 7f1cee07..00000000 --- a/Bootstrap.DataAccess.SQLite/User.cs +++ /dev/null @@ -1,116 +0,0 @@ -using Bootstrap.Security; -using Longbow.Data; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; - -namespace Bootstrap.DataAccess.SQLite -{ - /// - /// 用户表实体类 - /// - public class User : DataAccess.User - { - /// - /// 通过角色ID保存当前授权用户(插入) - /// - /// 角色ID - /// 用户ID数组 - /// - public override bool SaveUsersByRoleId(string roleId, IEnumerable userIds) - { - bool ret = false; - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - //删除用户角色表该角色所有的用户 - string sql = $"delete from UserRole where RoleID = {roleId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入用户角色表 - userIds.ToList().ForEach(uId => - { - cmd.CommandText = $"Insert Into UserRole (UserID, RoleID) Values ( {uId}, {roleId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - /// - /// 通过部门ID保存当前授权用户(插入) - /// - /// GroupID - /// 用户ID数组 - /// - public override bool SaveUsersByGroupId(string groupId, IEnumerable userIds) - { - bool ret = false; - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - try - { - //删除用户角色表该角色所有的用户 - string sql = $"delete from UserGroup where GroupID = {groupId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入用户角色表 - userIds.ToList().ForEach(uId => - { - cmd.CommandText = $"Insert Into UserGroup (UserID, GroupID) Values ( {uId}, {groupId})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - }); - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - return ret; - } - /// - /// - /// - /// - /// - public override BootstrapUser RetrieveUserByUserName(string userName) - { - BootstrapUser user = null; - var sql = "select UserName, DisplayName, case ifnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end || ifnull(Icon, 'default.jpg') Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = '头像地址' and Name = '头像路径' where ApprovedTime is not null and UserName = @UserName"; - var db = DbAccessManager.DBAccess; - var cmd = db.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(db.CreateParameter("@UserName", userName)); - using (DbDataReader reader = db.ExecuteReader(cmd)) - { - if (reader.Read()) - { - user = new BootstrapUser - { - UserName = (string)reader[0], - DisplayName = (string)reader[1], - Icon = (string)reader[2], - Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3] - }; - } - } - return user; - } - } -} diff --git a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 7c4c9d7e..cafabf1f 100644 --- a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -11,11 +11,13 @@ - - - - - + + + + + + + diff --git a/Bootstrap.DataAccess/DbAccessManager.cs b/Bootstrap.DataAccess/DbAccessManager.cs deleted file mode 100644 index 61cb11f7..00000000 --- a/Bootstrap.DataAccess/DbAccessManager.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Longbow.Data; - -namespace Bootstrap.DataAccess -{ - /// - /// - /// - public static class DbAccessManager - { - /// - /// - /// - public static IDbAccess DBAccess - { - get { return DbAdapterManager.CreateDB("ba"); } - } - } -} diff --git a/Bootstrap.DataAccess/DbManager.cs b/Bootstrap.DataAccess/DbManager.cs new file mode 100644 index 00000000..87a07614 --- /dev/null +++ b/Bootstrap.DataAccess/DbManager.cs @@ -0,0 +1,39 @@ +using PetaPoco; + +namespace Bootstrap.DataAccess +{ + /// + /// + /// + public static class DbManager + { + /// + /// + /// + public static IDatabase Db { get { return Create(); } } + + /// + /// + /// + /// + /// + public static IDatabase Create(string connectionName = null, bool keepAlive = false) + { + var db = Longbow.Data.DbManager.Create(connectionName, keepAlive); + return db.AddMaps(); + } + + private static IDatabase AddMaps(this IDatabase database) + { + database.AddMap("Dicts"); + database.AddMap("Users", new string[] { "Checked", "Period", "NewPassword", "UserStatus" }); + database.AddMap("Exceptions", new string[] { "Period" }); + database.AddMap("Groups", new string[] { "Checked" }); + database.AddMap("Logs"); + database.AddMap("Navigations", new string[] { "ParentName", "CategoryName", "Active", "Menus" }); + database.AddMap("Roles", new string[] { "Checked" }); + database.AddMap("Tasks"); + return database; + } + } +} diff --git a/Bootstrap.DataAccess/Dict.cs b/Bootstrap.DataAccess/Dict.cs index c4d89414..2c00ee7b 100644 --- a/Bootstrap.DataAccess/Dict.cs +++ b/Bootstrap.DataAccess/Dict.cs @@ -2,8 +2,6 @@ using Bootstrap.Security.DataAccess; using System; using System.Collections.Generic; -using System.Data; -using System.Data.Common; using System.Linq; namespace Bootstrap.DataAccess @@ -18,42 +16,29 @@ namespace Bootstrap.DataAccess /// /// 需要删除的IDs /// - public virtual bool DeleteDict(IEnumerable value) + public virtual bool Delete(IEnumerable value) { - var ret = false; var ids = string.Join(",", value); - string sql = $"Delete from Dicts where ID in ({ids})"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == value.Count(); - } - return ret; + string sql = $"where ID in ({ids})"; + DbManager.Db.Delete(sql); + return true; } + /// /// 保存新建/更新的字典信息 /// /// /// - public virtual bool SaveDict(BootstrapDict dict) + public virtual bool Save(BootstrapDict dict) { - bool ret = false; if (dict.Category.Length > 50) dict.Category = dict.Category.Substring(0, 50); if (dict.Name.Length > 50) dict.Name = dict.Name.Substring(0, 50); if (dict.Code.Length > 50) dict.Code = dict.Code.Substring(0, 50); - string sql = string.IsNullOrEmpty(dict.Id) ? - "Insert Into Dicts (Category, Name, Code ,Define) Values (@Category, @Name, @Code, @Define)" : - "Update Dicts set Category = @Category, Name = @Name, Code = @Code, Define = @Define where ID = @ID"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", dict.Id)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", dict.Category)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", dict.Name)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Code", dict.Code)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Define", dict.Define)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; + + DbManager.Db.Save(dict); + return true; } + /// /// 保存网站个性化设置 /// @@ -63,37 +48,34 @@ namespace Bootstrap.DataAccess /// public virtual bool SaveSettings(BootstrapDict dict) { - var ret = false; - string sql = "Update Dicts set Code = @Code where Category = @Category and Name = @Name"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", dict.Name)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Code", dict.Code)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", dict.Category)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; + DbManager.Db.Update("set Code = @Code where Category = @Category and Name = @Name", dict); + return true; } + /// /// 获取字典分类名称 /// /// public virtual IEnumerable RetrieveCategories() => DictHelper.RetrieveDicts().Select(d => d.Category).Distinct(); + /// /// /// /// public virtual string RetrieveWebTitle() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code; + /// /// /// /// public virtual string RetrieveWebFooter() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code; + /// /// 获得系统中配置的可以使用的网站样式 /// /// public virtual IEnumerable RetrieveThemes() => DictHelper.RetrieveDicts().Where(d => d.Category == "网站样式"); + /// /// 获得网站设置中的当前样式 /// @@ -103,21 +85,27 @@ namespace Bootstrap.DataAccess var theme = DictHelper.RetrieveDicts().Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0).FirstOrDefault(); return theme == null ? string.Empty : (theme.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase) ? string.Empty : theme.Code); } + /// /// 获取头像路径 /// /// - public virtual BootstrapDict RetrieveIconFolderPath() => DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" }; + public virtual string RetrieveIconFolderPath() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" }).Code; + /// /// 获得默认的前台首页地址,默认为~/Home/Index /// /// public virtual string RetrieveHomeUrl() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code; + + public virtual string RetrieveDefaultIcon() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "头像文件" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "default.jpg" }).Code; + /// /// /// /// public virtual IEnumerable> RetrieveApps() => DictHelper.RetrieveDicts().Where(d => d.Category == "应用程序" && d.Define == 0).Select(d => new KeyValuePair(d.Code, d.Name)).OrderBy(d => d.Key); + /// /// 通过数据库获得所有字典表配置信息,缓存Key=DictHelper-RetrieveDicts /// diff --git a/Bootstrap.DataAccess/Exceptions.cs b/Bootstrap.DataAccess/Exceptions.cs index 7dee6d87..aaafa455 100644 --- a/Bootstrap.DataAccess/Exceptions.cs +++ b/Bootstrap.DataAccess/Exceptions.cs @@ -1,11 +1,10 @@ using Longbow; using Longbow.Configuration; -using Longbow.Data; +using Longbow.Web.Mvc; +using PetaPoco; using System; using System.Collections.Generic; using System.Collections.Specialized; -using System.Data; -using System.Data.Common; namespace Bootstrap.DataAccess { @@ -18,53 +17,57 @@ namespace Bootstrap.DataAccess /// /// public string Id { get; set; } + /// /// /// public string AppDomainName { get; set; } + /// /// /// public string ErrorPage { get; set; } + /// /// /// public string UserId { get; set; } + /// /// /// public string UserIp { get; set; } - /// - /// - /// - public string Message { get; set; } - /// - /// - /// - public string StackTrace { get; set; } - /// - /// - /// - public DateTime LogTime { get; set; } + /// /// /// public string ExceptionType { get; set; } + + /// + /// + /// + public string Message { get; set; } + + /// + /// + /// + public string StackTrace { get; set; } + + /// + /// + /// + public DateTime LogTime { get; set; } + /// /// 获得/设置 时间描述 2分钟内为刚刚 /// public string Period { get; set; } - private static void ClearExceptions() + private static void ClearExceptions() => System.Threading.Tasks.Task.Run(() => { - System.Threading.Tasks.Task.Run(() => - { - string sql = $"delete from Exceptions where LogTime < @LogTime"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepExceptionsPeriod"], 1)), DbType.DateTime)); - DbAccessManager.DBAccess.ExecuteNonQuery(cmd); - }); - } + DbManager.Db.Execute("delete from Exceptions where LogTime < @0", DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepExceptionsPeriod"], 1))); + }); + /// /// /// @@ -73,62 +76,47 @@ namespace Bootstrap.DataAccess /// public virtual bool Log(Exception ex, NameValueCollection additionalInfo) { - if (ex == null) return true; - if (additionalInfo == null) + 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() { - additionalInfo = new NameValueCollection - { - ["UserId"] = null, - ["UserIp"] = null, - ["ErrorPage"] = null - }; - } - var errorPage = additionalInfo["ErrorPage"] ?? (ex.GetType().Name.Length > 50 ? ex.GetType().Name.Substring(0, 50) : ex.GetType().Name); - var sql = "insert into Exceptions (AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (@AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, @LogTime)"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", DbAdapterManager.ToDBValue(additionalInfo["UserId"]))); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserIp", DbAdapterManager.ToDBValue(additionalInfo["UserIp"]))); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAdapterManager.ToDBValue(ex.StackTrace))); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now, DbType.DateTime)); - DbAccessManager.DBAccess.ExecuteNonQuery(cmd); - ClearExceptions(); - } + AppDomainName = AppDomain.CurrentDomain.FriendlyName, + ErrorPage = errorPage, + UserId = additionalInfo?["UserId"], + UserIp = additionalInfo?["UserIp"], + ExceptionType = ex.GetType().FullName, + Message = ex.Message, + StackTrace = ex.StackTrace, + LogTime = DateTime.Now + }); + ClearExceptions(); return true; } + /// /// 查询一周内所有异常 /// /// - public virtual IEnumerable RetrieveExceptions() + public virtual IEnumerable Retrieves() => DbManager.Db.Fetch("select * from Exceptions where LogTime > @0 order by LogTime desc", DateTime.Now.AddDays(-7)); + + /// + /// + /// + /// + /// + /// + /// + /// + public virtual Page RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime) { - string sql = "select * from Exceptions where LogTime > @LogTime order by LogTime desc"; - List exceptions = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now.AddDays(-7), DbType.DateTime)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - exceptions.Add(new Exceptions() - { - Id = reader[0].ToString(), - AppDomainName = (string)reader[1], - ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3], - UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4], - ExceptionType = (string)reader[5], - Message = (string)reader[6], - StackTrace = reader.IsDBNull(7) ? string.Empty : (string)reader[7], - LogTime = LgbConvert.ReadValue(reader[8], DateTime.MinValue) - }); - } - } - return exceptions; + var sql = new Sql("select * from Exceptions"); + if (startTime.HasValue) sql.Append("where LogTime > @0", startTime.Value); + if (endTime.HasValue) sql.Append("where LogTime < @0", endTime.Value); + 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); } } } diff --git a/Bootstrap.DataAccess/Group.cs b/Bootstrap.DataAccess/Group.cs index 2d26ddb0..9350df75 100644 --- a/Bootstrap.DataAccess/Group.cs +++ b/Bootstrap.DataAccess/Group.cs @@ -1,10 +1,6 @@ using Bootstrap.Security.DataAccess; -using Longbow.Data; using System; using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Data.SqlClient; using System.Linq; namespace Bootstrap.DataAccess @@ -39,57 +35,30 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveGroups() - { - string sql = "select * from Groups"; - List groups = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - groups.Add(new Group() - { - Id = reader[0].ToString(), - GroupName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2] - }); - } - } - return groups; - } + public virtual IEnumerable Retrieves() => DbManager.Db.Fetch("select * from Groups"); /// /// 删除群组信息 /// /// - public virtual bool DeleteGroup(IEnumerable value) + public virtual bool Delete(IEnumerable value) { bool ret = false; var ids = string.Join(",", value); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + try { - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from UserGroup where GroupID in ({ids})")) - { - try - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from RoleGroup where GroupID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from Groups where ID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - transaction.CommitTransaction(); - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } + db.BeginTransaction(); + db.Execute($"delete from UserGroup where GroupID in ({ids})"); + db.Execute($"delete from RoleGroup where GroupID in ({ids})"); + db.Execute($"delete from Groups where ID in ({ids})"); + db.CompleteTransaction(); + ret = true; + } + catch (Exception e) + { + db.AbortTransaction(); + throw e; } return ret; } @@ -99,22 +68,10 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveGroup(Group p) + public virtual bool Save(Group p) { - bool ret = false; - if (p.GroupName.Length > 50) p.GroupName = p.GroupName.Substring(0, 50); - if (!string.IsNullOrEmpty(p.Description) && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500); - string sql = string.IsNullOrEmpty(p.Id) ? - "Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" : - "Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description))); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; + DbManager.Db.Save(p); + return !p.Id.IsNullOrEmpty(); } /// @@ -122,27 +79,14 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveGroupsByUserId(string userId) - { - string sql = "select g.ID,g.GroupName,g.Description,case ug.GroupID when g.ID then 'checked' else '' end status from Groups g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID"; - List groups = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - groups.Add(new Group() - { - Id = reader[0].ToString(), - GroupName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } - } - return groups; - } + 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); + + /// + /// 根据角色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); /// /// 保存用户部门关系 @@ -150,113 +94,50 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveGroupsByUserId(string userId, IEnumerable groupIds) + public virtual bool SaveByUserId(string userId, IEnumerable groupIds) { var ret = false; - DataTable dt = new DataTable(); - dt.Columns.Add("UserID", typeof(int)); - dt.Columns.Add("GroupID", typeof(int)); - //判断用户是否选定角色 - groupIds.ToList().ForEach(groupId => dt.Rows.Add(userId, groupId)); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + try { - try - { - //删除用户部门表中该用户所有的部门关系 - string sql = $"delete from UserGroup where UserID = {userId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - // insert batch data into config table - using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction)) - { - bulk.BatchSize = 1000; - bulk.DestinationTableName = "UserGroup"; - bulk.ColumnMappings.Add("UserID", "UserID"); - bulk.ColumnMappings.Add("GroupID", "GroupID"); - bulk.WriteToServer(dt); - transaction.CommitTransaction(); - } - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } + db.BeginTransaction(); + //删除用户部门表中该用户所有的部门关系 + db.Execute("delete from UserGroup where UserID = @0", userId); + db.InsertBulk("UserGroup", groupIds.Select(g => new { UserID = userId, GroupID = g })); + db.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } - /// - /// 根据角色ID指派部门 - /// - /// - /// - public virtual IEnumerable RetrieveGroupsByRoleId(string roleId) - { - List groups = new List(); - string sql = "select g.ID,g.GroupName,g.Description,case rg.GroupID when g.ID then 'checked' else '' end status from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - groups.Add(new Group() - { - Id = reader[0].ToString(), - GroupName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } - } - return groups; - } - /// /// 根据角色ID以及选定的部门ID,保到角色部门表 /// /// /// /// - public virtual bool SaveGroupsByRoleId(string roleId, IEnumerable groupIds) + public virtual bool SaveByRoleId(string roleId, IEnumerable groupIds) { bool ret = false; - DataTable dt = new DataTable(); - dt.Columns.Add("GroupID", typeof(int)); - dt.Columns.Add("RoleID", typeof(int)); - groupIds.ToList().ForEach(groupId => dt.Rows.Add(groupId, roleId)); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + try { - try - { - //删除角色部门表该角色所有的部门 - string sql = $"delete from RoleGroup where RoleID = {roleId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入角色部门表 - using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction)) - { - bulk.BatchSize = 1000; - bulk.ColumnMappings.Add("GroupID", "GroupID"); - bulk.ColumnMappings.Add("RoleID", "RoleID"); - bulk.DestinationTableName = "RoleGroup"; - bulk.WriteToServer(dt); - transaction.CommitTransaction(); - } - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } + db.BeginTransaction(); + //删除角色部门表该角色所有的部门 + db.Execute("delete from RoleGroup where RoleID = @0", roleId); + db.InsertBulk("RoleGroup", groupIds.Select(g => new { RoleID = roleId, GroupID = g })); + db.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } @@ -266,6 +147,6 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveGroupsByUserName(string userName) => DbHelper.RetrieveGroupsByUserName(userName); + public virtual IEnumerable RetrievesByUserName(string userName) => DbHelper.RetrieveGroupsByUserName(userName); } } diff --git a/Bootstrap.DataAccess/Helper/DictHelper.cs b/Bootstrap.DataAccess/Helper/DictHelper.cs index 726a9a0e..4a732939 100644 --- a/Bootstrap.DataAccess/Helper/DictHelper.cs +++ b/Bootstrap.DataAccess/Helper/DictHelper.cs @@ -17,37 +17,42 @@ namespace Bootstrap.DataAccess /// 缓存索引,BootstrapAdmin后台清理缓存时使用 /// public const string RetrieveDictsDataKey = "BootstrapDict-RetrieveDicts"; + /// /// /// public const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory"; + /// /// /// /// - public static IEnumerable RetrieveDicts() => CacheManager.GetOrAdd(RetrieveDictsDataKey, key => DbAdapterManager.Create().RetrieveDicts()); + public static IEnumerable RetrieveDicts() => CacheManager.GetOrAdd(RetrieveDictsDataKey, key => DbContextManager.Create().RetrieveDicts()); + /// /// 删除字典中的数据 /// /// 需要删除的IDs /// - public static bool DeleteDict(IEnumerable value) + public static bool Delete(IEnumerable value) { - var ret = DbAdapterManager.Create().DeleteDict(value); + var ret = DbContextManager.Create().Delete(value); CacheCleanUtility.ClearCache(dictIds: value); return ret; } + /// /// 保存新建/更新的字典信息 /// /// /// - public static bool SaveDict(BootstrapDict p) + public static bool Save(BootstrapDict p) { - var ret = DbAdapterManager.Create().SaveDict(p); - if (ret) CacheCleanUtility.ClearCache( new List() { p.Id }); + var ret = DbContextManager.Create().Save(p); + if (ret) CacheCleanUtility.ClearCache(new List() { p.Id }); return ret; } + /// /// 保存网站个性化设置 /// @@ -57,49 +62,63 @@ namespace Bootstrap.DataAccess /// public static bool SaveSettings(BootstrapDict dict) { - var ret = DbAdapterManager.Create().SaveSettings(dict); + var ret = DbContextManager.Create().SaveSettings(dict); if (ret) CacheCleanUtility.ClearCache(dictIds: new List()); return ret; } + /// /// 获取字典分类名称 /// /// - public static IEnumerable RetrieveCategories() => CacheManager.GetOrAdd(RetrieveCategoryDataKey, key => DbAdapterManager.Create().RetrieveCategories()); + public static IEnumerable RetrieveCategories() => CacheManager.GetOrAdd(RetrieveCategoryDataKey, key => DbContextManager.Create().RetrieveCategories()); + /// /// /// /// - public static string RetrieveWebTitle() => DbAdapterManager.Create().RetrieveWebTitle(); + public static string RetrieveWebTitle() => DbContextManager.Create().RetrieveWebTitle(); + /// /// /// /// - public static string RetrieveWebFooter() => DbAdapterManager.Create().RetrieveWebFooter(); + public static string RetrieveWebFooter() => DbContextManager.Create().RetrieveWebFooter(); + /// /// 获得系统中配置的可以使用的网站样式 /// /// - public static IEnumerable RetrieveThemes() => DbAdapterManager.Create().RetrieveThemes(); + public static IEnumerable RetrieveThemes() => DbContextManager.Create().RetrieveThemes(); + /// /// 获得网站设置中的当前样式 /// /// - public static string RetrieveActiveTheme() => DbAdapterManager.Create().RetrieveActiveTheme(); + public static string RetrieveActiveTheme() => DbContextManager.Create().RetrieveActiveTheme(); + /// /// 获取头像路径 /// /// - public static BootstrapDict RetrieveIconFolderPath() => DbAdapterManager.Create().RetrieveIconFolderPath(); + public static string RetrieveIconFolderPath() => DbContextManager.Create().RetrieveIconFolderPath(); + /// /// 获得默认的前台首页地址,默认为~/Home/Index /// /// - public static string RetrieveHomeUrl() => DbAdapterManager.Create().RetrieveHomeUrl(); + public static string RetrieveHomeUrl() => DbContextManager.Create().RetrieveHomeUrl(); + + /// + /// 获得默认的前台首页地址,默认为~/Home/Index + /// + /// + public static string RetrieveDefaultIcon() => DbContextManager.Create().RetrieveDefaultIcon(); + /// /// /// /// - public static IEnumerable> RetrieveApps() => DbAdapterManager.Create().RetrieveApps(); + public static IEnumerable> RetrieveApps() => DbContextManager.Create().RetrieveApps(); } } diff --git a/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs b/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs index 833e2da2..8b06c08e 100644 --- a/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs +++ b/Bootstrap.DataAccess/Helper/ExceptionsHelper.cs @@ -1,5 +1,7 @@ using Longbow.Cache; using Longbow.Data; +using Longbow.Web.Mvc; +using PetaPoco; using System; using System.Collections.Generic; using System.Collections.Specialized; @@ -23,7 +25,7 @@ namespace Bootstrap.DataAccess /// public static void Log(Exception ex, NameValueCollection additionalInfo) { - var ret = DbAdapterManager.Create().Log(ex, additionalInfo); + var ret = DbContextManager.Create().Log(ex, additionalInfo); if (ret) CacheManager.Clear(RetrieveExceptionsDataKey); } @@ -31,6 +33,15 @@ namespace Bootstrap.DataAccess /// 查询一周内所有异常 /// /// - public static IEnumerable RetrieveExceptions() => CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => DbAdapterManager.Create().RetrieveExceptions()); + public static IEnumerable Retrieves() => CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => DbContextManager.Create().Retrieves()); + + /// + /// + /// + /// + /// + /// + /// + public static Page RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime) => CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => DbContextManager.Create().RetrievePages(po, startTime, endTime)); } } diff --git a/Bootstrap.DataAccess/Helper/GroupHelper.cs b/Bootstrap.DataAccess/Helper/GroupHelper.cs index a2c5224d..6e9262d3 100644 --- a/Bootstrap.DataAccess/Helper/GroupHelper.cs +++ b/Bootstrap.DataAccess/Helper/GroupHelper.cs @@ -19,16 +19,16 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveGroups() => CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbAdapterManager.Create().RetrieveGroups()); + public static IEnumerable Retrieves() => CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbContextManager.Create().Retrieves()); /// /// 删除群组信息 /// - /// - public static bool DeleteGroup(IEnumerable value) + /// + public static bool Delete(IEnumerable values) { - var ret = DbAdapterManager.Create().DeleteGroup(value); - if (ret) CacheCleanUtility.ClearCache(groupIds: value); + var ret = DbContextManager.Create().Delete(values); + if (ret) CacheCleanUtility.ClearCache(groupIds: values); return ret; } @@ -37,9 +37,9 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveGroup(Group p) + public static bool Save(Group p) { - var ret = DbAdapterManager.Create().SaveGroup(p); + var ret = DbContextManager.Create().Save(p); if (ret) CacheCleanUtility.ClearCache(groupIds: string.IsNullOrEmpty(p.Id) ? new List() : new List() { p.Id }); return ret; } @@ -48,7 +48,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveGroupsByUserId(string userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbAdapterManager.Create().RetrieveGroupsByUserId(userId), RetrieveGroupsByUserIdDataKey); + public static IEnumerable RetrievesByUserId(string userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbContextManager.Create().RetrievesByUserId(userId), RetrieveGroupsByUserIdDataKey); /// /// 保存用户部门关系 @@ -56,9 +56,9 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveGroupsByUserId(string userId, IEnumerable groupIds) + public static bool SaveByUserId(string userId, IEnumerable groupIds) { - var ret = DbAdapterManager.Create().SaveGroupsByUserId(userId, groupIds); + var ret = DbContextManager.Create().SaveByUserId(userId, groupIds); if (ret) CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List() { userId }); return ret; } @@ -68,7 +68,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveGroupsByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbAdapterManager.Create().RetrieveGroupsByRoleId(roleId), RetrieveGroupsByRoleIdDataKey); + public static IEnumerable RetrievesByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbContextManager.Create().RetrievesByRoleId(roleId), RetrieveGroupsByRoleIdDataKey); /// /// 根据角色ID以及选定的部门ID,保到角色部门表 @@ -76,9 +76,9 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveGroupsByRoleId(string roleId, IEnumerable groupIds) + public static bool SaveByRoleId(string roleId, IEnumerable groupIds) { - var ret = DbAdapterManager.Create().SaveGroupsByRoleId(roleId, groupIds); + var ret = DbContextManager.Create().SaveByRoleId(roleId, groupIds); if (ret) CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List() { roleId }); return ret; } @@ -88,6 +88,6 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveGroupsByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => DbAdapterManager.Create().RetrieveGroupsByUserName(userName), RetrieveGroupsByUserNameDataKey); + public static IEnumerable RetrievesByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => DbContextManager.Create().RetrievesByUserName(userName), RetrieveGroupsByUserNameDataKey); } } diff --git a/Bootstrap.DataAccess/Helper/LogHelper.cs b/Bootstrap.DataAccess/Helper/LogHelper.cs index 59a1a676..937a929d 100644 --- a/Bootstrap.DataAccess/Helper/LogHelper.cs +++ b/Bootstrap.DataAccess/Helper/LogHelper.cs @@ -13,20 +13,22 @@ namespace Bootstrap.DataAccess /// /// public const string RetrieveLogsDataKey = "LogHelper-RetrieveLogs"; + /// /// 查询所有日志信息 /// /// /// - public static IEnumerable RetrieveLogs() => CacheManager.GetOrAdd(RetrieveLogsDataKey, key => DbAdapterManager.Create().RetrieveLogs()); + public static IEnumerable Retrieves() => CacheManager.GetOrAdd(RetrieveLogsDataKey, key => DbContextManager.Create().Retrieves()); + /// /// 保存新增的日志信息 /// /// /// - public static bool SaveLog(Log p) + public static bool Save(Log p) { - var ret = DbAdapterManager.Create().SaveLog(p); + var ret = DbContextManager.Create().Save(p); if (ret) CacheManager.Clear(RetrieveLogsDataKey); return ret; } diff --git a/Bootstrap.DataAccess/Helper/MenuHelper.cs b/Bootstrap.DataAccess/Helper/MenuHelper.cs index c37bb8aa..2758f5ff 100644 --- a/Bootstrap.DataAccess/Helper/MenuHelper.cs +++ b/Bootstrap.DataAccess/Helper/MenuHelper.cs @@ -27,9 +27,9 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveMenu(BootstrapMenu p) + public static bool Save(BootstrapMenu p) { - var ret = DbAdapterManager.Create().SaveMenu(p); + var ret = DbContextManager.Create().Save(p); if (ret) CacheCleanUtility.ClearCache(menuIds: string.IsNullOrEmpty(p.Id) ? new List() : new List() { p.Id }); return ret; } @@ -39,9 +39,9 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool DeleteMenu(IEnumerable value) + public static bool Delete(IEnumerable value) { - var ret = DbAdapterManager.Create().DeleteMenu(value); + var ret = DbContextManager.Create().Delete(value); if (ret) CacheCleanUtility.ClearCache(menuIds: value); return ret; } @@ -58,7 +58,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveMenusByRoleId(string roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbAdapterManager.Create().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey); + public static IEnumerable RetrieveMenusByRoleId(string roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbContextManager.Create().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey); /// /// @@ -68,7 +68,7 @@ namespace Bootstrap.DataAccess /// public static bool SaveMenusByRoleId(string roleId, IEnumerable menuIds) { - var ret = DbAdapterManager.Create().SaveMenusByRoleId(roleId, menuIds); + var ret = DbContextManager.Create().SaveMenusByRoleId(roleId, menuIds); if (ret) CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List() { roleId }); return ret; } @@ -82,10 +82,9 @@ namespace Bootstrap.DataAccess public static IEnumerable RetrieveAppMenus(string appId, string userName, string activeUrl) { var menus = RetrieveAllMenus(userName).Where(m => m.Category == "1" && m.IsResource == 0); - if (appId != "0") menus = menus.Where(m => m.ApplicationCode == appId); - var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order); - DbHelper.CascadeMenus(menus, root); - DbHelper.ActiveMenu(null, menus, activeUrl); + if (appId != "0") menus = menus.Where(m => m.Application == appId); + var root = DbHelper.CascadeMenus(menus); + DbHelper.ActiveMenu(root, activeUrl); return root; } @@ -100,9 +99,8 @@ namespace Bootstrap.DataAccess public static IEnumerable RetrieveSystemMenus(string userName, string activeUrl = null) { var menus = RetrieveAllMenus(userName).Where(m => m.Category == "0" && m.IsResource == 0); - var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order); - DbHelper.CascadeMenus(menus, root); - DbHelper.ActiveMenu(null, menus, activeUrl); + var root = DbHelper.CascadeMenus(menus); + DbHelper.ActiveMenu(root, activeUrl); return root; } @@ -114,9 +112,7 @@ namespace Bootstrap.DataAccess public static IEnumerable RetrieveMenus(string userName) { var menus = RetrieveAllMenus(userName); - var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order); - DbHelper.CascadeMenus(menus, root); - return root; + return DbHelper.CascadeMenus(menus); } /// @@ -124,6 +120,6 @@ namespace Bootstrap.DataAccess /// /// /// - private static IEnumerable RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbAdapterManager.Create().RetrieveAllMenus(userName), RetrieveMenusAll); + private static IEnumerable RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbContextManager.Create().RetrieveAllMenus(userName), RetrieveMenusAll); } } diff --git a/Bootstrap.DataAccess/Helper/MessageHelper.cs b/Bootstrap.DataAccess/Helper/MessageHelper.cs index a7d7daab..feb1cadf 100644 --- a/Bootstrap.DataAccess/Helper/MessageHelper.cs +++ b/Bootstrap.DataAccess/Helper/MessageHelper.cs @@ -18,30 +18,30 @@ namespace Bootstrap.DataAccess /// 收件箱 /// /// - public static IEnumerable Inbox(string userName) => DbAdapterManager.Create().Inbox(userName); + public static IEnumerable Inbox(string userName) => DbContextManager.Create().Inbox(userName); /// /// 发件箱 /// /// /// - public static IEnumerable SendMail(string userName) => DbAdapterManager.Create().SendMail(userName); + public static IEnumerable SendMail(string userName) => DbContextManager.Create().SendMail(userName); /// /// 垃圾箱 /// /// /// - public static IEnumerable Trash(string userName) => DbAdapterManager.Create().Trash(userName); + public static IEnumerable Trash(string userName) => DbContextManager.Create().Trash(userName); /// /// 标旗 /// /// /// - public static IEnumerable Mark(string userName) => DbAdapterManager.Create().Flag(userName); + public static IEnumerable Mark(string userName) => DbContextManager.Create().Flag(userName); /// /// 获取Header处显示的消息列表 /// /// /// - public static IEnumerable RetrieveMessagesHeader(string userName) => CacheManager.GetOrAdd(RetrieveMessageDataKey, key => DbAdapterManager.Create().RetrieveMessagesHeader(userName).OrderByDescending(n => n.SendTime)); + public static IEnumerable Retrieves(string userName) => CacheManager.GetOrAdd(RetrieveMessageDataKey, key => DbContextManager.Create().RetrieveHeaders(userName).OrderByDescending(n => n.SendTime)); } } diff --git a/Bootstrap.DataAccess/Helper/RoleHelper.cs b/Bootstrap.DataAccess/Helper/RoleHelper.cs index 08dd2473..a3e9ca49 100644 --- a/Bootstrap.DataAccess/Helper/RoleHelper.cs +++ b/Bootstrap.DataAccess/Helper/RoleHelper.cs @@ -21,7 +21,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveRoles() => CacheManager.GetOrAdd(RetrieveRolesDataKey, key => DbAdapterManager.Create().RetrieveRoles()); + public static IEnumerable Retrieves() => CacheManager.GetOrAdd(RetrieveRolesDataKey, key => DbContextManager.Create().Retrieves()); /// /// 保存用户角色关系 @@ -29,9 +29,9 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveRolesByUserId(string userId, IEnumerable roleIds) + public static bool SaveByUserId(string userId, IEnumerable roleIds) { - var ret = DbAdapterManager.Create().SaveRolesByUserId(userId, roleIds); + var ret = DbContextManager.Create().SaveByUserId(userId, roleIds); if (ret) CacheCleanUtility.ClearCache(userIds: new List() { userId }, roleIds: roleIds); return ret; } @@ -40,15 +40,15 @@ namespace Bootstrap.DataAccess /// 查询某个用户所拥有的角色 /// /// - public static IEnumerable RetrieveRolesByUserId(string userId) => CacheManager.GetOrAdd($"{RetrieveRolesByUserIdDataKey}-{userId}", key => DbAdapterManager.Create().RetrieveRolesByUserId(userId), RetrieveRolesByUserIdDataKey); + public static IEnumerable RetrievesByUserId(string userId) => CacheManager.GetOrAdd($"{RetrieveRolesByUserIdDataKey}-{userId}", key => DbContextManager.Create().RetrievesByUserId(userId), RetrieveRolesByUserIdDataKey); /// /// 删除角色表 /// /// - public static bool DeleteRole(IEnumerable value) + public static bool Delete(IEnumerable value) { - var ret = DbAdapterManager.Create().DeleteRole(value); + var ret = DbContextManager.Create().Delete(value); if (ret) CacheCleanUtility.ClearCache(roleIds: value); return ret; } @@ -58,9 +58,9 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveRole(Role p) + public static bool Save(Role p) { - var ret = DbAdapterManager.Create().SaveRole(p); + var ret = DbContextManager.Create().Save(p); if (ret) CacheCleanUtility.ClearCache(roleIds: string.IsNullOrEmpty(p.Id) ? new List() : new List { p.Id }); return ret; } @@ -70,7 +70,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveRolesByMenuId(string menuId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId), key => DbAdapterManager.Create().RetrieveRolesByMenuId(menuId), RetrieveRolesByMenuIdDataKey); + public static IEnumerable RetrievesByMenuId(string menuId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId), key => DbContextManager.Create().RetrievesByMenuId(menuId), RetrieveRolesByMenuIdDataKey); /// /// @@ -78,9 +78,9 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SavaRolesByMenuId(string menuId, IEnumerable roleIds) + public static bool SavaByMenuId(string menuId, IEnumerable roleIds) { - var ret = DbAdapterManager.Create().SavaRolesByMenuId(menuId, roleIds); + var ret = DbContextManager.Create().SavaByMenuId(menuId, roleIds); if (ret) CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List() { menuId }); return ret; } @@ -90,7 +90,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveRolesByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId), key => DbAdapterManager.Create().RetrieveRolesByGroupId(groupId), RetrieveRolesByGroupIdDataKey); + public static IEnumerable RetrievesByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId), key => DbContextManager.Create().RetrievesByGroupId(groupId), RetrieveRolesByGroupIdDataKey); /// /// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息 @@ -98,9 +98,9 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveRolesByGroupId(string groupId, IEnumerable roleIds) + public static bool SaveByGroupId(string groupId, IEnumerable roleIds) { - var ret = DbAdapterManager.Create().SaveRolesByGroupId(groupId, roleIds); + var ret = DbContextManager.Create().SaveByGroupId(groupId, roleIds); if (ret) CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List() { groupId }); return ret; } @@ -110,13 +110,13 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveRolesByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUserNameDataKey, userName), key => DbAdapterManager.Create().RetrieveRolesByUserName(userName), RetrieveRolesByUserNameDataKey); + public static IEnumerable RetrieveRolesByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUserNameDataKey, userName), key => DbContextManager.Create().RetrieveRolesByUserName(userName), RetrieveRolesByUserNameDataKey); /// /// /// /// /// - public static IEnumerable RetrieveRolesByUrl(string url) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUrlDataKey, url), key => DbAdapterManager.Create().RetrieveRolesByUrl(url), RetrieveRolesByUrlDataKey); + public static IEnumerable RetrieveRolesByUrl(string url) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUrlDataKey, url), key => DbContextManager.Create().RetrieveRolesByUrl(url), RetrieveRolesByUrlDataKey); } } \ No newline at end of file diff --git a/Bootstrap.DataAccess/Helper/TaskHelper.cs b/Bootstrap.DataAccess/Helper/TaskHelper.cs index bde2deb1..85fa6fae 100644 --- a/Bootstrap.DataAccess/Helper/TaskHelper.cs +++ b/Bootstrap.DataAccess/Helper/TaskHelper.cs @@ -13,10 +13,11 @@ namespace Bootstrap.DataAccess /// /// public const string RetrieveTasksDataKey = "TaskHelper-RetrieveTasks"; + /// /// 查询所有任务 /// /// - public static IEnumerable RetrieveTasks() => CacheManager.GetOrAdd(RetrieveTasksDataKey, key => DbAdapterManager.Create().RetrieveTasks()); + public static IEnumerable Retrieves() => CacheManager.GetOrAdd(RetrieveTasksDataKey, key => DbContextManager.Create().Retrieves()); } } diff --git a/Bootstrap.DataAccess/Helper/UserHelper.cs b/Bootstrap.DataAccess/Helper/UserHelper.cs index f51f385b..b72cc12a 100644 --- a/Bootstrap.DataAccess/Helper/UserHelper.cs +++ b/Bootstrap.DataAccess/Helper/UserHelper.cs @@ -15,45 +15,51 @@ namespace Bootstrap.DataAccess public const string RetrieveUsersByGroupIdDataKey = "UserHelper-RetrieveUsersByGroupId"; public const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers"; public const string RetrieveUsersByNameDataKey = "BootstrapUser-RetrieveUsersByName"; + /// /// 查询所有用户 /// /// /// - public static IEnumerable RetrieveUsers() => CacheManager.GetOrAdd(RetrieveUsersDataKey, key => DbAdapterManager.Create().RetrieveUsers()); + public static IEnumerable Retrieves() => CacheManager.GetOrAdd(RetrieveUsersDataKey, key => DbContextManager.Create().Retrieves()); + /// /// /// /// /// /// - public static bool Authenticate(string userName, string password) => DbAdapterManager.Create().Authenticate(userName, password); + public static bool Authenticate(string userName, string password) => DbContextManager.Create().Authenticate(userName, password); + /// /// 查询所有的新注册用户 /// /// - public static IEnumerable RetrieveNewUsers() => CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key => DbAdapterManager.Create().RetrieveNewUsers()); + public static IEnumerable RetrieveNewUsers() => CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key => DbContextManager.Create().RetrieveNewUsers()); + /// /// 删除用户 /// /// - public static bool DeleteUser(IEnumerable value) + public static bool Delete(IEnumerable value) { - var ret = DbAdapterManager.Create().DeleteUser(value); + var ret = DbContextManager.Create().Delete(value); if (ret) CacheCleanUtility.ClearCache(userIds: value); return ret; } + /// /// 保存新建 /// /// /// - public static bool SaveUser(User p) + public static bool Save(User p) { - var ret = DbAdapterManager.Create().SaveUser(p); + var ret = DbContextManager.Create().Save(p); if (ret) CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(p.Id) ? new List() : new List() { p.Id }); return ret; } + /// /// /// @@ -61,24 +67,26 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool UpdateUser(string id, string password, string displayName) + public static bool Update(string id, string password, string displayName) { - var ret = DbAdapterManager.Create().UpdateUser(id, password, displayName); + var ret = DbContextManager.Create().Update(id, password, displayName); if (ret) CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(id) ? new List() : new List() { id }); return ret; } + /// /// /// /// /// /// - public static bool ApproveUser(string id, string approvedBy) + public static bool Approve(string id, string approvedBy) { - var ret = DbAdapterManager.Create().ApproveUser(id, approvedBy); + var ret = DbContextManager.Create().Approve(id, approvedBy); if (ret) CacheCleanUtility.ClearCache(userIds: new List() { id }); return ret; } + /// /// /// @@ -86,7 +94,8 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool ChangePassword(string userName, string password, string newPass) => DbAdapterManager.Create().ChangePassword(userName, password, newPass); + public static bool ChangePassword(string userName, string password, string newPass) => DbContextManager.Create().ChangePassword(userName, password, newPass); + /// /// /// @@ -94,48 +103,53 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool RejectUser(string id, string rejectBy) + public static bool Reject(string id, string rejectBy) { - var ret = DbAdapterManager.Create().RejectUser(id, rejectBy); + var ret = DbContextManager.Create().Reject(id, rejectBy); if (ret) CacheCleanUtility.ClearCache(userIds: new List() { id }); return ret; } + /// /// 通过roleId获取所有用户 /// /// /// - public static IEnumerable RetrieveUsersByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId), k => DbAdapterManager.Create().RetrieveUsersByRoleId(roleId), RetrieveUsersByRoleIdDataKey); + public static IEnumerable RetrievesByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId), k => DbContextManager.Create().RetrievesByRoleId(roleId), RetrieveUsersByRoleIdDataKey); + /// /// 通过角色ID保存当前授权用户(插入) /// /// 角色ID /// 用户ID数组 /// - public static bool SaveUsersByRoleId(string roleId, IEnumerable userIds) + public static bool SaveByRoleId(string roleId, IEnumerable userIds) { - var ret = DbAdapterManager.Create().SaveUsersByRoleId(roleId, userIds); + var ret = DbContextManager.Create().SaveByRoleId(roleId, userIds); if (ret) CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List() { roleId }); return ret; } + /// /// 通过groupId获取所有用户 /// /// /// - public static IEnumerable RetrieveUsersByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId), k => DbAdapterManager.Create().RetrieveUsersByGroupId(groupId), RetrieveUsersByRoleIdDataKey); + public static IEnumerable RetrievesByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId), k => DbContextManager.Create().RetrievesByGroupId(groupId), RetrieveUsersByRoleIdDataKey); + /// /// 通过部门ID保存当前授权用户(插入) /// /// GroupID /// 用户ID数组 /// - public static bool SaveUsersByGroupId(string groupId, IEnumerable userIds) + public static bool SaveByGroupId(string groupId, IEnumerable userIds) { - var ret = DbAdapterManager.Create().SaveUsersByGroupId(groupId, userIds); + var ret = DbContextManager.Create().SaveByGroupId(groupId, userIds); if (ret) CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List() { groupId }); return ret; } + /// 根据用户名修改用户头像 /// /// @@ -143,10 +157,11 @@ namespace Bootstrap.DataAccess /// public static bool SaveUserIconByName(string userName, string iconName) { - var ret = DbAdapterManager.Create().SaveUserIconByName(userName, iconName); + var ret = DbContextManager.Create().SaveUserIconByName(userName, iconName); if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*"); return ret; } + /// /// /// @@ -155,7 +170,7 @@ namespace Bootstrap.DataAccess /// public static bool SaveDisplayName(string userName, string displayName) { - var ret = DbAdapterManager.Create().SaveDisplayName(userName, displayName); + var ret = DbContextManager.Create().SaveDisplayName(userName, displayName); if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*"); return ret; } @@ -168,15 +183,16 @@ namespace Bootstrap.DataAccess /// public static bool SaveUserCssByName(string userName, string cssName) { - var ret = DbAdapterManager.Create().SaveUserCssByName(userName, cssName); + var ret = DbContextManager.Create().SaveUserCssByName(userName, cssName); if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{UserHelper.RetrieveUsersDataKey}*"); return ret; } + /// /// /// /// /// - public static BootstrapUser RetrieveUserByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName), k => DbAdapterManager.Create().RetrieveUserByUserName(userName), RetrieveUsersByNameDataKey); + public static BootstrapUser RetrieveUserByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName), k => DbContextManager.Create().RetrieveUserByUserName(userName), RetrieveUsersByNameDataKey); } } diff --git a/Bootstrap.DataAccess/Log.cs b/Bootstrap.DataAccess/Log.cs index 2a43c3c3..f37be3a7 100644 --- a/Bootstrap.DataAccess/Log.cs +++ b/Bootstrap.DataAccess/Log.cs @@ -2,8 +2,6 @@ using Longbow.Configuration; using System; using System.Collections.Generic; -using System.Data; -using System.Data.Common; namespace Bootstrap.DataAccess { @@ -46,35 +44,14 @@ namespace Bootstrap.DataAccess /// 获取/设置 请求网址 /// public string RequestUrl { get; set; } + /// /// 查询所有日志信息 /// /// /// - public virtual IEnumerable RetrieveLogs() - { - string sql = "select * from Logs where LogTime > @LogTime"; - List logs = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now.AddDays(-7), DbType.DateTime)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - logs.Add(new Log() - { - Id = reader[0].ToString(), - CRUD = (string)reader[1], - UserName = (string)reader[2], - LogTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), - ClientIp = (string)reader[4], - ClientAgent = (string)reader[5], - RequestUrl = (string)reader[6] - }); - } - } - return logs; - } + public virtual IEnumerable Retrieves() => DbManager.Db.Fetch(); + /// /// 删除日志信息 /// @@ -84,34 +61,23 @@ namespace Bootstrap.DataAccess { System.Threading.Tasks.Task.Run(() => { - string sql = $"delete from Logs where LogTime < @LogTime"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepLogsPeriod"], 1)), DbType.DateTime)); - DbAccessManager.DBAccess.ExecuteNonQuery(cmd); + var dtm = DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepLogsPeriod"], 1)); + DbManager.Db.Execute("delete from Logs where LogTime < @0", dtm); }); } + /// /// 保存新增的日志信息 /// /// /// - public virtual bool SaveLog(Log p) + public virtual bool Save(Log p) { if (p == null) throw new ArgumentNullException(nameof(p)); - bool ret = false; - string sql = "Insert Into Logs (CRUD, UserName, LogTime, ClientIp, ClientAgent, RequestUrl) Values (@CRUD, @UserName, @LogTime, @ClientIp, @ClientAgent, @RequestUrl)"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@CRUD", p.CRUD)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", p.UserName)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now, DbType.DateTime)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ClientIp", p.ClientIp)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ClientAgent", p.ClientAgent)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } DeleteLogAsync(); - return ret; + p.LogTime = DateTime.Now; + DbManager.Db.Save(p); + return true; } } } diff --git a/Bootstrap.DataAccess/Menu.cs b/Bootstrap.DataAccess/Menu.cs index 66374081..f8f533c2 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -1,11 +1,7 @@ using Bootstrap.Security; using Bootstrap.Security.DataAccess; -using Longbow.Data; using System; using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Data.SqlClient; using System.Linq; namespace Bootstrap.DataAccess @@ -19,30 +15,23 @@ namespace Bootstrap.DataAccess /// 删除菜单信息 /// /// - public virtual bool DeleteMenu(IEnumerable value) + public virtual bool Delete(IEnumerable value) { - bool ret = false; - var ids = string.Join(",", value); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var ret = false; + var db = DbManager.Db; + try { - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from NavigationRole where NavigationID in ({ids})")) - { - try - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from Navigations where ID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - transaction.CommitTransaction(); - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } + var ids = string.Join(",", value); + db.BeginTransaction(); + db.Execute($"delete from NavigationRole where NavigationID in ({ids})"); + db.Execute($"delete from Navigations where ID in ({ids})"); + db.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } @@ -51,31 +40,15 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveMenu(BootstrapMenu p) + public virtual bool Save(BootstrapMenu p) { - if (string.IsNullOrEmpty(p.Name)) return false; - bool ret = false; + if (string.IsNullOrEmpty(p.Name)) throw new ArgumentNullException(nameof(p.Name)); + 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); - string sql = string.IsNullOrEmpty(p.Id) ? - "Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category, Target, IsResource, Application) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource, @ApplicationCode)" : - "Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource, Application = @ApplicationCode where ID = @ID"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", p.Name)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Order", p.Order)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Icon", DbAdapterManager.ToDBValue(p.Icon))); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Url", DbAdapterManager.ToDBValue(p.Url))); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", p.Category)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Target", p.Target)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; + DbManager.Db.Save(p); + return true; } /// /// 查询某个角色所配置的菜单 @@ -84,22 +57,7 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable RetrieveMenusByRoleId(string roleId) { - var menus = new List(); - string sql = "select NavigationID from NavigationRole where RoleID = @RoleID"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - menus.Add(new BootstrapMenu() - { - Id = reader[0].ToString() - }); - } - } - } + var menus = DbManager.Db.Fetch("select NavigationID as Id from NavigationRole where RoleID = @0", roleId); return menus.Select(m => new { m.Id }); } /// @@ -111,36 +69,19 @@ namespace Bootstrap.DataAccess public virtual bool SaveMenusByRoleId(string roleId, IEnumerable menuIds) { bool ret = false; - DataTable dt = new DataTable(); - dt.Columns.Add("RoleID", typeof(int)); - dt.Columns.Add("NavigationID", typeof(int)); - menuIds.ToList().ForEach(menuId => dt.Rows.Add(roleId, menuId)); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + try { - try - { - //删除菜单角色表该角色所有的菜单 - string sql = $"delete from NavigationRole where RoleID = {roleId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入菜单角色表 - using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction)) - { - bulk.DestinationTableName = "NavigationRole"; - bulk.ColumnMappings.Add("RoleID", "RoleID"); - bulk.ColumnMappings.Add("NavigationID", "NavigationID"); - bulk.WriteToServer(dt); - transaction.CommitTransaction(); - } - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } + db.BeginTransaction(); + db.Execute("delete from NavigationRole where RoleID = @0", roleId); + db.InsertBulk("NavigationRole", menuIds.Select(g => new { NavigationID = g, RoleID = roleId })); + db.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } diff --git a/Bootstrap.DataAccess/Message.cs b/Bootstrap.DataAccess/Message.cs index 46fa59bb..155aa8b4 100644 --- a/Bootstrap.DataAccess/Message.cs +++ b/Bootstrap.DataAccess/Message.cs @@ -1,8 +1,5 @@ -using Longbow; -using System; +using System; using System.Collections.Generic; -using System.Data; -using System.Data.Common; using System.Linq; namespace Bootstrap.DataAccess @@ -16,102 +13,96 @@ namespace Bootstrap.DataAccess /// 消息主键 数据库自增 /// public string Id { get; set; } + /// /// 标题 /// public string Title { get; set; } + /// /// 内容 /// public string Content { get; set; } + /// /// 发消息人 /// public string From { get; set; } + /// /// 收消息人 /// public string To { get; set; } + /// /// 消息发送时间 /// public DateTime SendTime { get; set; } + /// /// 消息状态:0-未读,1-已读 和Dict表的通知消息关联 /// public string Status { get; set; } + /// /// 标旗状态:0-未标旗,1-已标旗 /// public int Mark { get; set; } + /// /// 删除状态:0-未删除,1-已删除 /// public int IsDelete { get; set; } + /// /// 消息标签:0-一般,1-紧要 和Dict表的消息标签关联 /// public string Label { get; set; } + /// /// 获得/设置 标签名称 /// public string LabelName { get; set; } + /// /// 获得/设置 时间描述 2分钟内为刚刚 /// public string Period { get; set; } + /// /// 获得/设置 发件人头像 /// public string FromIcon { get; set; } + /// /// 获得/设置 发件人昵称 /// public string FromDisplayName { get; set; } + + //TODO: SQL语句不兼容 /// /// 所有有关userName所有消息列表 /// /// /// - protected virtual IEnumerable RetrieveMessages(string userName) + protected virtual IEnumerable Retrieves(string userName) { - string sql = "select m.*, d.Name, isnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = N'消息标签' and d.Define = 0 left join Dicts i on i.Category = N'头像地址' and i.Name = N'头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc"; - List messages = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - messages.Add(new Message() - { - Id = reader[0].ToString(), - Title = (string)reader[1], - Content = (string)reader[2], - From = (string)reader[3], - To = (string)reader[4], - SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue), - Status = (string)reader[6], - Mark = (int)reader[7], - IsDelete = (int)reader[8], - Label = (string)reader[9], - LabelName = LgbConvert.ReadValue(reader[10], string.Empty), - FromIcon = (string)reader[11], - FromDisplayName = (string)reader[12] - }); - } - } - return messages; + var db = DbManager.Db; + 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 = "消息标签" }); } + /// /// 收件箱 /// /// public virtual IEnumerable Inbox(string userName) { - var messageRet = RetrieveMessages(userName); + var messageRet = Retrieves(userName); return messageRet.Where(n => n.To.Equals(userName, StringComparison.OrdinalIgnoreCase)); } + /// /// 发件箱 /// @@ -119,9 +110,10 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable SendMail(string userName) { - var messageRet = RetrieveMessages(userName); + var messageRet = Retrieves(userName); return messageRet.Where(n => n.From.Equals(userName, StringComparison.OrdinalIgnoreCase)); } + /// /// 垃圾箱 /// @@ -129,9 +121,10 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable Trash(string userName) { - var messageRet = RetrieveMessages(userName); + var messageRet = Retrieves(userName); return messageRet.Where(n => n.IsDelete == 1); } + /// /// 标旗 /// @@ -139,15 +132,16 @@ namespace Bootstrap.DataAccess /// public virtual IEnumerable Flag(string userName) { - var messageRet = RetrieveMessages(userName); + var messageRet = Retrieves(userName); return messageRet.Where(n => n.Mark == 1); } + /// /// 获取Header处显示的消息列表 /// /// /// - public virtual IEnumerable RetrieveMessagesHeader(string userName) + public virtual IEnumerable RetrieveHeaders(string userName) { var messageRet = Inbox(userName); messageRet.AsParallel().ForAll(n => diff --git a/Bootstrap.DataAccess/Role.cs b/Bootstrap.DataAccess/Role.cs index f9d04fb3..ebb2dcbd 100644 --- a/Bootstrap.DataAccess/Role.cs +++ b/Bootstrap.DataAccess/Role.cs @@ -1,10 +1,6 @@ using Bootstrap.Security.DataAccess; -using Longbow.Data; using System; using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Data.SqlClient; using System.Linq; namespace Bootstrap.DataAccess @@ -38,25 +34,7 @@ namespace Bootstrap.DataAccess /// 查询所有角色 /// /// - public virtual IEnumerable RetrieveRoles() - { - string sql = "select * from Roles"; - var roles = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - roles.Add(new Role() - { - Id = reader[0].ToString(), - RoleName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2] - }); - } - } - return roles; - } + public virtual IEnumerable Retrieves() => DbManager.Db.Fetch(); /// /// 保存用户角色关系 @@ -64,43 +42,23 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveRolesByUserId(string userId, IEnumerable roleIds) + public virtual bool SaveByUserId(string userId, IEnumerable roleIds) { var ret = false; - DataTable dt = new DataTable(); - dt.Columns.Add("UserID", typeof(int)); - dt.Columns.Add("RoleID", typeof(int)); - //判断用户是否选定角色 - roleIds.ToList().ForEach(roleId => dt.Rows.Add(userId, roleId)); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + try { - try - { - // delete user from config table - string sql = $"delete from UserRole where UserID = {userId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - if (dt.Rows.Count > 0) - { - // insert batch data into config table - using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction)) - { - bulk.DestinationTableName = "UserRole"; - bulk.ColumnMappings.Add("UserID", "UserID"); - bulk.ColumnMappings.Add("RoleID", "RoleID"); - bulk.WriteToServer(dt); - } - } - transaction.CommitTransaction(); - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } + 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.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } @@ -109,62 +67,31 @@ namespace Bootstrap.DataAccess /// 查询某个用户所拥有的角色 /// /// - public virtual IEnumerable RetrieveRolesByUserId(string userId) - { - List roles = new List(); - string sql = "select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end status from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @UserID"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - roles.Add(new Role() - { - Id = reader[0].ToString(), - RoleName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } - } - return roles; - } + 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 bool DeleteRole(IEnumerable value) + public virtual bool Delete(IEnumerable value) { bool ret = false; var ids = string.Join(",", value); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + try { - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from UserRole where RoleID in ({ids})")) - { - try - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from RoleGroup where RoleID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from NavigationRole where RoleID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from Roles where ID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - transaction.CommitTransaction(); - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } + db.BeginTransaction(); + db.Execute($"delete from UserRole where RoleID in ({ids})"); + db.Execute($"delete from RoleGroup where RoleID in ({ids})"); + db.Execute($"delete from NavigationRole where RoleID in ({ids})"); + db.Execute($"delete from Roles where ID in ({ids})"); + db.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } @@ -174,22 +101,13 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveRole(Role p) + public virtual bool Save(Role p) { - bool ret = false; 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); - string sql = string.IsNullOrEmpty(p.Id) ? - "Insert Into Roles (RoleName, Description) Values (@RoleName, @Description)" : - "Update Roles set RoleName = @RoleName, Description = @Description where ID = @ID"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleName", p.RoleName)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description))); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; + + DbManager.Db.Save(p); + return true; } /// @@ -197,27 +115,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveRolesByMenuId(string menuId) - { - string sql = "select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end status from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @NavigationID"; - List roles = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@NavigationID", menuId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - roles.Add(new Role() - { - Id = reader[0].ToString(), - RoleName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } - } - return roles; - } + 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); /// /// @@ -225,42 +123,23 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SavaRolesByMenuId(string menuId, IEnumerable roleIds) + public virtual bool SavaByMenuId(string menuId, IEnumerable roleIds) { var ret = false; - DataTable dt = new DataTable(); - dt.Columns.Add("NavigationID", typeof(int)); - dt.Columns.Add("RoleID", typeof(int)); - //判断用户是否选定角色 - roleIds.ToList().ForEach(roleId => dt.Rows.Add(menuId, roleId)); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + db.BeginTransaction(); + try { - try - { - // delete role from config table - string sql = $"delete from NavigationRole where NavigationID = {menuId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - // insert batch data into config table - using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction)) - { - bulk.BatchSize = 1000; - bulk.DestinationTableName = "NavigationRole"; - bulk.ColumnMappings.Add("NavigationID", "NavigationID"); - bulk.ColumnMappings.Add("RoleID", "RoleID"); - bulk.WriteToServer(dt); - transaction.CommitTransaction(); - } - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } + // 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.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } @@ -270,27 +149,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveRolesByGroupId(string groupId) - { - List roles = new List(); - string sql = "select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end status from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @GroupID"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - roles.Add(new Role() - { - Id = reader[0].ToString(), - RoleName = (string)reader[1], - Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], - Checked = (string)reader[3] - }); - } - } - return roles; - } + 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); /// /// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息 @@ -298,42 +157,22 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveRolesByGroupId(string groupId, IEnumerable roleIds) + public virtual bool SaveByGroupId(string groupId, IEnumerable roleIds) { var ret = false; - //构造表格 - DataTable dt = new DataTable(); - dt.Columns.Add("RoleID", typeof(int)); - dt.Columns.Add("GroupID", typeof(int)); - roleIds.ToList().ForEach(roleId => dt.Rows.Add(roleId, groupId)); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + try { - try - { - // delete user from config table - string sql = $"delete from RoleGroup where GroupID = {groupId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - // insert batch data into config table - using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction)) - { - bulk.BatchSize = 1000; - bulk.DestinationTableName = "RoleGroup"; - bulk.ColumnMappings.Add("RoleID", "RoleID"); - bulk.ColumnMappings.Add("GroupID", "GroupID"); - bulk.WriteToServer(dt); - transaction.CommitTransaction(); - } - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } + // 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.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } diff --git a/Bootstrap.DataAccess/Task.cs b/Bootstrap.DataAccess/Task.cs index 4eb09e9f..0a796cfc 100644 --- a/Bootstrap.DataAccess/Task.cs +++ b/Bootstrap.DataAccess/Task.cs @@ -1,72 +1,57 @@ -using Longbow; -using System; +using System; using System.Collections.Generic; -using System.Data; -using System.Data.Common; namespace Bootstrap.DataAccess { + /// + /// + /// public class Task { /// /// 获取/设置 任务ID /// public string Id { get; set; } + /// /// 获取/设置 任务名称 /// public string TaskName { get; set; } + /// /// 获取/设置 分配人 /// public string AssignName { get; set; } + /// /// 获得/设置 分配人昵称 /// public string AssignDisplayName { get; set; } + /// /// 获取/设置 完成任务人 /// public string UserName { get; set; } + /// /// 获取/设置 任务所需时间(天) /// public int TaskTime { get; set; } + /// /// 获取/设置 任务进度 /// public double TaskProgress { get; set; } + /// /// 获取/设置 分配时间 /// public DateTime AssignTime { get; set; } + /// /// 查询所有任务 /// /// - public virtual IEnumerable RetrieveTasks() - { - string sql = "select top 100 t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc"; - List tasks = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - tasks.Add(new Task() - { - Id = reader[0].ToString(), - TaskName = (string)reader[1], - AssignName = (string)reader[2], - UserName = (string)reader[3], - TaskTime = (int)reader[4], - TaskProgress = (double)reader[5], - AssignTime = LgbConvert.ReadValue(reader[6], DateTime.MinValue), - AssignDisplayName = (string)reader[7] - }); - } - } - return tasks; - } + 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"); } } diff --git a/Bootstrap.DataAccess/User.cs b/Bootstrap.DataAccess/User.cs index cb5c194d..60366d84 100644 --- a/Bootstrap.DataAccess/User.cs +++ b/Bootstrap.DataAccess/User.cs @@ -1,13 +1,8 @@ using Bootstrap.Security; using Bootstrap.Security.DataAccess; -using Longbow; -using Longbow.Data; using Longbow.Security.Cryptography; using System; using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Data.SqlClient; using System.Linq; namespace Bootstrap.DataAccess @@ -21,46 +16,57 @@ namespace Bootstrap.DataAccess /// 获得/设置 用户主键ID /// public string Id { get; set; } + /// /// 获取/设置 密码 /// public string Password { get; set; } + /// /// 获取/设置 密码盐 /// public string PassSalt { get; set; } + /// /// 获取/设置 角色用户关联状态 checked 标示已经关联 '' 标示未关联 /// public string Checked { get; set; } + /// /// 获得/设置 用户注册时间 /// public DateTime RegisterTime { get; set; } + /// /// 获得/设置 用户被批复时间 /// - public DateTime ApprovedTime { get; set; } + public DateTime? ApprovedTime { get; set; } + /// /// 获得/设置 用户批复人 /// public string ApprovedBy { get; set; } + /// /// 获得/设置 用户的申请理由 /// public string Description { get; set; } + /// /// 获得/设置 用户当前状态 0 表示管理员注册用户 1 表示用户注册 2 表示更改密码 3 表示更改个人皮肤 4 表示更改显示名称 5 批复新用户注册操作 /// public UserStates UserStatus { get; set; } + /// /// 获得/设置 通知描述 2分钟内为刚刚 /// public string Period { get; set; } + /// /// 获得/设置 新密码 /// public string NewPassword { get; set; } + /// /// 验证用户登陆账号与密码正确 /// @@ -69,25 +75,11 @@ namespace Bootstrap.DataAccess /// public virtual bool Authenticate(string userName, string password) { - if (string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(password)) return false; - string oldPassword = null; - string passwordSalt = null; - string sql = "select Password, PassSalt from Users where ApprovedTime is not null and UserName = @UserName"; - var db = DbAccessManager.DBAccess; - using (DbCommand cmd = db.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(db.CreateParameter("@UserName", userName)); - using (DbDataReader reader = db.ExecuteReader(cmd)) - { - if (reader.Read()) - { - oldPassword = (string)reader[0]; - passwordSalt = (string)reader[1]; - } - } - } - return !string.IsNullOrEmpty(passwordSalt) && oldPassword == LgbCryptography.ComputeHash(password, passwordSalt); + var user = DbManager.Db.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); } + /// /// /// @@ -100,159 +92,87 @@ namespace Bootstrap.DataAccess bool ret = false; if (Authenticate(userName, password)) { - string sql = "Update Users set Password = @Password, PassSalt = @PassSalt where UserName = @userName"; + string sql = "set Password = @0, PassSalt = @1 where UserName = @2"; var passSalt = LgbCryptography.GenerateSalt(); var newPassword = LgbCryptography.ComputeHash(newPass, passSalt); - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Password", newPassword)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } + ret = DbManager.Db.Update(sql, newPassword, passSalt, userName) == 1; } return ret; } + /// /// 查询所有用户 /// /// /// - public virtual IEnumerable RetrieveUsers() - { - List users = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null"); + public virtual IEnumerable Retrieves() => DbManager.Db.Fetch("select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null"); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - users.Add(new User() - { - Id = reader[0].ToString(), - UserName = (string)reader[1], - DisplayName = (string)reader[2], - RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), - ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue), - ApprovedBy = reader.IsDBNull(5) ? string.Empty : (string)reader[5], - Description = (string)reader[6] - }); - } - } - return users; - } /// /// 查询所有的新注册用户 /// /// - public virtual IEnumerable RetrieveNewUsers() - { - string sql = "select ID, UserName, DisplayName, RegisterTime, Description from Users Where ApprovedTime is null order by RegisterTime desc"; - List users = new List(); - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - users.Add(new User() - { - Id = reader[0].ToString(), - UserName = (string)reader[1], - DisplayName = (string)reader[2], - RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), - Description = (string)reader[4] - }); - } - } - return users; - } + 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 bool DeleteUser(IEnumerable value) + public virtual bool Delete(IEnumerable value) { bool ret = false; - var ids = string.Join(",", value); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + try { - try - { - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"Delete from UserRole where UserID in ({ids})")) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from UserGroup where UserID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from Users where ID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - transaction.CommitTransaction(); - ret = true; - } - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } + var ids = string.Join(",", value); + db.BeginTransaction(); + db.Execute($"Delete from UserRole where UserID in ({ids})"); + db.Execute($"delete from UserGroup where UserID in ({ids})"); + db.Execute($"delete from Users where ID in ({ids})"); + db.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } + /// /// 新建前台User View调用/注册用户调用 /// /// /// - public virtual bool SaveUser(User p) + public virtual bool Save(User p) { var ret = false; if (string.IsNullOrEmpty(p.Id) && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500); if (p.UserName.Length > 50) p.UserName = p.UserName.Substring(0, 50); p.PassSalt = LgbCryptography.GenerateSalt(); p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt); + p.RegisterTime = DateTime.Now; - var db = DbAccessManager.DBAccess; - using (TransactionPackage transaction = db.BeginTransaction()) + var db = DbManager.Db; + try { - try + db.BeginTransaction(); + if (!db.Exists("where UserName = @0", p.UserName)) { - using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select UserName from Users Where UserName = @userName")) - { - cmd.Parameters.Add(db.CreateParameter("@userName", p.UserName)); - var un = db.ExecuteScalar(cmd, transaction); - if (DbAdapterManager.ToObjectValue(un) == null) - { - object approveTime = DBNull.Value; - if (p.ApprovedTime != DateTime.MinValue) approveTime = p.ApprovedTime; - cmd.CommandText = "Insert Into Users (UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedBy, ApprovedTime, Description) values (@userName, @password, @passSalt, @displayName, @registerTime, @approvedBy, @approveTime, @description)"; - cmd.Parameters.Add(db.CreateParameter("@password", p.Password)); - cmd.Parameters.Add(db.CreateParameter("@passSalt", p.PassSalt)); - cmd.Parameters.Add(db.CreateParameter("@registerTime", DateTime.Now)); - cmd.Parameters.Add(db.CreateParameter("@displayName", p.DisplayName)); - cmd.Parameters.Add(db.CreateParameter("@approvedBy", DbAdapterManager.ToDBValue(p.ApprovedBy))); - cmd.Parameters.Add(db.CreateParameter("@approveTime", approveTime)); - cmd.Parameters.Add(db.CreateParameter("@description", p.Description)); - db.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"insert into UserRole (UserID, RoleID) select ID, (select ID from Roles where RoleName = 'Default') RoleId from Users where UserName = '{p.UserName}'"; - cmd.Parameters.Clear(); - db.ExecuteNonQuery(cmd, transaction); - - transaction.CommitTransaction(); - ret = true; - } - } - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; + db.Insert(p); + db.Execute("insert into UserRole (UserID, RoleID) select ID, (select ID from Roles where RoleName = 'Default') RoleId from Users where UserName = @0", p.UserName); } + db.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } + /// /// User List 视图保存按钮调用 /// @@ -260,278 +180,148 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool UpdateUser(string id, string password, string displayName) + public virtual bool Update(string id, string password, string displayName) { - bool ret = false; - string sql = "Update Users set Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @id"; var passSalt = LgbCryptography.GenerateSalt(); var newPassword = LgbCryptography.ComputeHash(password, passSalt); - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@DisplayName", displayName)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Password", newPassword)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; + return DbManager.Db.Update("set Password = @1, PassSalt = @2, DisplayName = @3 where ID = @0", id, newPassword, passSalt, displayName) == 1; } + /// /// /// /// /// /// - public virtual bool ApproveUser(string id, string approvedBy) - { - var ret = false; - var sql = "update Users set ApprovedTime = @ApproveTime, ApprovedBy = @approvedBy where ID = @id"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ApproveTime", DateTime.Now, DbType.DateTime)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; - } + 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 RejectUser(string id, string rejectBy) + public virtual bool Reject(string id, string rejectBy) { var ret = false; - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + try { - try - { - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"insert into RejectUsers (UserName, DisplayName, RegisterTime, RejectedBy, RejectedTime, RejectedReason) select UserName, DisplayName, Registertime, '{rejectBy}', @RejectTime, '未填写' from Users where ID = {id}")) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RejectTime", DateTime.Now, DbType.DateTime)); - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.Parameters.Clear(); - cmd.CommandText = $"delete from UserRole where UserId = {id}"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from UserGroup where UserId = {id}"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from users where ID = {id}"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - transaction.CommitTransaction(); - ret = true; - } - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } + db.BeginTransaction(); + db.Execute("insert into RejectUsers (UserName, DisplayName, RegisterTime, RejectedBy, RejectedTime, RejectedReason) select UserName, DisplayName, Registertime, @1, @2, @3 from Users where ID = @0", id, rejectBy, DateTime.Now, "未填写"); + db.Execute("delete from UserRole where UserId = @0", id); + db.Execute("delete from UserGroup where UserId = @0", id); + db.Execute("delete from users where ID = @0", id); + db.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } + /// /// 通过roleId获取所有用户 /// /// /// - public virtual IEnumerable RetrieveUsersByRoleId(string roleId) - { - List users = new List(); - string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end status from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @RoleID where u.ApprovedTime is not null"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - users.Add(new User() - { - Id = reader[0].ToString(), - UserName = (string)reader[1], - DisplayName = (string)reader[2], - Checked = (string)reader[3] - }); - } - } - return users; - } + 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); + /// /// 通过角色ID保存当前授权用户(插入) /// /// 角色ID /// 用户ID数组 /// - public virtual bool SaveUsersByRoleId(string roleId, IEnumerable userIds) + public virtual bool SaveByRoleId(string roleId, IEnumerable userIds) { bool ret = false; - DataTable dt = new DataTable(); - dt.Columns.Add("RoleID", typeof(int)); - dt.Columns.Add("UserID", typeof(int)); - userIds.ToList().ForEach(userId => dt.Rows.Add(roleId, userId)); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + try { - try - { - //删除用户角色表该角色所有的用户 - string sql = $"delete from UserRole where RoleID = {roleId}"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入用户角色表 - using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction)) - { - bulk.DestinationTableName = "UserRole"; - bulk.ColumnMappings.Add("RoleID", "RoleID"); - bulk.ColumnMappings.Add("UserID", "UserID"); - bulk.WriteToServer(dt); - transaction.CommitTransaction(); - } - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } + db.BeginTransaction(); + //删除用户角色表该角色所有的用户 + db.Execute("delete from UserRole where RoleID = @0", roleId); + db.InsertBulk("UserRole", userIds.Select(g => new { UserID = g, RoleID = roleId })); + db.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } + /// /// 通过groupId获取所有用户 /// /// /// - public virtual IEnumerable RetrieveUsersByGroupId(string groupId) - { - List users = new List(); - string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end status from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID =@groupId where u.ApprovedTime is not null"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId)); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - users.Add(new User() - { - Id = reader[0].ToString(), - UserName = (string)reader[1], - DisplayName = (string)reader[2], - Checked = (string)reader[3] - }); - } - } - return users; - } + 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); + /// /// 通过部门ID保存当前授权用户(插入) /// /// GroupID /// 用户ID数组 /// - public virtual bool SaveUsersByGroupId(string groupId, IEnumerable userIds) + public virtual bool SaveByGroupId(string groupId, IEnumerable userIds) { bool ret = false; - DataTable dt = new DataTable(); - dt.Columns.Add("UserID", typeof(int)); - dt.Columns.Add("GroupID", typeof(int)); - userIds.ToList().ForEach(userId => dt.Rows.Add(userId, groupId)); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) + var db = DbManager.Db; + try { - try - { - //删除用户角色表该角色所有的用户 - string sql = "delete from UserGroup where GroupID = @GroupID"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId)); - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - //批插入用户角色表 - using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction)) - { - bulk.DestinationTableName = "UserGroup"; - bulk.ColumnMappings.Add("UserID", "UserID"); - bulk.ColumnMappings.Add("GroupID", "GroupID"); - bulk.WriteToServer(dt); - transaction.CommitTransaction(); - } - } - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } + db.BeginTransaction(); + //删除用户角色表该角色所有的用户 + db.Execute("delete from UserGroup where GroupID = @0", groupId); + db.InsertBulk("UserGroup", userIds.Select(g => new { UserID = g, GroupID = groupId })); + db.CompleteTransaction(); + ret = true; + } + catch (Exception ex) + { + db.AbortTransaction(); + throw ex; } return ret; } + /// /// 根据用户名修改用户头像 /// /// /// /// - public virtual bool SaveUserIconByName(string userName, string iconName) - { - bool ret = false; - string sql = "Update Users set Icon = @iconName where UserName = @userName"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@iconName", iconName)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; - } + public virtual bool SaveUserIconByName(string userName, string iconName) => DbManager.Db.Update("set Icon = @1 where UserName = @0", userName, iconName) == 1; + /// /// /// /// /// /// - public virtual bool SaveDisplayName(string userName, string displayName) - { - bool ret = false; - string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@DisplayName", displayName)); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; - } + public virtual bool SaveDisplayName(string userName, string displayName) => DbManager.Db.Update("set DisplayName = @1 where UserName = @0", userName, displayName) == 1; + /// /// 根据用户名更改用户皮肤 /// /// /// /// - public virtual bool SaveUserCssByName(string userName, string cssName) - { - bool ret = false; - string sql = "Update Users set Css = @cssName where UserName = @userName"; - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql)) - { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@cssName", DbAdapterManager.ToDBValue(cssName))); - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - } - return ret; - } + public virtual bool SaveUserCssByName(string userName, string cssName) => DbManager.Db.Update("set Css = @1 where UserName = @0", userName, cssName) == 1; + /// /// /// /// /// public virtual BootstrapUser RetrieveUserByUserName(string userName) => DbHelper.RetrieveUserByUserName(userName); + /// /// /// @@ -541,6 +331,7 @@ namespace Bootstrap.DataAccess return string.Format("{0} ({1})", UserName, DisplayName); } } + /// /// /// diff --git a/BootstrapAdmin.sln b/BootstrapAdmin.sln index 740340ca..696b979c 100644 --- a/BootstrapAdmin.sln +++ b/BootstrapAdmin.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27703.2047 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28407.52 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SQLServer", "SQLServer", "{87319AF5-7C40-4362-B67C-35F9DD737DB4}" ProjectSection(SolutionItems) = preProject @@ -31,8 +31,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.Client.DataAccess EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess", "Bootstrap.DataAccess\Bootstrap.DataAccess.csproj", "{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess.SQLite", "Bootstrap.DataAccess.SQLite\Bootstrap.DataAccess.SQLite.csproj", "{BC18A24F-5C99-4DF5-803D-72A912BCBD57}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SQLite", "SQLite", "{523515EC-2AD7-4282-9AF4-9D20371183B0}" ProjectSection(SolutionItems) = preProject DatabaseScripts\SQLite\InitData.sql = DatabaseScripts\SQLite\InitData.sql @@ -56,7 +54,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MySQL", "MySQL", "{084E2E94 DatabaseScripts\MySQL\install.sql = DatabaseScripts\MySQL\install.sql EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess.MySQL", "Bootstrap.DataAccess.MySQL\Bootstrap.DataAccess.MySQL.csproj", "{B6877AEA-EC65-47DA-BA6E-FD657729C285}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniTest", "UniTest\UniTest.csproj", "{1019D84F-2D0E-4976-947E-10AB16A4E53F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -80,18 +78,14 @@ Global {8D62BE79-BE13-43C8-969B-C9B00B3C84B7}.Debug|Any CPU.Build.0 = Debug|Any CPU {8D62BE79-BE13-43C8-969B-C9B00B3C84B7}.Release|Any CPU.ActiveCfg = Release|Any CPU {8D62BE79-BE13-43C8-969B-C9B00B3C84B7}.Release|Any CPU.Build.0 = Release|Any CPU - {BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Release|Any CPU.Build.0 = Release|Any CPU {8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Debug|Any CPU.Build.0 = Debug|Any CPU {8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Release|Any CPU.ActiveCfg = Release|Any CPU {8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Release|Any CPU.Build.0 = Release|Any CPU - {B6877AEA-EC65-47DA-BA6E-FD657729C285}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B6877AEA-EC65-47DA-BA6E-FD657729C285}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B6877AEA-EC65-47DA-BA6E-FD657729C285}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B6877AEA-EC65-47DA-BA6E-FD657729C285}.Release|Any CPU.Build.0 = Release|Any CPU + {1019D84F-2D0E-4976-947E-10AB16A4E53F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1019D84F-2D0E-4976-947E-10AB16A4E53F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1019D84F-2D0E-4976-947E-10AB16A4E53F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1019D84F-2D0E-4976-947E-10AB16A4E53F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/DatabaseScripts/InitData.sql b/DatabaseScripts/InitData.sql index 8cf0bf34..f14788ba 100644 --- a/DatabaseScripts/InitData.sql +++ b/DatabaseScripts/InitData.sql @@ -25,6 +25,7 @@ INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'消息状 INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'消息标签', N'一般', N'0', 0) INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'消息标签', N'紧要', N'1', 0) INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'头像地址', N'头像路径', N'~/images/uploader/', 0) +INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'头像地址', N'头像文件', N'default.jpg', 0) INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'网站样式', N'蓝色样式', N'blue.css', 0) INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'网站样式', N'黑色样式', N'black.css', 0) INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'当前样式', N'使用样式', N'blue.css', 0) diff --git a/DatabaseScripts/MongoDB/BootstrapAdmin.Dicts.json b/DatabaseScripts/MongoDB/BootstrapAdmin.Dicts.json index f9c9c939..9f9044b9 100644 --- a/DatabaseScripts/MongoDB/BootstrapAdmin.Dicts.json +++ b/DatabaseScripts/MongoDB/BootstrapAdmin.Dicts.json @@ -1,268 +1,275 @@ [ { - "_id": ObjectId("5bd6c73d5fa31256f77e4a13"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a13\")", "Category": "菜单", "Name": "系统菜单", "Code": "0", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a14"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a14\")", "Category": "菜单", "Name": "外部菜单", "Code": "1", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a15"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a15\")", "Category": "应用程序", "Name": "未设置", "Code": "0", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a16"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a16\")", "Category": "网站设置", "Name": "网站标题", "Code": "后台管理系统", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a17"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a17\")", "Category": "网站设置", "Name": "网站页脚", "Code": "2016 © 通用后台管理系统", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a18"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a18\")", "Category": "系统通知", "Name": "用户注册", "Code": "0", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a19"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a19\")", "Category": "系统通知", "Name": "程序异常", "Code": "1", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a1a"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1a\")", "Category": "系统通知", "Name": "数据库连接", "Code": "2", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a1b"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1b\")", "Category": "通知状态", "Name": "未处理", "Code": "0", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a1c"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1c\")", "Category": "通知状态", "Name": "已处理", "Code": "1", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a1d"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1d\")", "Category": "处理结果", "Name": "同意", "Code": "0", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a1e"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1e\")", "Category": "处理结果", "Name": "拒绝", "Code": "1", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a1f"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1f\")", "Category": "消息状态", "Name": "未读", "Code": "0", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a20"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a20\")", "Category": "消息状态", "Name": "已读", "Code": "1", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a21"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a21\")", "Category": "消息标签", "Name": "一般", "Code": "0", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a22"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a22\")", "Category": "消息标签", "Name": "紧要", "Code": "1", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a23"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a23\")", "Category": "头像地址", "Name": "头像路径", "Code": "~/images/uploader/", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a24"), + "_id": "ObjectId(\"4bd6c73d5fa31256f77e4a23\")", + "Category": "头像地址", + "Name": "头像文件", + "Code": "default.jpg", + "Define": "NumberInt(0)" + }, + { + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a24\")", "Category": "当前样式", "Name": "使用样式", "Code": "blue.css", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a25"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a25\")", "Category": "网站设置", "Name": "前台首页", "Code": "~/Home/Index", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a26"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a26\")", "Category": "应用程序", "Name": "组垛平台", "Code": "4", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a27"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a27\")", "Category": "组垛平台", "Name": "网站标题", "Code": "托盘组垛程序", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a28"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a28\")", "Category": "组垛平台", "Name": "网站页脚", "Code": "版权所有:中烟信息", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a29"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a29\")", "Category": "组垛平台", "Name": "个人中心地址", "Code": "http://localhost:50852/Admin/Profiles", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a2a"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2a\")", "Category": "组垛平台", "Name": "系统设置地址", "Code": "http://localhost:50852/Admin/Index", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a2b"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2b\")", "Category": "设备厂商", "Name": "远望谷", "Code": "Invengo", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a2c"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2c\")", "Category": "设备厂商", "Name": "测试", "Code": "Test", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a2d"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2d\")", "Category": "远程数据库", "Name": "组垛数据库", "Code": "Corp_Scan", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a2e"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2e\")", "Category": "网站样式", "Name": "黑色样式", "Code": "black.css", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a2f"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2f\")", "Category": "网站样式", "Name": "蓝色样式", "Code": "blue.css", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a30"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a30\")", "Category": "设备天线", "Name": "天线1", "Code": "1", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a31"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a31\")", "Category": "设备天线", "Name": "天线2", "Code": "2", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a32"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a32\")", "Category": "应用程序", "Name": "测试平台", "Code": "2", - "Define": NumberInt(0) + "Define": "NumberInt(0)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a33"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a33\")", "Category": "测试平台", "Name": "网站标题", "Code": "托盘组垛程序", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a34"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a34\")", "Category": "测试平台", "Name": "网站页脚", "Code": "通用后台管理测试平台", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a35"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a35\")", "Category": "测试平台", "Name": "个人中心地址", "Code": "http://localhost:50852/Admin/Profiles", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a36"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a36\")", "Category": "测试平台", "Name": "系统设置地址", "Code": "http://localhost:50852/Admin/Settings", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a37"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a37\")", "Category": "设备驱动", "Name": "Invengo", "Code": "Longbow.Invengo.Device, Longbow.Invengo", - "Define": NumberInt(1) + "Define": "NumberInt(1)" }, { - "_id": ObjectId("5bd6c73d5fa31256f77e4a38"), + "_id": "ObjectId(\"5bd6c73d5fa31256f77e4a38\")", "Category": "设备驱动", "Name": "Test", "Code": "Pallet.DeviceInterface.Device, Pallet.DeviceHub", - "Define": NumberInt(1) + "Define": "NumberInt(1)" } ] diff --git a/DatabaseScripts/MySQL/initData.sql b/DatabaseScripts/MySQL/initData.sql index 4c69473c..02df89a1 100644 --- a/DatabaseScripts/MySQL/initData.sql +++ b/DatabaseScripts/MySQL/initData.sql @@ -22,6 +22,7 @@ INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '消息状态 INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '消息标签', '一般', '0', 0); INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '消息标签', '紧要', '1', 0); INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '头像地址', '头像路径', '~/images/uploader/', 0); +INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '头像地址', '头像文件', 'default.jpg', 0); INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '网站样式', '蓝色样式', 'blue.css', 0); INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '网站样式', '黑色样式', 'black.css', 0); INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '当前样式', '使用样式', 'blue.css', 0); diff --git a/DatabaseScripts/SQLite/InitData.sql b/DatabaseScripts/SQLite/InitData.sql index ac10b697..364ed122 100644 --- a/DatabaseScripts/SQLite/InitData.sql +++ b/DatabaseScripts/SQLite/InitData.sql @@ -20,6 +20,7 @@ INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, ' INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '消息标签', '一般', '0', 0); INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '消息标签', '紧要', '1', 0); INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '头像地址', '头像路径', '~/images/uploader/', 0); +INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '头像地址', '头像文件', 'default.jpg', 0); INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '网站样式', '蓝色样式', 'blue.css', 0); INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '网站样式', '黑色样式', 'black.css', 0); INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '当前样式', '使用样式', 'blue.css', 0); diff --git a/Scripts/Longbow.lic b/Scripts/Longbow.lic deleted file mode 100644 index 8d0114d1..00000000 --- a/Scripts/Longbow.lic +++ /dev/null @@ -1,3 +0,0 @@ - - tH0NNQQxF3DJiiPpEWlKmsCMOhp/ijYoPnWvpjAH9Nfph06YjvCg6SBgs0SLGKrp+pHKey0Lf/wN94bR7/TYcsHrX20WvxvhBPmk2REJxLyqn6M+fAQAX++XZsQH9ywhgZaM2maGN+cXO+y+5aXGvUYKKOL6dxCIRBSNtAl21swA - \ No newline at end of file diff --git a/Scripts/Publish-Console.bat b/Scripts/Publish-Console.bat deleted file mode 100644 index b7f1362f..00000000 --- a/Scripts/Publish-Console.bat +++ /dev/null @@ -1,4 +0,0 @@ -D: -cd "D:\src\Longbow\BootstrapAdmin\Publish\Web-App\WebConsole\bin" -rem xcopy "C:\Longbow.Utility 2005\Release\Longbow.ComponentModel.dll" /f /y -rem call "D:\src\Longbow\Scripts\LgbSign.bat" OutFactoryScanContracts.dll Release Manual diff --git a/Scripts/Publish.vbs b/Scripts/Publish.vbs deleted file mode 100644 index c52216fe..00000000 --- a/Scripts/Publish.vbs +++ /dev/null @@ -1,124 +0,0 @@ -Option Explicit - -Dim fso, shell -Dim targetDir, targetName, extName, keyFile, destDir, solutionDir, cmd, file, assemblyDir, outDir, batFile, signCmd -Dim msg(), m - -keyFile = "..\Keys\Longbow.Utility.snk" -destDir = "Publish\Web-App\WebConsole" -assemblyDir = "C:\Longbow.Utility 2005\Release" -batFile = "..\Scripts\LgbSign.bat" -signCmd = "%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\bin\sn.exe" - -Set shell = WScript.CreateObject("WScript.Shell") -Set fso = CreateObject("Scripting.FileSystemObject") - -If WScript.Arguments.Count > 0 Then - targetDir = WScript.Arguments(0) -End If - -If WScript.Arguments.Count > 1 Then - targetName = WScript.Arguments(1) -End If - -If WScript.Arguments.Count > 2 Then - extName = WScript.Arguments(2) -End If - -If WScript.Arguments.Count > 3 Then - solutionDir = WScript.Arguments(3) - keyFile = solutionDir & keyFile - destDir = solutionDir & destDir - batFile = solutionDir & batFile -End If - -If WScript.Arguments.Count > 4 Then - outDir = WScript.Arguments(4) -End If - -If WScript.Arguments.Count > 5 Then - If WScript.Arguments(5) = "Debug" Then - ReSignFile targetDir & targetName & extName - WScript.Echo WScript.Arguments(5) & " Mode... Quit copy AFTER Re-signed assembly" - WScript.Quit - Else - If extName = ".dll" Then - WScript.Echo WScript.Arguments(5) & " Mode... Quit copy BEFORE Re-signed assembly" - WScript.Quit - End If - End If -End If - -destDir = destdir & targetName & "\" -If NOT fso.FolderExists(destDir) then - fso.CreateFolder(destDir) -End If - -If NOT fso.FolderExists(destdir & "Original\") then - fso.CreateFolder(destdir & "Original\") -End If - -If extName = ".exe" Then - CopyFile fso, targetDir, destDir, targetName & extName & ".config", true -End If -CopyFile fso, targetDir, destdir & "Original\", targetName & extName, true - -ReDim msg(0) -msg(0) = """" & batFile & """ """ & destdir & targetName & extName & """ """ & keyFile - -For Each file in fso.GetFolder(targetDir).Files - If fso.GetExtensionName(file) = "dll" then - If NOT CopyFile(fso, assemblyDir, destDir, file.Name, false) Then - ReDim Preserve msg(UBound(msg)+1) - msg(UBound(msg)) = """" & signCmd & """ """ & destdir & file.Name & """" - CopyFile fso, solutionDir & GetFileName(file.Name) & "\" & outDir, destDir & "Original\", file.Name, true - ReSignFile targetdir & file.Name - Else - CopyFile fso, assemblyDir, destDir & "Original\", file.Name, true - End If - End If -Next - -ReSignFile targetDir & targetName & extName -Wscript.Echo "Ready for DotFuscator... After Dotfuscator run the following command Please!" - -For Each m in msg - Wscript.Echo m -Next - -Function CopyFile(fso, targetDir, destDir, targetName, show) - If fso.FileExists(targetDir & targetName) then - fso.CopyFile targetDir & targetName, destDir & targetName, True - Wscript.Echo targetDir & targetName & " --> " & destDir & targetName & " Copied!" - CopyFile = True - Else - If show then - Wscript.Echo "Missing " & targetDir & targetName & " Not Copied!" - end if - CopyFile = False - End If -End Function - -Function GetFileName(fileName) - Dim pos, index - index = 1 - Do - pos = index + 1 - index = InStr(pos, fileName, ".") - Loop while index > 0 - - If pos > 0 Then - GetFileName = Left(fileName, pos -2) - Else - GetFileName = fileName - End If -End Function - -Sub ReSignFile(fileName) - If Not fso.FileExists(shell.ExpandEnvironmentStrings(signCmd)) Then - signCmd = "%ProgramFiles(x86)%\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe" - End If - cmd = """"& signCmd &""" -R """ & fileName & """ " & keyFile - shell.run cmd, 0, True - WScript.Echo "Assembly '" & fileName & "' successfully re-signed @_@" -End Sub \ No newline at end of file diff --git a/UniTest/Bootstrap.DataAccess/BootstrapAdminStartup.cs b/UniTest/Bootstrap.DataAccess/BootstrapAdminStartup.cs new file mode 100644 index 00000000..76cb2d88 --- /dev/null +++ b/UniTest/Bootstrap.DataAccess/BootstrapAdminStartup.cs @@ -0,0 +1,23 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using System.Collections.Generic; + +namespace Bootstrap.DataAccess +{ + public class BootstrapAdminStartup + { + public BootstrapAdminStartup() + { + var config = new ConfigurationBuilder().AddInMemoryCollection(new KeyValuePair[] { + new KeyValuePair("ConnectionStrings:ba", "Data Source=.;Initial Catalog=UnitTest;User ID=sa;Password=sa"), + new KeyValuePair("DB:0:Enabled", "false"), + new KeyValuePair("LongbowCache:Enabled", "false") + }).Build(); + var sc = new ServiceCollection(); + sc.AddSingleton(config); + sc.AddConfigurationManager(config); + sc.AddCacheManager(config); + sc.AddDbAdapter(); + } + } +} diff --git a/UniTest/Bootstrap.DataAccess/DictsTest.cs b/UniTest/Bootstrap.DataAccess/DictsTest.cs new file mode 100644 index 00000000..cdd32ff5 --- /dev/null +++ b/UniTest/Bootstrap.DataAccess/DictsTest.cs @@ -0,0 +1,103 @@ +using Xunit; + +namespace Bootstrap.DataAccess +{ + public class DictsTest : IClassFixture + { + [Fact] + public void Delete_Ok() + { + var dict = new Dict(); + Assert.True(dict.Delete(new string[] { "64", "65" })); + } + + [Fact] + public void Save_Ok() + { + var dict = new Dict() + { + Category = "UnitTest", + Name = "Test1", + Code = "1", + Define = 1 + }; + Assert.True(dict.Save(dict)); + } + + [Fact] + public void SaveSettings_Ok() + { + var dict = new Dict() + { + Category = "UnitTest", + Name = "Test1", + Code = "1", + Define = 1 + }; + Assert.True(dict.SaveSettings(dict)); + } + + [Fact] + public void RetrieveCategories_Ok() + { + var dict = new Dict(); + Assert.NotEmpty(dict.RetrieveCategories()); + } + + [Fact] + public void RetrieveWebTitle_Ok() + { + var dict = new Dict(); + Assert.Equal("后台管理系统", dict.RetrieveWebTitle()); + } + + [Fact] + public void RetrieveWebFooter_Ok() + { + var dict = new Dict(); + Assert.Equal("2016 © 通用后台管理系统", dict.RetrieveWebFooter()); + } + + [Fact] + public void RetrieveThemes_Ok() + { + var dict = new Dict(); + Assert.NotEmpty(dict.RetrieveThemes()); + } + + [Fact] + public void RetrieveActiveTheme_Ok() + { + var dict = new Dict(); + Assert.Equal("blue.css", dict.RetrieveActiveTheme()); + } + + [Fact] + public void RetrieveIconFolderPath_Ok() + { + var dict = new Dict(); + Assert.Equal("~/images/uploader/", dict.RetrieveIconFolderPath()); + } + + [Fact] + public void RetrieveHomeUrl_Ok() + { + var dict = new Dict(); + Assert.Equal("~/Home/Index", dict.RetrieveHomeUrl()); + } + + [Fact] + public void RetrieveApps_Ok() + { + var dict = new Dict(); + Assert.NotEmpty(dict.RetrieveApps()); + } + + [Fact] + public void RetrieveDicts_Ok() + { + var dict = new Dict(); + Assert.NotEmpty(dict.RetrieveDicts()); + } + } +} diff --git a/UniTest/Bootstrap.DataAccess/ExceptionsTest.cs b/UniTest/Bootstrap.DataAccess/ExceptionsTest.cs new file mode 100644 index 00000000..ddfa809a --- /dev/null +++ b/UniTest/Bootstrap.DataAccess/ExceptionsTest.cs @@ -0,0 +1,31 @@ +using Longbow.Web.Mvc; +using System; +using Xunit; + +namespace Bootstrap.DataAccess +{ + public class ExceptionsTest : IClassFixture + { + [Fact] + public void Log_Ok() + { + Exceptions excep = new Exceptions(); + Assert.True(excep.Log(new Exception("UnitTest"), null)); + } + + [Fact] + public void Retrieves_Ok() + { + Exceptions excep = new Exceptions(); + Assert.NotEmpty(excep.Retrieves()); + } + + [Fact] + public void RetrievePages_Ok() + { + var excep = new Exceptions(); + var op = excep.RetrievePages(new PaginationOption() { Offset = 0, Limit = 20, Sort = "LogTime", Order = "desc" }, null, null); + Assert.NotNull(op); + } + } +} diff --git a/UniTest/Bootstrap.DataAccess/GroupsTest.cs b/UniTest/Bootstrap.DataAccess/GroupsTest.cs new file mode 100644 index 00000000..b13ad763 --- /dev/null +++ b/UniTest/Bootstrap.DataAccess/GroupsTest.cs @@ -0,0 +1,63 @@ +using Xunit; + +namespace Bootstrap.DataAccess +{ + public class GroupsTest : IClassFixture + { + [Fact] + public void Retrieves_Ok() + { + Group g = new Group(); + Assert.NotEmpty(g.Retrieves()); + } + + [Fact] + public void Save_Ok() + { + Group g = new Group() { GroupName = "UnitTest", Description = "UnitTestSave" }; + Assert.True(g.Save(g)); + } + + [Fact] + public void Delete_Ok() + { + Group g = new Group(); + Assert.True(g.Delete(new string[] { "12", "13" })); + } + + [Fact] + public void RetrievesByRoleId_Ok() + { + Group p = new Group(); + var groups = p.RetrievesByRoleId("1"); + } + + [Fact] + public void RetrievesByUserId_Ok() + { + Group p = new Group(); + var groups = p.RetrievesByUserId("1"); + } + + [Fact] + public void SaveByUserId_Ok() + { + Group p = new Group(); + var groups = p.SaveByUserId("1", new string[] { "1", "2", "3" }); + } + + [Fact] + public void SaveByRoleId_Ok() + { + Group p = new Group(); + var groups = p.SaveByRoleId("1", new string[] { "1", "2" }); + } + + [Fact] + public void RetrievesByUserName_Ok() + { + Group p = new Group(); + Assert.NotEmpty(p.RetrievesByUserName("Admin")); + } + } +} diff --git a/UniTest/Bootstrap.DataAccess/LogsTest.cs b/UniTest/Bootstrap.DataAccess/LogsTest.cs new file mode 100644 index 00000000..49b1c1b0 --- /dev/null +++ b/UniTest/Bootstrap.DataAccess/LogsTest.cs @@ -0,0 +1,28 @@ +using Xunit; + +namespace Bootstrap.DataAccess +{ + public class LogsTest : IClassFixture + { + [Fact] + public void Save_Ok() + { + var log = new Log() + { + UserName = "UnitTest", + ClientAgent = "UnitTest-Agent", + ClientIp = "::", + CRUD = "UnitTest", + RequestUrl = "~/Home/Index" + }; + Assert.True(log.Save(log)); + } + + [Fact] + public void Retrieves_Ok() + { + var log = new Log(); + Assert.NotEmpty(log.Retrieves()); + } + } +} diff --git a/UniTest/Bootstrap.DataAccess/MenusTest.cs b/UniTest/Bootstrap.DataAccess/MenusTest.cs new file mode 100644 index 00000000..476e5e97 --- /dev/null +++ b/UniTest/Bootstrap.DataAccess/MenusTest.cs @@ -0,0 +1,54 @@ +using Xunit; + +namespace Bootstrap.DataAccess +{ + public class MenusTest : IClassFixture + { + [Fact] + public void Save_Ok() + { + var m = new Menu() + { + Name = "UnitTest", + Application = "0", + Category = "0", + Icon = "fa fa-fa", + IsResource = 0, + Target = "_blank", + Order = 10, + Url = "#", + ParentId = "0" + + }; + Assert.True(m.Save(m)); + } + + [Fact] + public void RetrieveMenusByRoleId_Ok() + { + var m = new Menu(); + Assert.NotEmpty(m.RetrieveMenusByRoleId("1")); + } + + [Fact] + public void Delete_Ok() + { + var m = new Menu(); + Assert.True(m.Delete(new string[] { "452" })); + } + + [Fact] + public void RetrieveAllMenus_Ok() + { + var m = new Menu(); + Assert.NotEmpty(m.RetrieveAllMenus("Admin")); + } + + [Fact] + public void SaveMenusByRoleId_Ok() + { + var m = new Menu(); + Assert.True(m.SaveMenusByRoleId("1", new string[] { "450", "451" })); + } + } +} diff --git a/UniTest/Bootstrap.DataAccess/MessagesTest.cs b/UniTest/Bootstrap.DataAccess/MessagesTest.cs new file mode 100644 index 00000000..61a2fd6c --- /dev/null +++ b/UniTest/Bootstrap.DataAccess/MessagesTest.cs @@ -0,0 +1,14 @@ +using Xunit; + +namespace Bootstrap.DataAccess +{ + public class MessagesTest : IClassFixture + { + [Fact] + public void RetrieveHeaders_Ok() + { + var m = new Message(); + m.RetrieveHeaders("Admin"); + } + } +} diff --git a/UniTest/Bootstrap.DataAccess/RolesTest.cs b/UniTest/Bootstrap.DataAccess/RolesTest.cs new file mode 100644 index 00000000..08494178 --- /dev/null +++ b/UniTest/Bootstrap.DataAccess/RolesTest.cs @@ -0,0 +1,83 @@ +using Xunit; + +namespace Bootstrap.DataAccess +{ + public class RolesTest : IClassFixture + { + [Fact] + public void SaveRolesByUserId_Ok() + { + var role = new Role(); + Assert.True(role.SaveByUserId("1", new string[] { "1", "2" })); + } + + [Fact] + public void RetrieveRolesByUserId_Ok() + { + var role = new Role(); + Assert.NotEmpty(role.RetrievesByUserId("1")); + } + + [Fact] + public void DeleteRole_Ok() + { + var role = new Role() + { + Description = "Role_Desc", + RoleName = "UnitTest" + }; + role.Save(role); + Assert.True(role.Delete(new string[] { role.Id.ToString() })); + } + + [Fact] + public void SaveRole_Ok() + { + var role = new Role() + { + Description = "Role_Desc", + RoleName = "UnitTest" + }; + Assert.True(role.Save(role)); + } + + [Fact] + public void RetrieveRolesByMenuId_Ok() + { + var menu = new Menu(); + menu.SaveMenusByRoleId("1", new string[] { "1" }); + + var role = new Role(); + var rs = role.RetrievesByMenuId("1"); + Assert.Contains(rs, r => r.Checked == "checked"); + } + + [Fact] + public void SavaRolesByMenuId_Ok() + { + var role = new Role(); + Assert.True(role.SavaByMenuId("1", new string[] { "1" })); + } + + [Fact] + public void RetrieveRolesByGroupId_Ok() + { + var role = new Role(); + Assert.Contains(role.RetrievesByGroupId("1"), r => r.Checked == "checked"); + } + + [Fact] + public void RetrieveRolesByUserName_Ok() + { + var role = new Role(); + Assert.NotEmpty(role.RetrieveRolesByUserName("Admin")); + } + + [Fact] + public void RetrieveRolesByUrl_Ok() + { + var role = new Role(); + Assert.NotEmpty(role.RetrieveRolesByUrl("~/Home/Index")); + } + } +} diff --git a/UniTest/Bootstrap.DataAccess/TasksTest.cs b/UniTest/Bootstrap.DataAccess/TasksTest.cs new file mode 100644 index 00000000..5c1b2899 --- /dev/null +++ b/UniTest/Bootstrap.DataAccess/TasksTest.cs @@ -0,0 +1,15 @@ +using System.Linq; +using Xunit; + +namespace Bootstrap.DataAccess +{ + public class TasksTest : IClassFixture + { + [Fact] + public void Retrieves_Ok() + { + var t = new Task(); + Assert.Equal(Enumerable.Empty(), t.Retrieves()); + } + } +} diff --git a/UniTest/Bootstrap.DataAccess/UsersTest.cs b/UniTest/Bootstrap.DataAccess/UsersTest.cs new file mode 100644 index 00000000..330719fe --- /dev/null +++ b/UniTest/Bootstrap.DataAccess/UsersTest.cs @@ -0,0 +1,135 @@ +using System; +using Xunit; + +namespace Bootstrap.DataAccess +{ + /// + /// + /// + public class UsersTest : IClassFixture + { + /// + /// + /// + [Fact] + public void Authenticate_Ok() + { + var u = new User(); + Assert.True(u.Authenticate("Admin", "123789")); + } + + [Fact] + public void ChangePassword_Ok() + { + var u = new User(); + Assert.True(u.ChangePassword("Admin", "123789", "123789")); + } + + [Fact] + public void Retrieves_Ok() + { + var u = new User(); + Assert.NotEmpty(u.Retrieves()); + } + + [Fact] + public void RetrieveNewUsers_Ok() + { + var u = new User(); + Assert.Empty(u.RetrieveNewUsers()); + } + + [Fact] + public void Update_Ok() + { + var u = new User(); + Assert.True(u.Update("1", "123789", "Administrators")); + } + + [Fact] + public void ApproveUser_Ok() + { + var u = new User(); + Assert.True(u.Approve("3", "Administrators")); + } + + [Fact] + public void RetrieveUsersByRoleId_Ok() + { + var u = new User(); + var users = u.RetrievesByRoleId("1"); + Assert.NotEmpty(users); + Assert.Contains(users, usr => usr.Checked == "checked"); + } + + [Fact] + public void RetrievesByGroupId_Ok() + { + var u = new User(); + var users = u.RetrievesByGroupId("1"); + Assert.NotEmpty(users); + Assert.Contains(users, usr => !usr.Checked.IsNullOrEmpty()); + } + + [Fact] + public void DeleteUser_Ok() + { + var u = new User(); + Assert.True(u.Delete(new string[] { "5", "6" })); + } + + [Fact] + public void SaveUser_Ok() + { + var u = new User(); + Assert.True(u.Save(new User { UserName = "UnitTest", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "default.jpg" })); + } + + [Fact] + public void SaveUserIconByName_Ok() + { + var u = new User(); + Assert.True(u.SaveUserIconByName("Admin", "default.jpg")); + } + + [Fact] + public void SaveDisplayName_Ok() + { + var u = new User(); + Assert.True(u.SaveDisplayName("Admin", "Administrators")); + } + + [Fact] + public void SaveUserCssByName_Ok() + { + var u = new User(); + Assert.True(u.SaveUserCssByName("Admin", "default.css")); + } + + [Fact] + public void Reject_Ok() + { + var u = new User(); + u.UserName = "UnitTest-Reject"; + u.DisplayName = "DisplayName"; + u.Description = "Desc"; + u.Icon = "default.jpg"; + u.Save(u); + Assert.True(u.Reject(u.Id, "Argo")); + } + + [Fact] + public void SaveByGroupId_Ok() + { + var u = new User(); + Assert.True(u.SaveByGroupId("1", new string[] { "1" })); + } + + [Fact] + public void SaveByRoleId_Ok() + { + var u = new User(); + Assert.True(u.SaveByRoleId("1", new string[] { "1", "2" })); + } + } +} diff --git a/UniTest/UniTest.csproj b/UniTest/UniTest.csproj new file mode 100644 index 00000000..4e61d394 --- /dev/null +++ b/UniTest/UniTest.csproj @@ -0,0 +1,19 @@ + + + + netcoreapp2.2 + + false + + + + + + + + + + + + + diff --git a/bldver.cs b/bldver.cs deleted file mode 100644 index 723983aa..00000000 --- a/bldver.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; - -//// General Information about an assembly is controlled through the following -//// set of attributes. Change these attribute values to modify the information -//// associated with an assembly. -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Cig MES Corporation Author: Argo Zhang (Argo@live.ca)")] -[assembly: AssemblyCopyright("Copyright (c) CIG All rights reserved.")] -#if DEBUG -[assembly: AssemblyTrademark("Cig MES Component Debug Version")] -#else -[assembly: AssemblyTrademark("Cig MES Component Release Version")] -#endif -[assembly: AssemblyCulture("")] -[assembly: AssemblyProduct("Cig MES (R) Component")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -//[assembly: ComVisible(false)] -//[assembly: CLSCompliant(true)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -//[assembly: Guid("a5f49ad1-f158-4eb7-9398-75fb414af28f")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file