From 55bb4b5f985c207fc57309422e427fa4ae7c2015 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Tue, 30 Oct 2018 13:07:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8A=9F=E8=83=BD=EF=BC=9A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0MongoDB=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Bootstrap.Admin.csproj | 1 + .../Controllers/Api/DictsController.cs | 2 +- .../Controllers/Api/ExceptionsController.cs | 2 +- .../Controllers/Api/GroupsController.cs | 8 +- .../Controllers/Api/LogsController.cs | 2 +- .../Controllers/Api/MenusController.cs | 6 +- .../Controllers/Api/RolesController.cs | 6 +- .../Controllers/Api/UsersController.cs | 8 +- Bootstrap.Admin/Query/QueryExceptionOption.cs | 6 +- Bootstrap.Admin/appsettings.json | 9 +- Bootstrap.Admin/wwwroot/js/exceptions.js | 2 +- Bootstrap.Admin/wwwroot/js/logs.js | 2 +- Bootstrap.Client.DataAccess/MenuHelper.cs | 2 +- .../Bootstrap.DataAccess.MongoDB.csproj | 21 +++ Bootstrap.DataAccess.MongoDB/Dict.cs | 23 +++ Bootstrap.DataAccess.MongoDB/Exceptions.cs | 22 +++ Bootstrap.DataAccess.MongoDB/Group.cs | 21 +++ Bootstrap.DataAccess.MongoDB/Log.cs | 22 +++ Bootstrap.DataAccess.MongoDB/Menu.cs | 23 +++ Bootstrap.DataAccess.MongoDB/Message.cs | 15 ++ .../MongoDbAccessManager.cs | 143 ++++++++++++++++++ Bootstrap.DataAccess.MongoDB/Role.cs | 37 +++++ Bootstrap.DataAccess.MongoDB/Task.cs | 21 +++ Bootstrap.DataAccess.MongoDB/User.cs | 48 ++++++ Bootstrap.DataAccess.SQLite/Exceptions.cs | 2 +- Bootstrap.DataAccess.SQLite/Group.cs | 10 +- Bootstrap.DataAccess.SQLite/Log.cs | 4 +- Bootstrap.DataAccess.SQLite/Menu.cs | 6 +- Bootstrap.DataAccess.SQLite/Message.cs | 2 +- Bootstrap.DataAccess.SQLite/Role.cs | 14 +- Bootstrap.DataAccess.SQLite/Task.cs | 2 +- Bootstrap.DataAccess.SQLite/User.cs | 22 +-- Bootstrap.DataAccess/CacheCleanUtility.cs | 2 +- Bootstrap.DataAccess/Dict.cs | 60 ++------ Bootstrap.DataAccess/Exceptions.cs | 4 +- Bootstrap.DataAccess/Group.cs | 34 ++--- Bootstrap.DataAccess/Helper/DictHelper.cs | 2 +- Bootstrap.DataAccess/Helper/GroupHelper.cs | 22 +-- Bootstrap.DataAccess/Helper/LogHelper.cs | 6 +- Bootstrap.DataAccess/Helper/MenuHelper.cs | 12 +- Bootstrap.DataAccess/Helper/RoleHelper.cs | 20 +-- Bootstrap.DataAccess/Helper/UserHelper.cs | 16 +- Bootstrap.DataAccess/Log.cs | 6 +- Bootstrap.DataAccess/Menu.cs | 17 +-- Bootstrap.DataAccess/Message.cs | 4 +- Bootstrap.DataAccess/Role.cs | 38 +++-- Bootstrap.DataAccess/Task.cs | 4 +- Bootstrap.DataAccess/User.cs | 41 +++-- BootstrapAdmin.sln | 6 + 49 files changed, 579 insertions(+), 229 deletions(-) create mode 100644 Bootstrap.DataAccess.MongoDB/Bootstrap.DataAccess.MongoDB.csproj create mode 100644 Bootstrap.DataAccess.MongoDB/Dict.cs create mode 100644 Bootstrap.DataAccess.MongoDB/Exceptions.cs create mode 100644 Bootstrap.DataAccess.MongoDB/Group.cs create mode 100644 Bootstrap.DataAccess.MongoDB/Log.cs create mode 100644 Bootstrap.DataAccess.MongoDB/Menu.cs create mode 100644 Bootstrap.DataAccess.MongoDB/Message.cs create mode 100644 Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs create mode 100644 Bootstrap.DataAccess.MongoDB/Role.cs create mode 100644 Bootstrap.DataAccess.MongoDB/Task.cs create mode 100644 Bootstrap.DataAccess.MongoDB/User.cs diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 7583db45..4876094c 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -27,6 +27,7 @@ + diff --git a/Bootstrap.Admin/Controllers/Api/DictsController.cs b/Bootstrap.Admin/Controllers/Api/DictsController.cs index 862c3f1d..85666a5c 100644 --- a/Bootstrap.Admin/Controllers/Api/DictsController.cs +++ b/Bootstrap.Admin/Controllers/Api/DictsController.cs @@ -39,7 +39,7 @@ namespace Bootstrap.Admin.Controllers.Api /// [HttpDelete] [Authorize(Roles = "Administrators")] - public bool Delete([FromBody]IEnumerable value) + public bool Delete([FromBody]IEnumerable value) { return DictHelper.DeleteDict(value); } diff --git a/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs b/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs index afc6b895..0be33ac2 100644 --- a/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs +++ b/Bootstrap.Admin/Controllers/Api/ExceptionsController.cs @@ -22,7 +22,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpGet] - public QueryData Get(QueryExceptionOption value) + public QueryData Get(QueryExceptionOption value) { return value.RetrieveData(); } diff --git a/Bootstrap.Admin/Controllers/Api/GroupsController.cs b/Bootstrap.Admin/Controllers/Api/GroupsController.cs index 37a70576..7de801d6 100644 --- a/Bootstrap.Admin/Controllers/Api/GroupsController.cs +++ b/Bootstrap.Admin/Controllers/Api/GroupsController.cs @@ -29,7 +29,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpGet("{id}")] - public Group Get(int id) + public Group Get(string id) { return GroupHelper.RetrieveGroups().FirstOrDefault(t => t.Id == id); } @@ -47,7 +47,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpDelete] - public bool Delete([FromBody]IEnumerable value) + public bool Delete([FromBody]IEnumerable value) { return GroupHelper.DeleteGroup(value); } @@ -58,7 +58,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpPost("{id}")] - public IEnumerable Post(int id, [FromQuery]string type) + public IEnumerable Post(string id, [FromQuery]string type) { var ret = new List(); switch (type) @@ -82,7 +82,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpPut("{id}")] - public bool Put(int id, [FromBody]IEnumerable groupIds, [FromQuery]string type) + public bool Put(string id, [FromBody]IEnumerable groupIds, [FromQuery]string type) { var ret = false; switch (type) diff --git a/Bootstrap.Admin/Controllers/Api/LogsController.cs b/Bootstrap.Admin/Controllers/Api/LogsController.cs index ce1398a7..55a95f90 100644 --- a/Bootstrap.Admin/Controllers/Api/LogsController.cs +++ b/Bootstrap.Admin/Controllers/Api/LogsController.cs @@ -28,7 +28,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpGet("{id}")] - public Log Get(int id) + public Log Get(string id) { return LogHelper.RetrieveLogs().FirstOrDefault(t => t.Id == id); } diff --git a/Bootstrap.Admin/Controllers/Api/MenusController.cs b/Bootstrap.Admin/Controllers/Api/MenusController.cs index 25f3658f..524feb03 100644 --- a/Bootstrap.Admin/Controllers/Api/MenusController.cs +++ b/Bootstrap.Admin/Controllers/Api/MenusController.cs @@ -38,7 +38,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpDelete] - public bool Delete([FromBody]IEnumerable value) + public bool Delete([FromBody]IEnumerable value) { return MenuHelper.DeleteMenu(value); } @@ -49,7 +49,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpPost("{id}")] - public IEnumerable Post(int id, [FromQuery]string type) + public IEnumerable Post(string id, [FromQuery]string type) { var ret = new List(); switch (type) @@ -72,7 +72,7 @@ namespace Bootstrap.Admin.Controllers.Api /// 菜单ID集合 /// [HttpPut("{id}")] - public bool Put(int id, [FromBody]IEnumerable value) + public bool Put(string id, [FromBody]IEnumerable value) { return MenuHelper.SaveMenusByRoleId(id, value); } diff --git a/Bootstrap.Admin/Controllers/Api/RolesController.cs b/Bootstrap.Admin/Controllers/Api/RolesController.cs index 606af074..ba3e48af 100644 --- a/Bootstrap.Admin/Controllers/Api/RolesController.cs +++ b/Bootstrap.Admin/Controllers/Api/RolesController.cs @@ -31,7 +31,7 @@ namespace Bootstrap.Admin.Controllers.Api /// 类型 /// [HttpPost("{id}")] - public IEnumerable Post(int id, [FromQuery]string type) + public IEnumerable Post(string id, [FromQuery]string type) { var ret = new List(); switch (type) @@ -58,7 +58,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpPut("{id}")] - public bool Put(int id, [FromBody]IEnumerable roleIds, [FromQuery]string type) + public bool Put(string id, [FromBody]IEnumerable roleIds, [FromQuery]string type) { var ret = false; switch (type) @@ -91,7 +91,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpDelete] - public bool Delete([FromBody]IEnumerable value) + public bool Delete([FromBody]IEnumerable value) { return RoleHelper.DeleteRole(value); } diff --git a/Bootstrap.Admin/Controllers/Api/UsersController.cs b/Bootstrap.Admin/Controllers/Api/UsersController.cs index 7e462a8e..393a05a6 100644 --- a/Bootstrap.Admin/Controllers/Api/UsersController.cs +++ b/Bootstrap.Admin/Controllers/Api/UsersController.cs @@ -54,7 +54,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpPost("{id}")] - public IEnumerable Post(int id, [FromQuery]string type) + public IEnumerable Post(string id, [FromQuery]string type) { var ret = new List(); switch (type) @@ -78,7 +78,7 @@ namespace Bootstrap.Admin.Controllers.Api public bool Post([FromBody]User value) { var ret = false; - if (value.Id == 0) + if (string.IsNullOrEmpty(value.Id)) { value.Description = string.Format("管理员{0}创建用户", User.Identity.Name); value.ApprovedBy = User.Identity.Name; @@ -98,7 +98,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpPut("{id}")] - public bool Put(int id, [FromBody]IEnumerable userIds, [FromQuery]string type) + public bool Put(string id, [FromBody]IEnumerable userIds, [FromQuery]string type) { var ret = false; switch (type) @@ -119,7 +119,7 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpDelete] - public bool Delete([FromBody]IEnumerable value) + public bool Delete([FromBody]IEnumerable value) { return UserHelper.DeleteUser(value); } diff --git a/Bootstrap.Admin/Query/QueryExceptionOption.cs b/Bootstrap.Admin/Query/QueryExceptionOption.cs index a96d0ec0..d0824737 100644 --- a/Bootstrap.Admin/Query/QueryExceptionOption.cs +++ b/Bootstrap.Admin/Query/QueryExceptionOption.cs @@ -22,7 +22,7 @@ namespace Bootstrap.Admin.Query /// /// /// - public QueryData RetrieveData() + public QueryData RetrieveData() { var data = ExceptionsHelper.RetrieveExceptions(); if (StartTime > DateTime.MinValue) @@ -33,7 +33,7 @@ namespace Bootstrap.Admin.Query { data = data.Where(t => t.LogTime < EndTime.AddDays(1)); } - var ret = new QueryData(); + var ret = new QueryData(); ret.total = data.Count(); switch (Sort) { @@ -52,7 +52,7 @@ namespace Bootstrap.Admin.Query default: break; } - ret.rows = data.Skip(Offset).Take(Limit); + ret.rows = data.Skip(Offset).Take(Limit).Select(ex => new { ex.UserId, ex.UserIp, ex.LogTime, ex.Message, ex.ErrorPage, ex.ExceptionType }); return ret; } } diff --git a/Bootstrap.Admin/appsettings.json b/Bootstrap.Admin/appsettings.json index 0841530e..1228a49f 100644 --- a/Bootstrap.Admin/appsettings.json +++ b/Bootstrap.Admin/appsettings.json @@ -21,12 +21,19 @@ "Widget": "Bootstrap.DataAccess" }, { - "Enabled": true, + "Enabled": false, "Widget": "Bootstrap.DataAccess.SQLite", "DBProviderFactory": "Microsoft.Data.Sqlite.SqliteFactory, Microsoft.Data.Sqlite", "ConnectionStrings": { "ba": "Data Source=BootstrapAdmin.db;" } + }, + { + "Enabled": true, + "Widget": "Bootstrap.DataAccess.MongoDB", + "ConnectionStrings": { + "ba": "mongodb://10.211.55.2:27017;Data Source=BootstrapAdmin" + } } ], "SwaggerPathBase": "/BA", diff --git a/Bootstrap.Admin/wwwroot/js/exceptions.js b/Bootstrap.Admin/wwwroot/js/exceptions.js index aaaaf6c6..2f551520 100644 --- a/Bootstrap.Admin/wwwroot/js/exceptions.js +++ b/Bootstrap.Admin/wwwroot/js/exceptions.js @@ -6,7 +6,7 @@ var $errorDetail = $('#errorDetail'); var $errorDetailTitle = $('#myDetailModalLabel'); - $('table').smartTable({ + $('.card-body table').smartTable({ url: Exceptions.url, sortName: 'LogTime', sortOrder: 'desc', diff --git a/Bootstrap.Admin/wwwroot/js/logs.js b/Bootstrap.Admin/wwwroot/js/logs.js index f463372e..e7a8afa5 100644 --- a/Bootstrap.Admin/wwwroot/js/logs.js +++ b/Bootstrap.Admin/wwwroot/js/logs.js @@ -1,7 +1,7 @@ $(function () { var url = 'api/Logs/'; - $('table').smartTable({ + $('.card-body table').smartTable({ url: url, sortName: 'LogTime', sortOrder: 'desc', diff --git a/Bootstrap.Client.DataAccess/MenuHelper.cs b/Bootstrap.Client.DataAccess/MenuHelper.cs index c3958b56..ad8adb5b 100644 --- a/Bootstrap.Client.DataAccess/MenuHelper.cs +++ b/Bootstrap.Client.DataAccess/MenuHelper.cs @@ -26,7 +26,7 @@ namespace Bootstrap.Client.DataAccess { var menus = RetrieveAllMenus(userName).Where(m => m.Category == "1" && m.IsResource == 0 && m.ApplicationCode == ConfigurationManager.AppSettings["AppId"]); DbHelper.ActiveMenu(null, menus, activeUrl); - var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order); + var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order); DbHelper.CascadeMenus(menus, root); return root; } diff --git a/Bootstrap.DataAccess.MongoDB/Bootstrap.DataAccess.MongoDB.csproj b/Bootstrap.DataAccess.MongoDB/Bootstrap.DataAccess.MongoDB.csproj new file mode 100644 index 00000000..15825bca --- /dev/null +++ b/Bootstrap.DataAccess.MongoDB/Bootstrap.DataAccess.MongoDB.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp2.1 + true + ..\Keys\Longbow.Utility.snk + + + + + + + + + + + + + + + diff --git a/Bootstrap.DataAccess.MongoDB/Dict.cs b/Bootstrap.DataAccess.MongoDB/Dict.cs new file mode 100644 index 00000000..b7fc68f6 --- /dev/null +++ b/Bootstrap.DataAccess.MongoDB/Dict.cs @@ -0,0 +1,23 @@ +using Bootstrap.Security; +using MongoDB.Driver; +using System.Collections.Generic; +using System.Linq; + +namespace Bootstrap.DataAccess.MongoDB +{ + /// + /// + /// + public class Dict : DataAccess.Dict + { + /// + /// + /// + /// + public override IEnumerable RetrieveDicts() + { + var dicts = MongoDbAccessManager.DBAccess.GetCollection("Dicts"); + return dicts.Find(FilterDefinition.Empty).ToList(); + } + } +} diff --git a/Bootstrap.DataAccess.MongoDB/Exceptions.cs b/Bootstrap.DataAccess.MongoDB/Exceptions.cs new file mode 100644 index 00000000..0efa19dd --- /dev/null +++ b/Bootstrap.DataAccess.MongoDB/Exceptions.cs @@ -0,0 +1,22 @@ +using MongoDB.Driver; +using System; +using System.Collections.Generic; + +namespace Bootstrap.DataAccess.MongoDB +{ + /// + /// + /// + public class Exceptions : DataAccess.Exceptions + { + /// + /// + /// + /// + public override IEnumerable RetrieveExceptions() + { + var msg = MongoDbAccessManager.DBAccess.GetCollection("Exceptions"); + return msg.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList(); + } + } +} diff --git a/Bootstrap.DataAccess.MongoDB/Group.cs b/Bootstrap.DataAccess.MongoDB/Group.cs new file mode 100644 index 00000000..6d06b39e --- /dev/null +++ b/Bootstrap.DataAccess.MongoDB/Group.cs @@ -0,0 +1,21 @@ +using MongoDB.Driver; +using System.Collections.Generic; + +namespace Bootstrap.DataAccess.MongoDB +{ + /// + /// + /// + public class Group : DataAccess.Group + { + /// + /// + /// + /// + public override IEnumerable RetrieveGroups() + { + var groups = MongoDbAccessManager.DBAccess.GetCollection("Groups"); + return groups.Find(FilterDefinition.Empty).ToList(); + } + } +} diff --git a/Bootstrap.DataAccess.MongoDB/Log.cs b/Bootstrap.DataAccess.MongoDB/Log.cs new file mode 100644 index 00000000..d04b976d --- /dev/null +++ b/Bootstrap.DataAccess.MongoDB/Log.cs @@ -0,0 +1,22 @@ +using MongoDB.Driver; +using System; +using System.Collections.Generic; + +namespace Bootstrap.DataAccess.MongoDB +{ + /// + /// + /// + public class Log : DataAccess.Log + { + /// + /// + /// + /// + public override IEnumerable RetrieveLogs() + { + var log = MongoDbAccessManager.DBAccess.GetCollection("Logs"); + return log.Find(l => l.LogTime >= DateTime.Now.AddDays(-7)).ToList(); + } + } +} diff --git a/Bootstrap.DataAccess.MongoDB/Menu.cs b/Bootstrap.DataAccess.MongoDB/Menu.cs new file mode 100644 index 00000000..ffaaabb2 --- /dev/null +++ b/Bootstrap.DataAccess.MongoDB/Menu.cs @@ -0,0 +1,23 @@ +using Bootstrap.Security; +using MongoDB.Driver; +using System.Collections.Generic; + +namespace Bootstrap.DataAccess.MongoDB +{ + /// + /// + /// + public class Menu : DataAccess.Menu + { + /// + /// + /// + /// + /// + public override IEnumerable RetrieveAllMenus(string userName) + { + var menus = MongoDbAccessManager.DBAccess.GetCollection("Navigations"); + return menus.Find(FilterDefinition.Empty).ToList(); + } + } +} diff --git a/Bootstrap.DataAccess.MongoDB/Message.cs b/Bootstrap.DataAccess.MongoDB/Message.cs new file mode 100644 index 00000000..86bbf329 --- /dev/null +++ b/Bootstrap.DataAccess.MongoDB/Message.cs @@ -0,0 +1,15 @@ +using MongoDB.Driver; +using System.Collections.Generic; + +namespace Bootstrap.DataAccess.MongoDB +{ + public class Message : DataAccess.Message + { + protected override IEnumerable RetrieveMessages(string userName) + { + //TODO: 完善其他字段信息 + 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 new file mode 100644 index 00000000..b935f080 --- /dev/null +++ b/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs @@ -0,0 +1,143 @@ +using Bootstrap.Security; +using Longbow.Data; +using MongoDB.Bson; +using MongoDB.Bson.Serialization; +using MongoDB.Bson.Serialization.Serializers; +using MongoDB.Driver; +using System; +using System.Linq; + +namespace Bootstrap.DataAccess.MongoDB +{ + /// + /// + /// + public static class MongoDbAccessManager + { + private static IMongoDatabase _db = null; + private static bool _register = false; + /// + /// + /// + public static IMongoDatabase DBAccess + { + get + { + if (_db == null) + { + if (!_register) + { + _register = true; + DbAdapterManager.RegisterConfigChangeCallback(InitDb); + } + InitDb(); + } + return _db; + } + } + + private static void InitDb() + { + var connectString = DbAdapterManager.GetConnectionString("ba"); + if (string.IsNullOrEmpty(connectString)) throw new InvalidOperationException("Please set the BA default value in configuration file."); + + var seq = connectString.Split(";", StringSplitOptions.RemoveEmptyEntries); + if (seq.Length != 2) throw new InvalidOperationException(""); + var client = new MongoClient(seq[0]); + _db = client.GetDatabase(seq[1].Split("=", StringSplitOptions.RemoveEmptyEntries).LastOrDefault()); + + BsonSerializer.RegisterSerializer(new DateTimeSerializer(DateTimeKind.Local)); + if (!BsonClassMap.IsClassMapRegistered(typeof(BootstrapDict))) + { + BsonClassMap.RegisterClassMap(md => + { + md.AutoMap(); + md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); + md.IdMemberMap.SetIgnoreIfDefault(true); + }); + } + if (!BsonClassMap.IsClassMapRegistered(typeof(BootstrapUser))) + { + BsonClassMap.RegisterClassMap(md => + { + md.AutoMap(); + md.SetIgnoreExtraElements(true); + }); + } + if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.User))) + { + BsonClassMap.RegisterClassMap(md => + { + md.AutoMap(); + md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); + md.IdMemberMap.SetIgnoreIfDefault(true); + }); + } + if (!BsonClassMap.IsClassMapRegistered(typeof(BootstrapMenu))) + { + BsonClassMap.RegisterClassMap(md => + { + md.AutoMap(); + md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); + md.IdMemberMap.SetIgnoreIfDefault(true); + }); + } + if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Group))) + { + BsonClassMap.RegisterClassMap(md => + { + md.AutoMap(); + md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); + md.IdMemberMap.SetIgnoreIfDefault(true); + md.UnmapMember(group => group.Checked); + }); + } + if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Role))) + { + BsonClassMap.RegisterClassMap(md => + { + md.AutoMap(); + md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); + md.IdMemberMap.SetIgnoreIfDefault(true); + md.UnmapMember(role => role.Checked); + }); + } + if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Task))) + { + BsonClassMap.RegisterClassMap(md => + { + md.AutoMap(); + md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); + md.IdMemberMap.SetIgnoreIfDefault(true); + }); + } + if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Message))) + { + BsonClassMap.RegisterClassMap(md => + { + md.AutoMap(); + md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); + md.IdMemberMap.SetIgnoreIfDefault(true); + }); + } + if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Exceptions))) + { + BsonClassMap.RegisterClassMap(md => + { + md.AutoMap(); + md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); + md.IdMemberMap.SetIgnoreIfDefault(true); + }); + } + if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Log))) + { + BsonClassMap.RegisterClassMap(md => + { + md.AutoMap(); + md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId)); + md.IdMemberMap.SetIgnoreIfDefault(true); + }); + } + } + } +} diff --git a/Bootstrap.DataAccess.MongoDB/Role.cs b/Bootstrap.DataAccess.MongoDB/Role.cs new file mode 100644 index 00000000..ea152838 --- /dev/null +++ b/Bootstrap.DataAccess.MongoDB/Role.cs @@ -0,0 +1,37 @@ +using MongoDB.Driver; +using System.Collections.Generic; + +namespace Bootstrap.DataAccess.MongoDB +{ + /// + /// + /// + public class Role : DataAccess.Role + { + /// + /// + /// + /// + /// + public override IEnumerable RetrieveRolesByUserName(string userName) + { + return new List() { "Administrators" }; + } + /// + /// + /// + /// + /// + public override IEnumerable RetrieveRolesByUrl(string url) => new List() { "Administrators" }; + /// + /// + /// + /// + /// + public override IEnumerable RetrieveRoles() + { + var roles = MongoDbAccessManager.DBAccess.GetCollection("Roles"); + return roles.Find(FilterDefinition.Empty).ToList(); + } + } +} diff --git a/Bootstrap.DataAccess.MongoDB/Task.cs b/Bootstrap.DataAccess.MongoDB/Task.cs new file mode 100644 index 00000000..de6b0083 --- /dev/null +++ b/Bootstrap.DataAccess.MongoDB/Task.cs @@ -0,0 +1,21 @@ +using MongoDB.Driver; +using System.Collections.Generic; + +namespace Bootstrap.DataAccess.MongoDB +{ + /// + /// + /// + public class Task : DataAccess.Task + { + /// + /// + /// + /// + public override IEnumerable RetrieveTasks() + { + 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 new file mode 100644 index 00000000..2a3004fd --- /dev/null +++ b/Bootstrap.DataAccess.MongoDB/User.cs @@ -0,0 +1,48 @@ +using Bootstrap.Security; +using Longbow.Security.Cryptography; +using MongoDB.Driver; +using System; +using System.Collections.Generic; + +namespace Bootstrap.DataAccess.MongoDB +{ + /// + /// + /// + public class User : DataAccess.User + { + /// + /// + /// + /// + /// + public override BootstrapUser RetrieveUserByUserName(string userName) + { + var users = MongoDbAccessManager.DBAccess.GetCollection("Users"); + return users.Find(user => user.UserName == userName).FirstOrDefault(); + } + /// + /// + /// + /// + /// + /// + public override bool Authenticate(string userName, string password) + { + if (string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(password)) return false; + + var users = MongoDbAccessManager.DBAccess.GetCollection("Users"); + var u = users.Find(user => user.UserName == userName).FirstOrDefault(); + return !string.IsNullOrEmpty(u.PassSalt) && u.Password == LgbCryptography.ComputeHash(password, u.PassSalt); + } + /// + /// + /// + /// + public override IEnumerable RetrieveNewUsers() + { + var users = MongoDbAccessManager.DBAccess.GetCollection("Users"); + return users.Find(user => user.ApprovedTime == DateTime.MinValue).SortByDescending(user => user.RegisterTime).ToList(); + } + } +} diff --git a/Bootstrap.DataAccess.SQLite/Exceptions.cs b/Bootstrap.DataAccess.SQLite/Exceptions.cs index 2ac1794f..92208f00 100644 --- a/Bootstrap.DataAccess.SQLite/Exceptions.cs +++ b/Bootstrap.DataAccess.SQLite/Exceptions.cs @@ -75,7 +75,7 @@ namespace Bootstrap.DataAccess.SQLite { exceptions.Add(new DataAccess.Exceptions() { - Id = LgbConvert.ReadValue(reader[0], 0), + 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], diff --git a/Bootstrap.DataAccess.SQLite/Group.cs b/Bootstrap.DataAccess.SQLite/Group.cs index 8b45216d..31b19895 100644 --- a/Bootstrap.DataAccess.SQLite/Group.cs +++ b/Bootstrap.DataAccess.SQLite/Group.cs @@ -17,7 +17,7 @@ namespace Bootstrap.DataAccess.SQLite /// 删除群组信息 /// /// - public override bool DeleteGroup(IEnumerable value) + public override bool DeleteGroup(IEnumerable value) { bool ret = false; var ids = string.Join(",", value); @@ -54,7 +54,7 @@ namespace Bootstrap.DataAccess.SQLite /// /// /// - public override bool SaveGroupsByUserId(int userId, IEnumerable groupIds) + public override bool SaveGroupsByUserId(string userId, IEnumerable groupIds) { var ret = false; @@ -76,7 +76,7 @@ namespace Bootstrap.DataAccess.SQLite }); transaction.CommitTransaction(); } - CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List() { userId }); + CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List() { userId }); ret = true; } catch (Exception ex) @@ -93,7 +93,7 @@ namespace Bootstrap.DataAccess.SQLite /// /// /// - public override bool SaveGroupsByRoleId(int roleId, IEnumerable groupIds) + public override bool SaveGroupsByRoleId(string roleId, IEnumerable groupIds) { bool ret = false; using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) @@ -113,7 +113,7 @@ namespace Bootstrap.DataAccess.SQLite }); transaction.CommitTransaction(); } - CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List() { roleId }); + CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List() { roleId }); ret = true; } catch (Exception ex) diff --git a/Bootstrap.DataAccess.SQLite/Log.cs b/Bootstrap.DataAccess.SQLite/Log.cs index 6de113ef..dc3f3aed 100644 --- a/Bootstrap.DataAccess.SQLite/Log.cs +++ b/Bootstrap.DataAccess.SQLite/Log.cs @@ -18,7 +18,7 @@ namespace Bootstrap.DataAccess.SQLite /// /// /// - public override IEnumerable RetrieveLogs(string tId = null) + public override IEnumerable RetrieveLogs() { string sql = "select * from Logs where LogTime > datetime('now', 'localtime', '-7 day')"; List logs = new List(); @@ -29,7 +29,7 @@ namespace Bootstrap.DataAccess.SQLite { logs.Add(new DataAccess.Log() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), CRUD = (string)reader[1], UserName = (string)reader[2], LogTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), diff --git a/Bootstrap.DataAccess.SQLite/Menu.cs b/Bootstrap.DataAccess.SQLite/Menu.cs index d60a42eb..5ab50c85 100644 --- a/Bootstrap.DataAccess.SQLite/Menu.cs +++ b/Bootstrap.DataAccess.SQLite/Menu.cs @@ -16,7 +16,7 @@ namespace Bootstrap.DataAccess.SQLite /// 删除菜单信息 /// /// - public override bool DeleteMenu(IEnumerable value) + public override bool DeleteMenu(IEnumerable value) { bool ret = false; var ids = string.Join(",", value); @@ -51,7 +51,7 @@ namespace Bootstrap.DataAccess.SQLite /// /// /// - public override bool SaveMenusByRoleId(int roleId, IEnumerable menuIds) + public override bool SaveMenusByRoleId(string roleId, IEnumerable menuIds) { bool ret = false; using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) @@ -71,7 +71,7 @@ namespace Bootstrap.DataAccess.SQLite }); transaction.CommitTransaction(); } - CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List() { roleId }); + CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List() { roleId }); ret = true; } catch (Exception ex) diff --git a/Bootstrap.DataAccess.SQLite/Message.cs b/Bootstrap.DataAccess.SQLite/Message.cs index 69463903..43bde2fb 100644 --- a/Bootstrap.DataAccess.SQLite/Message.cs +++ b/Bootstrap.DataAccess.SQLite/Message.cs @@ -28,7 +28,7 @@ namespace Bootstrap.DataAccess.SQLite { messages.Add(new DataAccess.Message() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), Title = (string)reader[1], Content = (string)reader[2], From = (string)reader[3], diff --git a/Bootstrap.DataAccess.SQLite/Role.cs b/Bootstrap.DataAccess.SQLite/Role.cs index 0a6d135f..0168767e 100644 --- a/Bootstrap.DataAccess.SQLite/Role.cs +++ b/Bootstrap.DataAccess.SQLite/Role.cs @@ -19,7 +19,7 @@ namespace Bootstrap.DataAccess.SQLite /// /// /// - public override bool SaveRolesByUserId(int userId, IEnumerable roleIds) + public override bool SaveRolesByUserId(string userId, IEnumerable roleIds) { var ret = false; //判断用户是否选定角色 @@ -39,7 +39,7 @@ namespace Bootstrap.DataAccess.SQLite }); transaction.CommitTransaction(); } - CacheCleanUtility.ClearCache(userIds: new List() { userId }, roleIds: roleIds); + CacheCleanUtility.ClearCache(userIds: new List() { userId }, roleIds: roleIds); ret = true; } catch (Exception ex) @@ -54,7 +54,7 @@ namespace Bootstrap.DataAccess.SQLite /// 删除角色表 /// /// - public override bool DeleteRole(IEnumerable value) + public override bool DeleteRole(IEnumerable value) { bool ret = false; var ids = string.Join(",", value); @@ -94,7 +94,7 @@ namespace Bootstrap.DataAccess.SQLite /// /// /// - public override bool SavaRolesByMenuId(int menuId, IEnumerable roleIds) + public override bool SavaRolesByMenuId(string menuId, IEnumerable roleIds) { var ret = false; //判断用户是否选定角色 @@ -115,7 +115,7 @@ namespace Bootstrap.DataAccess.SQLite }); transaction.CommitTransaction(); } - CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List() { menuId }); + CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List() { menuId }); ret = true; } catch (Exception ex) @@ -132,7 +132,7 @@ namespace Bootstrap.DataAccess.SQLite /// /// /// - public override bool SaveRolesByGroupId(int groupId, IEnumerable roleIds) + public override bool SaveRolesByGroupId(string groupId, IEnumerable roleIds) { var ret = false; //构造表格 @@ -154,7 +154,7 @@ namespace Bootstrap.DataAccess.SQLite }); transaction.CommitTransaction(); } - CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List() { groupId }); + CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List() { groupId }); ret = true; } catch (Exception ex) diff --git a/Bootstrap.DataAccess.SQLite/Task.cs b/Bootstrap.DataAccess.SQLite/Task.cs index 6f8f236a..c269ac36 100644 --- a/Bootstrap.DataAccess.SQLite/Task.cs +++ b/Bootstrap.DataAccess.SQLite/Task.cs @@ -23,7 +23,7 @@ namespace Bootstrap.DataAccess.SQLite { tasks.Add(new DataAccess.Task() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), TaskName = (string)reader[1], AssignName = (string)reader[2], UserName = (string)reader[3], diff --git a/Bootstrap.DataAccess.SQLite/User.cs b/Bootstrap.DataAccess.SQLite/User.cs index 5d72e360..9ffcbccf 100644 --- a/Bootstrap.DataAccess.SQLite/User.cs +++ b/Bootstrap.DataAccess.SQLite/User.cs @@ -19,7 +19,7 @@ namespace Bootstrap.DataAccess.SQLite /// 删除用户 /// /// - public override bool DeleteUser(IEnumerable value) + public override bool DeleteUser(IEnumerable value) { bool ret = false; var ids = string.Join(",", value); @@ -58,7 +58,7 @@ namespace Bootstrap.DataAccess.SQLite public override bool SaveUser(DataAccess.User p) { var ret = false; - if (p.Id == 0 && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500); + 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); @@ -86,7 +86,7 @@ namespace Bootstrap.DataAccess.SQLite DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); transaction.CommitTransaction(); - CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List() : new List() { p.Id }); + CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(p.Id) ? new List() : new List() { p.Id }); ret = true; } } @@ -105,7 +105,7 @@ namespace Bootstrap.DataAccess.SQLite /// /// /// - public override bool ApproveUser(int id, string approvedBy) + public override bool ApproveUser(string id, string approvedBy) { var ret = false; var sql = "update Users set ApprovedTime = datetime('now', 'localtime'), ApprovedBy = @approvedBy where ID = @id"; @@ -114,7 +114,7 @@ namespace Bootstrap.DataAccess.SQLite cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id)); cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy)); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - if (ret) CacheCleanUtility.ClearCache(userIds: new List() { id }); + if (ret) CacheCleanUtility.ClearCache(userIds: new List() { id }); } return ret; } @@ -125,7 +125,7 @@ namespace Bootstrap.DataAccess.SQLite /// /// /// - public override bool RejectUser(int id, string rejectBy) + public override bool RejectUser(string id, string rejectBy) { var ret = false; using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) @@ -146,7 +146,7 @@ namespace Bootstrap.DataAccess.SQLite DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); transaction.CommitTransaction(); - CacheCleanUtility.ClearCache(userIds: new List() { id }); + CacheCleanUtility.ClearCache(userIds: new List() { id }); ret = true; } } @@ -164,7 +164,7 @@ namespace Bootstrap.DataAccess.SQLite /// 角色ID /// 用户ID数组 /// - public override bool SaveUsersByRoleId(int roleId, IEnumerable userIds) + public override bool SaveUsersByRoleId(string roleId, IEnumerable userIds) { bool ret = false; DataTable dt = new DataTable(); @@ -188,7 +188,7 @@ namespace Bootstrap.DataAccess.SQLite }); transaction.CommitTransaction(); } - CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List() { roleId }); + CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List() { roleId }); ret = true; } catch (Exception ex) @@ -205,7 +205,7 @@ namespace Bootstrap.DataAccess.SQLite /// GroupID /// 用户ID数组 /// - public override bool SaveUsersByGroupId(int groupId, IEnumerable userIds) + public override bool SaveUsersByGroupId(string groupId, IEnumerable userIds) { bool ret = false; using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) @@ -225,7 +225,7 @@ namespace Bootstrap.DataAccess.SQLite }); transaction.CommitTransaction(); } - CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List() { groupId }); + CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List() { groupId }); ret = true; } catch (Exception ex) diff --git a/Bootstrap.DataAccess/CacheCleanUtility.cs b/Bootstrap.DataAccess/CacheCleanUtility.cs index d29ee3a1..78d83afa 100644 --- a/Bootstrap.DataAccess/CacheCleanUtility.cs +++ b/Bootstrap.DataAccess/CacheCleanUtility.cs @@ -19,7 +19,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static void ClearCache(IEnumerable roleIds = null, IEnumerable userIds = null, IEnumerable groupIds = null, IEnumerable menuIds = null, string dictIds = null, string cacheKey = null) + public static void ClearCache(IEnumerable roleIds = null, IEnumerable userIds = null, IEnumerable groupIds = null, IEnumerable menuIds = null, string dictIds = null, string cacheKey = null) { var cacheKeys = new List(); var corsKeys = new List(); diff --git a/Bootstrap.DataAccess/Dict.cs b/Bootstrap.DataAccess/Dict.cs index 400a96ff..53d4c5a3 100644 --- a/Bootstrap.DataAccess/Dict.cs +++ b/Bootstrap.DataAccess/Dict.cs @@ -18,7 +18,7 @@ namespace Bootstrap.DataAccess /// /// 需要删除的IDs /// - public virtual bool DeleteDict(IEnumerable value) + public virtual bool DeleteDict(IEnumerable value) { var ret = false; var ids = string.Join(",", value); @@ -41,7 +41,7 @@ namespace Bootstrap.DataAccess 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 = dict.Id == 0 ? + 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)) @@ -53,7 +53,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Define", dict.Define)); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; } - CacheCleanUtility.ClearCache(dictIds: dict.Id == 0 ? string.Empty : dict.Id.ToString()); + CacheCleanUtility.ClearCache(dictIds: string.IsNullOrEmpty(dict.Id) ? string.Empty : dict.Id.ToString()); return ret; } /// @@ -81,84 +81,46 @@ namespace Bootstrap.DataAccess /// 获取字典分类名称 /// /// - public virtual IEnumerable RetrieveCategories() - { - var ret = new List(); - string sql = "select distinct Category from Dicts"; - DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql); - using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd)) - { - while (reader.Read()) - { - ret.Add((string)reader[0]); - } - } - return ret; - } + public virtual IEnumerable RetrieveCategories() => DictHelper.RetrieveDicts().Select(d => d.Category); /// /// /// /// - public virtual string RetrieveWebTitle() - { - var settings = RetrieveDicts(); - return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code; - } + public virtual string RetrieveWebTitle() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code; /// /// /// /// - public virtual string RetrieveWebFooter() - { - var settings = RetrieveDicts(); - return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).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() - { - var data = RetrieveDicts(); - return data.Where(d => d.Category == "网站样式"); - } + public virtual IEnumerable RetrieveThemes() => DictHelper.RetrieveDicts().Where(d => d.Category == "网站样式"); /// /// 获得网站设置中的当前样式 /// /// public virtual string RetrieveActiveTheme() { - var data = RetrieveDicts(); - var theme = data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0).FirstOrDefault(); + 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() - { - var data = RetrieveDicts(); - return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" }; - } + public virtual BootstrapDict RetrieveIconFolderPath() => DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" }; /// /// 获得默认的前台首页地址,默认为~/Home/Index /// /// - public virtual string RetrieveHomeUrl() - { - var settings = RetrieveDicts(); - return (settings.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code; - } + public virtual string RetrieveHomeUrl() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code; /// /// /// /// - public virtual IEnumerable> RetrieveApps() - { - var settings = RetrieveDicts(); - return settings.Where(d => d.Category == "应用程序" && d.Define == 0).Select(d => new KeyValuePair(d.Code, d.Name)).OrderBy(d => d.Key); - } + 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 1e0dd920..b43703df 100644 --- a/Bootstrap.DataAccess/Exceptions.cs +++ b/Bootstrap.DataAccess/Exceptions.cs @@ -17,7 +17,7 @@ namespace Bootstrap.DataAccess /// /// /// - public int Id { get; set; } + public string Id { get; set; } /// /// /// @@ -112,7 +112,7 @@ namespace Bootstrap.DataAccess { exceptions.Add(new Exceptions() { - Id = (int)reader[0], + 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], diff --git a/Bootstrap.DataAccess/Group.cs b/Bootstrap.DataAccess/Group.cs index 91075a6d..e6058f7c 100644 --- a/Bootstrap.DataAccess/Group.cs +++ b/Bootstrap.DataAccess/Group.cs @@ -1,5 +1,4 @@ -using Longbow; -using Longbow.Data; +using Longbow.Data; using System; using System.Collections.Generic; using System.Data; @@ -17,18 +16,15 @@ namespace Bootstrap.DataAccess /// /// 获得/设置 群组主键ID /// - public int Id { get; set; } - + public string Id { get; set; } /// /// 获得/设置 群组名称 /// public string GroupName { get; set; } - /// /// 获得/设置 群组描述 /// public string Description { get; set; } - /// /// 获取/设置 用户群组关联状态 checked 标示已经关联 '' 标示未关联 /// @@ -38,7 +34,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveGroups(int id = 0) + public virtual IEnumerable RetrieveGroups() { string sql = "select * from Groups"; List groups = new List(); @@ -49,7 +45,7 @@ namespace Bootstrap.DataAccess { groups.Add(new Group() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), GroupName = (string)reader[1], Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2] }); @@ -61,7 +57,7 @@ namespace Bootstrap.DataAccess /// 删除群组信息 /// /// - public virtual bool DeleteGroup(IEnumerable value) + public virtual bool DeleteGroup(IEnumerable value) { bool ret = false; var ids = string.Join(",", value); @@ -83,7 +79,7 @@ namespace Bootstrap.DataAccess 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 = p.Id == 0 ? + 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)) @@ -93,7 +89,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description))); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; } - CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List() : new List() { p.Id }); + CacheCleanUtility.ClearCache(groupIds: string.IsNullOrEmpty(p.Id) ? new List() : new List() { p.Id }); return ret; } /// @@ -101,7 +97,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveGroupsByUserId(int userId) + 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(); @@ -113,7 +109,7 @@ namespace Bootstrap.DataAccess { groups.Add(new Group() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), GroupName = (string)reader[1], Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], Checked = (string)reader[3] @@ -128,7 +124,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveGroupsByUserId(int userId, IEnumerable groupIds) + public virtual bool SaveGroupsByUserId(string userId, IEnumerable groupIds) { var ret = false; DataTable dt = new DataTable(); @@ -157,7 +153,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List() { userId }); + CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List() { userId }); ret = true; } catch (Exception ex) @@ -173,7 +169,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveGroupsByRoleId(int roleId) + 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"; @@ -185,7 +181,7 @@ namespace Bootstrap.DataAccess { groups.Add(new Group() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), GroupName = (string)reader[1], Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], Checked = (string)reader[3] @@ -200,7 +196,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveGroupsByRoleId(int roleId, IEnumerable groupIds) + public virtual bool SaveGroupsByRoleId(string roleId, IEnumerable groupIds) { bool ret = false; DataTable dt = new DataTable(); @@ -227,7 +223,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List() { roleId }); + CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List() { roleId }); ret = true; } catch (Exception ex) diff --git a/Bootstrap.DataAccess/Helper/DictHelper.cs b/Bootstrap.DataAccess/Helper/DictHelper.cs index c9ac38ca..50124662 100644 --- a/Bootstrap.DataAccess/Helper/DictHelper.cs +++ b/Bootstrap.DataAccess/Helper/DictHelper.cs @@ -31,7 +31,7 @@ namespace Bootstrap.DataAccess /// /// 需要删除的IDs /// - public static bool DeleteDict(IEnumerable value) => DbAdapterManager.Create().DeleteDict(value); + public static bool DeleteDict(IEnumerable value) => DbAdapterManager.Create().DeleteDict(value); /// /// 保存新建/更新的字典信息 /// diff --git a/Bootstrap.DataAccess/Helper/GroupHelper.cs b/Bootstrap.DataAccess/Helper/GroupHelper.cs index cd479670..704214ee 100644 --- a/Bootstrap.DataAccess/Helper/GroupHelper.cs +++ b/Bootstrap.DataAccess/Helper/GroupHelper.cs @@ -1,7 +1,6 @@ using Longbow.Cache; using Longbow.Data; using System.Collections.Generic; -using System.Linq; namespace Bootstrap.DataAccess { @@ -19,17 +18,12 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveGroups(int id = 0) - { - var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbAdapterManager.Create().RetrieveGroups(id)); - return id == 0 ? ret : ret.Where(t => id == t.Id); - } - + public static IEnumerable RetrieveGroups() => CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbAdapterManager.Create().RetrieveGroups()); /// /// 删除群组信息 /// /// - public static bool DeleteGroup(IEnumerable value) => DbAdapterManager.Create().DeleteGroup(value); + public static bool DeleteGroup(IEnumerable value) => DbAdapterManager.Create().DeleteGroup(value); /// /// 保存新建/更新的群组信息 /// @@ -41,28 +35,28 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveGroupsByUserId(int userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbAdapterManager.Create().RetrieveGroupsByUserId(userId), RetrieveGroupsByUserIdDataKey); + public static IEnumerable RetrieveGroupsByUserId(string userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbAdapterManager.Create().RetrieveGroupsByUserId(userId), RetrieveGroupsByUserIdDataKey); /// /// 保存用户部门关系 /// - /// + /// /// /// - public static bool SaveGroupsByUserId(int id, IEnumerable groupIds) => DbAdapterManager.Create().SaveGroupsByUserId(id, groupIds); + public static bool SaveGroupsByUserId(string userId, IEnumerable groupIds) => DbAdapterManager.Create().SaveGroupsByUserId(userId, groupIds); /// /// 根据角色ID指派部门 /// /// /// - public static IEnumerable RetrieveGroupsByRoleId(int roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbAdapterManager.Create().RetrieveGroupsByRoleId(roleId), RetrieveGroupsByRoleIdDataKey); + public static IEnumerable RetrieveGroupsByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbAdapterManager.Create().RetrieveGroupsByRoleId(roleId), RetrieveGroupsByRoleIdDataKey); /// /// 根据角色ID以及选定的部门ID,保到角色部门表 /// - /// + /// /// /// - public static bool SaveGroupsByRoleId(int id, IEnumerable groupIds) => DbAdapterManager.Create().SaveGroupsByRoleId(id, groupIds); + public static bool SaveGroupsByRoleId(string roleId, IEnumerable groupIds) => DbAdapterManager.Create().SaveGroupsByRoleId(roleId, groupIds); /// /// /// diff --git a/Bootstrap.DataAccess/Helper/LogHelper.cs b/Bootstrap.DataAccess/Helper/LogHelper.cs index 1acff065..236e9239 100644 --- a/Bootstrap.DataAccess/Helper/LogHelper.cs +++ b/Bootstrap.DataAccess/Helper/LogHelper.cs @@ -20,11 +20,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveLogs(string tId = null) - { - var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key => DbAdapterManager.Create().RetrieveLogs(tId)); - return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase)); - } + public static IEnumerable RetrieveLogs() => CacheManager.GetOrAdd(RetrieveLogsDataKey, key => DbAdapterManager.Create().RetrieveLogs()); /// /// 保存新增的日志信息 /// diff --git a/Bootstrap.DataAccess/Helper/MenuHelper.cs b/Bootstrap.DataAccess/Helper/MenuHelper.cs index 0b233fc6..299e6b76 100644 --- a/Bootstrap.DataAccess/Helper/MenuHelper.cs +++ b/Bootstrap.DataAccess/Helper/MenuHelper.cs @@ -31,7 +31,7 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool DeleteMenu(IEnumerable value) => DbAdapterManager.Create().DeleteMenu(value); + public static bool DeleteMenu(IEnumerable value) => DbAdapterManager.Create().DeleteMenu(value); /// /// 通过用户名获得所有菜单 /// @@ -43,14 +43,14 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveMenusByRoleId(int roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbAdapterManager.Create().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey); + public static IEnumerable RetrieveMenusByRoleId(string roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbAdapterManager.Create().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey); /// /// /// /// /// /// - public static bool SaveMenusByRoleId(int id, IEnumerable value) => DbAdapterManager.Create().SaveMenusByRoleId(id, value); + public static bool SaveMenusByRoleId(string id, IEnumerable value) => DbAdapterManager.Create().SaveMenusByRoleId(id, value); /// /// /// @@ -62,7 +62,7 @@ namespace Bootstrap.DataAccess var menus = RetrieveAllMenus(userName).Where(m => m.Category == "1" && m.IsResource == 0); if (appId != "0") menus = menus.Where(m => m.ApplicationCode == appId); DbHelper.ActiveMenu(null, menus, activeUrl); - var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order); + var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order); DbHelper.CascadeMenus(menus, root); return root; } @@ -78,7 +78,7 @@ namespace Bootstrap.DataAccess { var menus = RetrieveAllMenus(userName).Where(m => m.Category == "0" && m.IsResource == 0); DbHelper.ActiveMenu(null, menus, activeUrl); - var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order); + var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order); DbHelper.CascadeMenus(menus, root); return root; } @@ -90,7 +90,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); + var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order); DbHelper.CascadeMenus(menus, root); return root; } diff --git a/Bootstrap.DataAccess/Helper/RoleHelper.cs b/Bootstrap.DataAccess/Helper/RoleHelper.cs index 8ba0d553..ab79f27b 100644 --- a/Bootstrap.DataAccess/Helper/RoleHelper.cs +++ b/Bootstrap.DataAccess/Helper/RoleHelper.cs @@ -21,28 +21,24 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveRoles(int id = 0) - { - var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, key => DbAdapterManager.Create().RetrieveRoles(id)); - return id == 0 ? ret : ret.Where(t => id == t.Id); - } + public static IEnumerable RetrieveRoles() => CacheManager.GetOrAdd(RetrieveRolesDataKey, key => DbAdapterManager.Create().RetrieveRoles()); /// /// 保存用户角色关系 /// /// /// /// - public static bool SaveRolesByUserId(int userId, IEnumerable roleIds) => DbAdapterManager.Create().SaveRolesByUserId(userId, roleIds); + public static bool SaveRolesByUserId(string userId, IEnumerable roleIds) => DbAdapterManager.Create().SaveRolesByUserId(userId, roleIds); /// /// 查询某个用户所拥有的角色 /// /// - public static IEnumerable RetrieveRolesByUserId(int userId) => CacheManager.GetOrAdd($"{RetrieveRolesByUserIdDataKey}-{userId}", key => DbAdapterManager.Create().RetrieveRolesByUserId(userId), RetrieveRolesByUserIdDataKey); + public static IEnumerable RetrieveRolesByUserId(string userId) => CacheManager.GetOrAdd($"{RetrieveRolesByUserIdDataKey}-{userId}", key => DbAdapterManager.Create().RetrieveRolesByUserId(userId), RetrieveRolesByUserIdDataKey); /// /// 删除角色表 /// /// - public static bool DeleteRole(IEnumerable value) => DbAdapterManager.Create().DeleteRole(value); + public static bool DeleteRole(IEnumerable value) => DbAdapterManager.Create().DeleteRole(value); /// /// 保存新建/更新的角色信息 /// @@ -54,27 +50,27 @@ namespace Bootstrap.DataAccess /// /// /// - public static IEnumerable RetrieveRolesByMenuId(int menuId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId), key => DbAdapterManager.Create().RetrieveRolesByMenuId(menuId), RetrieveRolesByMenuIdDataKey); + public static IEnumerable RetrieveRolesByMenuId(string menuId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId), key => DbAdapterManager.Create().RetrieveRolesByMenuId(menuId), RetrieveRolesByMenuIdDataKey); /// /// /// /// /// /// - public static bool SavaRolesByMenuId(int id, IEnumerable roleIds) => DbAdapterManager.Create().SavaRolesByMenuId(id, roleIds); + public static bool SavaRolesByMenuId(string id, IEnumerable roleIds) => DbAdapterManager.Create().SavaRolesByMenuId(id, roleIds); /// /// 根据GroupId查询和该Group有关的所有Roles /// /// /// - public static IEnumerable RetrieveRolesByGroupId(int groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId), key => DbAdapterManager.Create().RetrieveRolesByGroupId(groupId), RetrieveRolesByGroupIdDataKey); + public static IEnumerable RetrieveRolesByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId), key => DbAdapterManager.Create().RetrieveRolesByGroupId(groupId), RetrieveRolesByGroupIdDataKey); /// /// 根据GroupId更新Roles信息,删除旧的Roles信息,插入新的Roles信息 /// /// /// /// - public static bool SaveRolesByGroupId(int id, IEnumerable roleIds) => DbAdapterManager.Create().SaveRolesByGroupId(id, roleIds); + public static bool SaveRolesByGroupId(string id, IEnumerable roleIds) => DbAdapterManager.Create().SaveRolesByGroupId(id, roleIds); /// /// /// diff --git a/Bootstrap.DataAccess/Helper/UserHelper.cs b/Bootstrap.DataAccess/Helper/UserHelper.cs index 4d0e85fe..2a399292 100644 --- a/Bootstrap.DataAccess/Helper/UserHelper.cs +++ b/Bootstrap.DataAccess/Helper/UserHelper.cs @@ -37,7 +37,7 @@ namespace Bootstrap.DataAccess /// 删除用户 /// /// - public static bool DeleteUser(IEnumerable value) => DbAdapterManager.Create().DeleteUser(value); + public static bool DeleteUser(IEnumerable value) => DbAdapterManager.Create().DeleteUser(value); /// /// 保存新建 /// @@ -51,14 +51,14 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool UpdateUser(int id, string password, string displayName) => DbAdapterManager.Create().UpdateUser(id, password, displayName); + public static bool UpdateUser(string id, string password, string displayName) => DbAdapterManager.Create().UpdateUser(id, password, displayName); /// /// /// /// /// /// - public static bool ApproveUser(int id, string approvedBy) => DbAdapterManager.Create().ApproveUser(id, approvedBy); + public static bool ApproveUser(string id, string approvedBy) => DbAdapterManager.Create().ApproveUser(id, approvedBy); /// /// /// @@ -74,33 +74,33 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool RejectUser(int id, string rejectBy) => DbAdapterManager.Create().RejectUser(id, rejectBy); + public static bool RejectUser(string id, string rejectBy) => DbAdapterManager.Create().RejectUser(id, rejectBy); /// /// 通过roleId获取所有用户 /// /// /// - public static IEnumerable RetrieveUsersByRoleId(int roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId), k => DbAdapterManager.Create().RetrieveUsersByRoleId(roleId), RetrieveUsersByRoleIdDataKey); + public static IEnumerable RetrieveUsersByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId), k => DbAdapterManager.Create().RetrieveUsersByRoleId(roleId), RetrieveUsersByRoleIdDataKey); /// /// 通过角色ID保存当前授权用户(插入) /// /// 角色ID /// 用户ID数组 /// - public static bool SaveUsersByRoleId(int id, IEnumerable userIds) => DbAdapterManager.Create().SaveUsersByRoleId(id, userIds); + public static bool SaveUsersByRoleId(string id, IEnumerable userIds) => DbAdapterManager.Create().SaveUsersByRoleId(id, userIds); /// /// 通过groupId获取所有用户 /// /// /// - public static IEnumerable RetrieveUsersByGroupId(int groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId), k => DbAdapterManager.Create().RetrieveUsersByGroupId(groupId), RetrieveUsersByRoleIdDataKey); + public static IEnumerable RetrieveUsersByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId), k => DbAdapterManager.Create().RetrieveUsersByGroupId(groupId), RetrieveUsersByRoleIdDataKey); /// /// 通过部门ID保存当前授权用户(插入) /// /// GroupID /// 用户ID数组 /// - public static bool SaveUsersByGroupId(int id, IEnumerable userIds) => DbAdapterManager.Create().SaveUsersByGroupId(id, userIds); + public static bool SaveUsersByGroupId(string id, IEnumerable userIds) => DbAdapterManager.Create().SaveUsersByGroupId(id, userIds); /// 根据用户名修改用户头像 /// /// diff --git a/Bootstrap.DataAccess/Log.cs b/Bootstrap.DataAccess/Log.cs index 75fc88c9..cccdcdef 100644 --- a/Bootstrap.DataAccess/Log.cs +++ b/Bootstrap.DataAccess/Log.cs @@ -15,7 +15,7 @@ namespace Bootstrap.DataAccess /// /// 获得/设置 操作日志主键ID /// - public int Id { get; set; } + public string Id { get; set; } /// /// 获得/设置 操作类型 @@ -51,7 +51,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveLogs(string tId = null) + public virtual IEnumerable RetrieveLogs() { string sql = "select * from Logs where DATEDIFF(Week, LogTime, GETDATE()) = 0"; List logs = new List(); @@ -62,7 +62,7 @@ namespace Bootstrap.DataAccess { logs.Add(new Log() { - Id = (int)reader[0], + Id = reader[0].ToString(), CRUD = (string)reader[1], UserName = (string)reader[2], LogTime = (DateTime)reader[3], diff --git a/Bootstrap.DataAccess/Menu.cs b/Bootstrap.DataAccess/Menu.cs index 00e656b3..3bd3d378 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -1,6 +1,5 @@ using Bootstrap.Security; using Bootstrap.Security.DataAccess; -using Longbow; using Longbow.Data; using System; using System.Collections.Generic; @@ -20,7 +19,7 @@ namespace Bootstrap.DataAccess /// 删除菜单信息 /// /// - public virtual bool DeleteMenu(IEnumerable value) + public virtual bool DeleteMenu(IEnumerable value) { bool ret = false; var ids = string.Join(",", value); @@ -44,7 +43,7 @@ namespace Bootstrap.DataAccess if (p.Name.Length > 50) p.Name = p.Name.Substring(0, 50); if (p.Icon != null && p.Icon.Length > 50) p.Icon = p.Icon.Substring(0, 50); if (p.Url != null && p.Url.Length > 4000) p.Url = p.Url.Substring(0, 4000); - string sql = p.Id == 0 ? + 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)) @@ -61,7 +60,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode)); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; } - CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? new List() : new List() { p.Id }); + CacheCleanUtility.ClearCache(menuIds: string.IsNullOrEmpty(p.Id) ? new List() : new List() { p.Id }); return ret; } /// @@ -69,7 +68,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveMenusByRoleId(int roleId) + public virtual IEnumerable RetrieveMenusByRoleId(string roleId) { var menus = new List(); string sql = "select NavigationID from NavigationRole where RoleID = @RoleID"; @@ -82,7 +81,7 @@ namespace Bootstrap.DataAccess { menus.Add(new BootstrapMenu() { - Id = LgbConvert.ReadValue(reader[0], 0) + Id = reader[0].ToString() }); } } @@ -95,7 +94,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveMenusByRoleId(int roleId, IEnumerable menuIds) + public virtual bool SaveMenusByRoleId(string roleId, IEnumerable menuIds) { bool ret = false; DataTable dt = new DataTable(); @@ -121,7 +120,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List() { roleId }); + CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List() { roleId }); ret = true; } catch (Exception ex) @@ -133,7 +132,7 @@ namespace Bootstrap.DataAccess return ret; } /// - /// 通过当前用户名获得所有菜单,层次化后集合 + /// 通过当前用户名获得所有菜单 /// /// 当前登陆的用户名 /// diff --git a/Bootstrap.DataAccess/Message.cs b/Bootstrap.DataAccess/Message.cs index 9f514b0e..46fa59bb 100644 --- a/Bootstrap.DataAccess/Message.cs +++ b/Bootstrap.DataAccess/Message.cs @@ -15,7 +15,7 @@ namespace Bootstrap.DataAccess /// /// 消息主键 数据库自增 /// - public int Id { get; set; } + public string Id { get; set; } /// /// 标题 /// @@ -85,7 +85,7 @@ namespace Bootstrap.DataAccess { messages.Add(new Message() { - Id = (int)reader[0], + Id = reader[0].ToString(), Title = (string)reader[1], Content = (string)reader[2], From = (string)reader[3], diff --git a/Bootstrap.DataAccess/Role.cs b/Bootstrap.DataAccess/Role.cs index 4a06353a..05e461d9 100644 --- a/Bootstrap.DataAccess/Role.cs +++ b/Bootstrap.DataAccess/Role.cs @@ -1,5 +1,4 @@ using Bootstrap.Security.DataAccess; -using Longbow; using Longbow.Data; using System; using System.Collections.Generic; @@ -18,7 +17,7 @@ namespace Bootstrap.DataAccess /// /// 获得/设置 角色主键ID /// - public int Id { get; set; } + public string Id { get; set; } /// /// 获得/设置 角色名称 /// @@ -34,9 +33,8 @@ namespace Bootstrap.DataAccess /// /// 查询所有角色 /// - /// /// - public virtual IEnumerable RetrieveRoles(int id = 0) + public virtual IEnumerable RetrieveRoles() { string sql = "select * from Roles"; var roles = new List(); @@ -47,7 +45,7 @@ namespace Bootstrap.DataAccess { roles.Add(new Role() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), RoleName = (string)reader[1], Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2] }); @@ -61,7 +59,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveRolesByUserId(int userId, IEnumerable roleIds) + public virtual bool SaveRolesByUserId(string userId, IEnumerable roleIds) { var ret = false; DataTable dt = new DataTable(); @@ -91,7 +89,7 @@ namespace Bootstrap.DataAccess } transaction.CommitTransaction(); } - CacheCleanUtility.ClearCache(userIds: new List() { userId }, roleIds: roleIds); + CacheCleanUtility.ClearCache(userIds: new List() { userId }, roleIds: roleIds); ret = true; } catch (Exception ex) @@ -106,7 +104,7 @@ namespace Bootstrap.DataAccess /// 查询某个用户所拥有的角色 /// /// - public virtual IEnumerable RetrieveRolesByUserId(int userId) + 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"; @@ -118,7 +116,7 @@ namespace Bootstrap.DataAccess { roles.Add(new Role() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), RoleName = (string)reader[1], Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], Checked = (string)reader[3] @@ -131,7 +129,7 @@ namespace Bootstrap.DataAccess /// 删除角色表 /// /// - public virtual bool DeleteRole(IEnumerable value) + public virtual bool DeleteRole(IEnumerable value) { bool ret = false; var ids = string.Join(",", value); @@ -153,7 +151,7 @@ namespace Bootstrap.DataAccess 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 = p.Id == 0 ? + 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)) @@ -163,7 +161,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description))); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; } - CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List() : new List { p.Id }); + CacheCleanUtility.ClearCache(roleIds: string.IsNullOrEmpty(p.Id) ? new List() : new List { p.Id }); return ret; } /// @@ -171,7 +169,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveRolesByMenuId(int menuId) + 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(); @@ -183,7 +181,7 @@ namespace Bootstrap.DataAccess { roles.Add(new Role() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), RoleName = (string)reader[1], Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], Checked = (string)reader[3] @@ -198,7 +196,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SavaRolesByMenuId(int menuId, IEnumerable roleIds) + public virtual bool SavaRolesByMenuId(string menuId, IEnumerable roleIds) { var ret = false; DataTable dt = new DataTable(); @@ -227,7 +225,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List() { menuId }); + CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List() { menuId }); ret = true; } catch (Exception ex) @@ -243,7 +241,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveRolesByGroupId(int groupId) + 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"; @@ -255,7 +253,7 @@ namespace Bootstrap.DataAccess { roles.Add(new Role() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), RoleName = (string)reader[1], Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2], Checked = (string)reader[3] @@ -270,7 +268,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool SaveRolesByGroupId(int groupId, IEnumerable roleIds) + public virtual bool SaveRolesByGroupId(string groupId, IEnumerable roleIds) { var ret = false; //构造表格 @@ -299,7 +297,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List() { groupId }); + CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List() { groupId }); ret = true; } catch (Exception ex) diff --git a/Bootstrap.DataAccess/Task.cs b/Bootstrap.DataAccess/Task.cs index 1d308504..ac25fbee 100644 --- a/Bootstrap.DataAccess/Task.cs +++ b/Bootstrap.DataAccess/Task.cs @@ -10,7 +10,7 @@ namespace Bootstrap.DataAccess /// /// 获取/设置 任务ID /// - public int Id { get; set; } + public string Id { get; set; } /// /// 获取/设置 任务名称 /// @@ -54,7 +54,7 @@ namespace Bootstrap.DataAccess { tasks.Add(new Task() { - Id = (int)reader[0], + Id = reader[0].ToString(), TaskName = (string)reader[1], AssignName = (string)reader[2], UserName = (string)reader[3], diff --git a/Bootstrap.DataAccess/User.cs b/Bootstrap.DataAccess/User.cs index e892793e..aa41b566 100644 --- a/Bootstrap.DataAccess/User.cs +++ b/Bootstrap.DataAccess/User.cs @@ -20,7 +20,7 @@ namespace Bootstrap.DataAccess /// /// 获得/设置 用户主键ID /// - public int Id { get; set; } + public string Id { get; set; } /// /// 获取/设置 密码 /// @@ -129,7 +129,7 @@ namespace Bootstrap.DataAccess { users.Add(new User() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), UserName = (string)reader[1], DisplayName = (string)reader[2], RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), @@ -156,7 +156,7 @@ namespace Bootstrap.DataAccess { users.Add(new User() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), UserName = (string)reader[1], DisplayName = (string)reader[2], RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue), @@ -170,7 +170,7 @@ namespace Bootstrap.DataAccess /// 删除用户 /// /// - public virtual bool DeleteUser(IEnumerable value) + public virtual bool DeleteUser(IEnumerable value) { bool ret = false; var ids = string.Join(",", value); @@ -190,7 +190,7 @@ namespace Bootstrap.DataAccess public virtual bool SaveUser(User p) { var ret = false; - if (p.Id == 0 && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500); + 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); @@ -203,7 +203,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", DbAdapterManager.ToDBValue(p.ApprovedBy))); cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@description", p.Description)); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1; - if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List() : new List() { p.Id }); + if (ret) CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(p.Id) ? new List() : new List() { p.Id }); } return ret; } @@ -214,7 +214,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool UpdateUser(int id, string password, string displayName) + public virtual bool UpdateUser(string id, string password, string displayName) { bool ret = false; string sql = "Update Users set Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @id"; @@ -227,7 +227,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Password", newPassword)); cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt)); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - if (ret) CacheCleanUtility.ClearCache(userIds: id == 0 ? new List() : new List() { id }); + if (ret) CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(id) ? new List() : new List() { id }); } return ret; } @@ -237,7 +237,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual bool ApproveUser(int id, string approvedBy) + public virtual bool ApproveUser(string id, string approvedBy) { var ret = false; var sql = "update Users set ApprovedTime = GETDATE(), ApprovedBy = @approvedBy where ID = @id"; @@ -246,7 +246,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id)); cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy)); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1; - if (ret) CacheCleanUtility.ClearCache(userIds: new List() { id }); + if (ret) CacheCleanUtility.ClearCache(userIds: new List() { id }); } return ret; } @@ -255,9 +255,8 @@ namespace Bootstrap.DataAccess /// /// /// - /// /// - public virtual bool RejectUser(int id, string rejectBy) + public virtual bool RejectUser(string id, string rejectBy) { var ret = false; using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers")) @@ -266,7 +265,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@rejectedBy", rejectBy)); cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@rejectedReason", "未填写")); ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1; - if (ret) CacheCleanUtility.ClearCache(userIds: new List() { id }); + if (ret) CacheCleanUtility.ClearCache(userIds: new List() { id }); } return ret; } @@ -275,7 +274,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveUsersByRoleId(int 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"; @@ -287,7 +286,7 @@ namespace Bootstrap.DataAccess { users.Add(new User() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), UserName = (string)reader[1], DisplayName = (string)reader[2], Checked = (string)reader[3] @@ -302,7 +301,7 @@ namespace Bootstrap.DataAccess /// 角色ID /// 用户ID数组 /// - public virtual bool SaveUsersByRoleId(int roleId, IEnumerable userIds) + public virtual bool SaveUsersByRoleId(string roleId, IEnumerable userIds) { bool ret = false; DataTable dt = new DataTable(); @@ -328,7 +327,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List() { roleId }); + CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List() { roleId }); ret = true; } catch (Exception ex) @@ -344,7 +343,7 @@ namespace Bootstrap.DataAccess /// /// /// - public virtual IEnumerable RetrieveUsersByGroupId(int 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"; @@ -356,7 +355,7 @@ namespace Bootstrap.DataAccess { users.Add(new User() { - Id = LgbConvert.ReadValue(reader[0], 0), + Id = reader[0].ToString(), UserName = (string)reader[1], DisplayName = (string)reader[2], Checked = (string)reader[3] @@ -371,7 +370,7 @@ namespace Bootstrap.DataAccess /// GroupID /// 用户ID数组 /// - public virtual bool SaveUsersByGroupId(int groupId, IEnumerable userIds) + public virtual bool SaveUsersByGroupId(string groupId, IEnumerable userIds) { bool ret = false; DataTable dt = new DataTable(); @@ -398,7 +397,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List() { groupId }); + CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List() { groupId }); ret = true; } catch (Exception ex) diff --git a/BootstrapAdmin.sln b/BootstrapAdmin.sln index a5570aef..62d10cc9 100644 --- a/BootstrapAdmin.sln +++ b/BootstrapAdmin.sln @@ -41,6 +41,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SQLite", "SQLite", "{523515 DatabaseScripts\SQLite\Install.sql = DatabaseScripts\SQLite\Install.sql EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.DataAccess.MongoDB", "Bootstrap.DataAccess.MongoDB\Bootstrap.DataAccess.MongoDB.csproj", "{8336F096-4B4A-4710-A1FA-0F5E44CD8D26}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -67,6 +69,10 @@ Global {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE