diff --git a/Bootstrap.Admin/appsettings.Development.json b/Bootstrap.Admin/appsettings.Development.json index 7f0e4a37..c0f1015d 100644 --- a/Bootstrap.Admin/appsettings.Development.json +++ b/Bootstrap.Admin/appsettings.Development.json @@ -26,14 +26,14 @@ "CorsItems": [ { "Enabled": true, - "Name": "ba", + "Key": "ba", "Url": "CacheList.axd", "Desc": "后台管理数据缓存接口", "Self": true }, { "Enabled": true, - "Name": "APP", + "Key": "APP", "Url": "http://localhost:49185/CacheList.axd", "Desc": "测试系统", "Self": false diff --git a/Bootstrap.Admin/appsettings.json b/Bootstrap.Admin/appsettings.json index c9261eac..a7b799be 100644 --- a/Bootstrap.Admin/appsettings.json +++ b/Bootstrap.Admin/appsettings.json @@ -15,22 +15,21 @@ "ConnectionStrings": { "ba": "Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa" }, + "MongoDB": "BootstrapAdmin", "DB": [ { "Enabled": true }, { "Enabled": true, - "Widget": "Bootstrap.DataAccess.MySQL", - "DBProviderFactory": "MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data", + "ProviderName": "MySql", "ConnectionStrings": { "ba": "Server=10.211.55.2;Database=BA;Uid=argozhang;Pwd=argo@163.com;SslMode=none;" } }, { "Enabled": true, - "Widget": "Bootstrap.DataAccess.SQLite", - "DBProviderFactory": "Microsoft.Data.Sqlite.SqliteFactory, Microsoft.Data.Sqlite", + "ProviderName": "Sqlite", "ConnectionStrings": { "ba": "Data Source=BootstrapAdmin.db;" } @@ -39,7 +38,7 @@ "Enabled": true, "Widget": "Bootstrap.DataAccess.MongoDB", "ConnectionStrings": { - "ba": "mongodb://10.211.55.2:27017;Data Source=BootstrapAdmin" + "ba": "mongodb://10.211.55.2:27017" } } ], @@ -63,14 +62,14 @@ "CorsItems": [ { "Enabled": true, - "Name": "ba", + "Key": "ba", "Url": "CacheList.axd", "Desc": "后台管理数据缓存接口", "Self": true }, { "Enabled": true, - "Name": "Pallet", + "Key": "Pallet", "Url": "http://localhost/WebConsole/CacheList.axd", "Desc": "托盘组垛系统", "Self": false diff --git a/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs b/Bootstrap.DataAccess.MongoDB/DbManager.cs similarity index 90% rename from Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs rename to Bootstrap.DataAccess.MongoDB/DbManager.cs index 99684f3e..fb3cc457 100644 --- a/Bootstrap.DataAccess.MongoDB/MongoDbAccessManager.cs +++ b/Bootstrap.DataAccess.MongoDB/DbManager.cs @@ -5,15 +5,13 @@ 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 + internal static class DbManager { private static IMongoDatabase _db = null; private static bool _register = false; @@ -122,14 +120,8 @@ namespace Bootstrap.DataAccess.MongoDB 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.SpanSplit(";", StringSplitOptions.RemoveEmptyEntries); - if (seq.Count != 2) throw new InvalidOperationException("ConnectionString invalid in configuration file. It should be mongodb://127.0.0.1:27017;Data Source=BootstrapAdmin"); - - var client = new MongoClient(seq[0]); - _db = client.GetDatabase(seq[1].SpanSplit("=", StringSplitOptions.RemoveEmptyEntries).LastOrDefault()); + var client = new MongoClient(Longbow.Data.DbManager.GetConnectionString()); + _db = client.GetDatabase(ConfigurationManager.AppSettings["MongoDB"]); } private static void InitClassMap() diff --git a/Bootstrap.DataAccess.MongoDB/Dict.cs b/Bootstrap.DataAccess.MongoDB/Dict.cs index 44bdc06c..61a45d77 100644 --- a/Bootstrap.DataAccess.MongoDB/Dict.cs +++ b/Bootstrap.DataAccess.MongoDB/Dict.cs @@ -14,7 +14,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveDicts() => MongoDbAccessManager.Dicts.Find(FilterDefinition.Empty).ToList(); + public override IEnumerable RetrieveDicts() => DbManager.Dicts.Find(FilterDefinition.Empty).ToList(); /// /// @@ -28,7 +28,7 @@ namespace Bootstrap.DataAccess.MongoDB { list.Add(new DeleteOneModel(Builders.Filter.Eq(md => md.Id, id))); } - MongoDbAccessManager.Dicts.BulkWrite(list); + DbManager.Dicts.BulkWrite(list); return true; } @@ -42,12 +42,12 @@ namespace Bootstrap.DataAccess.MongoDB if (p.Id == "0") { p.Id = null; - MongoDbAccessManager.Dicts.InsertOne(p); + DbManager.Dicts.InsertOne(p); return true; } else { - MongoDbAccessManager.Dicts.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Category, p.Category) + DbManager.Dicts.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Category, p.Category) .Set(md => md.Define, p.Define) .Set(md => md.Name, p.Name) .Set(md => md.Code, p.Code)); @@ -62,7 +62,7 @@ namespace Bootstrap.DataAccess.MongoDB /// public override bool SaveSettings(BootstrapDict dict) { - MongoDbAccessManager.Dicts.FindOneAndUpdate(md => md.Category == dict.Category && md.Name == dict.Name, Builders.Update.Set(md => md.Code, dict.Code)); + DbManager.Dicts.FindOneAndUpdate(md => md.Category == dict.Category && md.Name == dict.Name, Builders.Update.Set(md => md.Code, dict.Code)); return true; } } diff --git a/Bootstrap.DataAccess.MongoDB/Exceptions.cs b/Bootstrap.DataAccess.MongoDB/Exceptions.cs index 8cb0570d..b126b2be 100644 --- a/Bootstrap.DataAccess.MongoDB/Exceptions.cs +++ b/Bootstrap.DataAccess.MongoDB/Exceptions.cs @@ -14,7 +14,7 @@ namespace Bootstrap.DataAccess.MongoDB { System.Threading.Tasks.Task.Run(() => { - MongoDbAccessManager.Exceptions.DeleteMany(ex => ex.LogTime < DateTime.Now.AddDays(-7)); + DbManager.Exceptions.DeleteMany(ex => ex.LogTime < DateTime.Now.AddDays(-7)); }); } @@ -24,7 +24,7 @@ namespace Bootstrap.DataAccess.MongoDB /// public override IEnumerable Retrieves() { - return MongoDbAccessManager.Exceptions.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList(); + return DbManager.Exceptions.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList(); } /// @@ -47,7 +47,7 @@ namespace Bootstrap.DataAccess.MongoDB UserId = additionalInfo?["UserId"], UserIp = additionalInfo?["UserIp"] }; - MongoDbAccessManager.Exceptions.InsertOne(excep); + DbManager.Exceptions.InsertOne(excep); ClearExceptions(); return true; } diff --git a/Bootstrap.DataAccess.MongoDB/Group.cs b/Bootstrap.DataAccess.MongoDB/Group.cs index 1440b693..a0c61f9e 100644 --- a/Bootstrap.DataAccess.MongoDB/Group.cs +++ b/Bootstrap.DataAccess.MongoDB/Group.cs @@ -20,7 +20,7 @@ namespace Bootstrap.DataAccess.MongoDB /// public override IEnumerable Retrieves() { - return MongoDbAccessManager.Groups.Find(FilterDefinition.Empty).ToList(); + return DbManager.Groups.Find(FilterDefinition.Empty).ToList(); } /// @@ -33,7 +33,7 @@ namespace Bootstrap.DataAccess.MongoDB if (p.Id == "0") { p.Id = null; - MongoDbAccessManager.Groups.InsertOne(new Group() { + DbManager.Groups.InsertOne(new Group() { GroupName = p.GroupName, Description = p.Description, Roles = new List() @@ -42,7 +42,7 @@ namespace Bootstrap.DataAccess.MongoDB } else { - MongoDbAccessManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.GroupName, p.GroupName).Set(md => md.Description, p.Description)); + DbManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.GroupName, p.GroupName).Set(md => md.Description, p.Description)); return true; } } @@ -59,7 +59,7 @@ namespace Bootstrap.DataAccess.MongoDB { list.Add(new DeleteOneModel(Builders.Filter.Eq(g => g.Id, id))); } - MongoDbAccessManager.Groups.BulkWrite(list); + DbManager.Groups.BulkWrite(list); return true; } @@ -84,7 +84,7 @@ namespace Bootstrap.DataAccess.MongoDB /// public override bool SaveByUserId(string userId, IEnumerable groupIds) { - MongoDbAccessManager.Users.FindOneAndUpdate(u => u.Id == userId, Builders.Update.Set(u => u.Groups, groupIds)); + DbManager.Users.FindOneAndUpdate(u => u.Id == userId, Builders.Update.Set(u => u.Groups, groupIds)); return true; } @@ -108,23 +108,23 @@ namespace Bootstrap.DataAccess.MongoDB /// public override bool SaveByRoleId(string roleId, IEnumerable groupIds) { - var groups = MongoDbAccessManager.Groups.Find(md => md.Roles != null && md.Roles.Contains(roleId)).ToList(); + var groups = DbManager.Groups.Find(md => md.Roles != null && md.Roles.Contains(roleId)).ToList(); // Remove roles groups.ForEach(p => { var roles = p.Roles == null ? new List() : p.Roles.ToList(); roles.Remove(roleId); - MongoDbAccessManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles)); + DbManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles)); }); - groups = MongoDbAccessManager.Groups.Find(md => groupIds.Contains(md.Id)).ToList(); + groups = DbManager.Groups.Find(md => groupIds.Contains(md.Id)).ToList(); // Add roles groups.ForEach(p => { var roles = p.Roles == null ? new List() : p.Roles.ToList(); roles.Add(roleId); - MongoDbAccessManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles)); + DbManager.Groups.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles)); }); return true; } diff --git a/Bootstrap.DataAccess.MongoDB/Log.cs b/Bootstrap.DataAccess.MongoDB/Log.cs index af8b8974..18fd848f 100644 --- a/Bootstrap.DataAccess.MongoDB/Log.cs +++ b/Bootstrap.DataAccess.MongoDB/Log.cs @@ -13,13 +13,13 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable Retrieves() => MongoDbAccessManager.Logs.Find(l => l.LogTime >= DateTime.Now.AddDays(-7)).ToList(); + public override IEnumerable Retrieves() => DbManager.Logs.Find(l => l.LogTime >= DateTime.Now.AddDays(-7)).ToList(); /// /// 删除日志信息 /// /// /// - private static void DeleteLogAsync() => System.Threading.Tasks.Task.Run(() => MongoDbAccessManager.Logs.DeleteMany(log => log.LogTime < DateTime.Now.AddDays(-7))); + private static void DeleteLogAsync() => System.Threading.Tasks.Task.Run(() => DbManager.Logs.DeleteMany(log => log.LogTime < DateTime.Now.AddDays(-7))); /// /// /// @@ -28,7 +28,7 @@ namespace Bootstrap.DataAccess.MongoDB public override bool Save(DataAccess.Log log) { log.LogTime = DateTime.Now; - MongoDbAccessManager.Logs.InsertOne(log); + DbManager.Logs.InsertOne(log); return true; } } diff --git a/Bootstrap.DataAccess.MongoDB/Menu.cs b/Bootstrap.DataAccess.MongoDB/Menu.cs index b793eb6f..82b07be4 100644 --- a/Bootstrap.DataAccess.MongoDB/Menu.cs +++ b/Bootstrap.DataAccess.MongoDB/Menu.cs @@ -19,7 +19,7 @@ namespace Bootstrap.DataAccess.MongoDB { var dicts = DictHelper.RetrieveDicts().Where(m => m.Category == "菜单"); - var menus = MongoDbAccessManager.Menus.Find(FilterDefinition.Empty).ToList(); + var menus = DbManager.Menus.Find(FilterDefinition.Empty).ToList(); menus.ForEach(m => { m.CategoryName = dicts.FirstOrDefault(d => d.Code == m.Category)?.Name; @@ -38,7 +38,7 @@ namespace Bootstrap.DataAccess.MongoDB if (p.Id == "0") { p.Id = null; - MongoDbAccessManager.Menus.InsertOne(p); + DbManager.Menus.InsertOne(p); return true; } else @@ -52,7 +52,7 @@ namespace Bootstrap.DataAccess.MongoDB .Set(md => md.Target, p.Target) .Set(md => md.IsResource, p.IsResource) .Set(md => md.Application, p.Application); - MongoDbAccessManager.Menus.UpdateOne(md => md.Id == p.Id, update); + DbManager.Menus.UpdateOne(md => md.Id == p.Id, update); return true; } } @@ -69,7 +69,7 @@ namespace Bootstrap.DataAccess.MongoDB { list.Add(new DeleteOneModel(Builders.Filter.Eq(g => g.Id, id))); } - MongoDbAccessManager.Menus.BulkWrite(list); + DbManager.Menus.BulkWrite(list); return true; } @@ -78,7 +78,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveMenusByRoleId(string roleId) => MongoDbAccessManager.Roles.Find(md => md.Id == roleId).FirstOrDefault().Menus.Select(m => new { Id = m }); + public override IEnumerable RetrieveMenusByRoleId(string roleId) => DbManager.Roles.Find(md => md.Id == roleId).FirstOrDefault().Menus.Select(m => new { Id = m }); /// /// @@ -88,7 +88,7 @@ namespace Bootstrap.DataAccess.MongoDB /// public override bool SaveMenusByRoleId(string roleId, IEnumerable menuIds) { - MongoDbAccessManager.Roles.FindOneAndUpdate(md => md.Id == roleId, Builders.Update.Set(md => md.Menus, menuIds)); + DbManager.Roles.FindOneAndUpdate(md => md.Id == roleId, Builders.Update.Set(md => md.Menus, menuIds)); return true; } } diff --git a/Bootstrap.DataAccess.MongoDB/Message.cs b/Bootstrap.DataAccess.MongoDB/Message.cs index 6d22b8a1..149df10a 100644 --- a/Bootstrap.DataAccess.MongoDB/Message.cs +++ b/Bootstrap.DataAccess.MongoDB/Message.cs @@ -15,7 +15,7 @@ namespace Bootstrap.DataAccess.MongoDB /// protected override IEnumerable Retrieves(string userName) { - var msg = MongoDbAccessManager.DBAccess.GetCollection("Messages"); + var msg = DbManager.DBAccess.GetCollection("Messages"); return msg.Find(message => message.To == userName || message.From == userName).ToList(); } } diff --git a/Bootstrap.DataAccess.MongoDB/Role.cs b/Bootstrap.DataAccess.MongoDB/Role.cs index 02fce094..c80510ff 100644 --- a/Bootstrap.DataAccess.MongoDB/Role.cs +++ b/Bootstrap.DataAccess.MongoDB/Role.cs @@ -21,7 +21,7 @@ namespace Bootstrap.DataAccess.MongoDB /// public override IEnumerable Retrieves() { - return MongoDbAccessManager.Roles.Find(FilterDefinition.Empty).ToList(); + return DbManager.Roles.Find(FilterDefinition.Empty).ToList(); } /// @@ -34,7 +34,7 @@ namespace Bootstrap.DataAccess.MongoDB if (p.Id == "0") { p.Id = null; - MongoDbAccessManager.Roles.InsertOne(new Role() + DbManager.Roles.InsertOne(new Role() { RoleName = p.RoleName, Description = p.Description, @@ -44,7 +44,7 @@ namespace Bootstrap.DataAccess.MongoDB } else { - MongoDbAccessManager.Roles.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.RoleName, p.RoleName).Set(md => md.Description, p.Description)); + DbManager.Roles.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.RoleName, p.RoleName).Set(md => md.Description, p.Description)); return true; } } @@ -61,7 +61,7 @@ namespace Bootstrap.DataAccess.MongoDB { list.Add(new DeleteOneModel(Builders.Filter.Eq(g => g.Id, id))); } - MongoDbAccessManager.Roles.BulkWrite(list); + DbManager.Roles.BulkWrite(list); return true; } @@ -102,7 +102,7 @@ namespace Bootstrap.DataAccess.MongoDB /// public override bool SaveByUserId(string userId, IEnumerable roleIds) { - MongoDbAccessManager.Users.FindOneAndUpdate(u => u.Id == userId, Builders.Update.Set(u => u.Roles, roleIds)); + DbManager.Users.FindOneAndUpdate(u => u.Id == userId, Builders.Update.Set(u => u.Roles, roleIds)); return true; } @@ -127,24 +127,24 @@ namespace Bootstrap.DataAccess.MongoDB /// public override bool SavaByMenuId(string menuId, IEnumerable roleIds) { - var roles = MongoDbAccessManager.Roles.Find(md => md.Menus != null && md.Menus.Contains(menuId)).ToList(); + var roles = DbManager.Roles.Find(md => md.Menus != null && md.Menus.Contains(menuId)).ToList(); // Remove roles roles.ForEach(p => { var menus = p.Menus == null ? new List() : p.Menus.ToList(); menus.Remove(menuId); - MongoDbAccessManager.Roles.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Menus, menus)); + DbManager.Roles.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Menus, menus)); }); - roles = MongoDbAccessManager.Roles.Find(md => roleIds.Contains(md.Id)).ToList(); + roles = DbManager.Roles.Find(md => roleIds.Contains(md.Id)).ToList(); roles.ForEach(role => { var menus = role.Menus == null ? new List() : role.Menus.ToList(); if (!menus.Contains(menuId)) { menus.Add(menuId); - MongoDbAccessManager.Roles.UpdateOne(md => md.Id == role.Id, Builders.Update.Set(md => md.Menus, menus)); + DbManager.Roles.UpdateOne(md => md.Id == role.Id, Builders.Update.Set(md => md.Menus, menus)); } }); return true; @@ -171,7 +171,7 @@ namespace Bootstrap.DataAccess.MongoDB /// public override bool SaveByGroupId(string groupId, IEnumerable roleIds) { - MongoDbAccessManager.Groups.FindOneAndUpdate(u => u.Id == groupId, Builders.Update.Set(u => u.Roles, roleIds)); + DbManager.Groups.FindOneAndUpdate(u => u.Id == groupId, Builders.Update.Set(u => u.Roles, roleIds)); return true; } @@ -182,7 +182,7 @@ namespace Bootstrap.DataAccess.MongoDB /// public override IEnumerable RetrieveRolesByUrl(string url) { - var menu = MongoDbAccessManager.Menus.Find(md => md.Url.StartsWith(url)).FirstOrDefault(); + var menu = DbManager.Menus.Find(md => md.Url.StartsWith(url)).FirstOrDefault(); 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 7a42dd05..e9429561 100644 --- a/Bootstrap.DataAccess.MongoDB/Task.cs +++ b/Bootstrap.DataAccess.MongoDB/Task.cs @@ -14,7 +14,7 @@ namespace Bootstrap.DataAccess.MongoDB /// public override IEnumerable Retrieves() { - var users = MongoDbAccessManager.DBAccess.GetCollection("Tasks"); + var users = DbManager.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 6e0288b8..c9d6e2cc 100644 --- a/Bootstrap.DataAccess.MongoDB/User.cs +++ b/Bootstrap.DataAccess.MongoDB/User.cs @@ -34,7 +34,7 @@ namespace Bootstrap.DataAccess.MongoDB .Include(u => u.DisplayName) .Include(u => u.Icon) .Include(u => u.Css); - return MongoDbAccessManager.Users.Find(user => user.UserName == userName).Project(project).FirstOrDefault(); + return DbManager.Users.Find(user => user.UserName == userName).Project(project).FirstOrDefault(); } /// @@ -47,7 +47,7 @@ namespace Bootstrap.DataAccess.MongoDB { if (string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(password)) return false; - var u = MongoDbAccessManager.Users.Find(user => user.UserName == userName).FirstOrDefault(); + var u = DbManager.Users.Find(user => user.UserName == userName).FirstOrDefault(); return !string.IsNullOrEmpty(u.PassSalt) && u.Password == LgbCryptography.ComputeHash(password, u.PassSalt); } @@ -55,7 +55,7 @@ namespace Bootstrap.DataAccess.MongoDB /// /// /// - public override IEnumerable RetrieveNewUsers() => MongoDbAccessManager.Users.Find(user => user.ApprovedTime == DateTime.MinValue).SortByDescending(user => user.RegisterTime).ToList(); + public override IEnumerable RetrieveNewUsers() => DbManager.Users.Find(user => user.ApprovedTime == DateTime.MinValue).SortByDescending(user => user.RegisterTime).ToList(); /// /// @@ -72,7 +72,7 @@ namespace Bootstrap.DataAccess.MongoDB .Include(u => u.Description) .Include(u => u.Groups) .Include(u => u.Roles); - return MongoDbAccessManager.Users.Find(user => user.ApprovedTime != DateTime.MinValue).Project(project).ToList(); + return DbManager.Users.Find(user => user.ApprovedTime != DateTime.MinValue).Project(project).ToList(); } /// @@ -87,7 +87,7 @@ namespace Bootstrap.DataAccess.MongoDB if (user.Description.Length > 500) user.Description = user.Description.Substring(0, 500); if (user.UserName.Length > 50) user.UserName = user.UserName.Substring(0, 50); - MongoDbAccessManager.Users.InsertOne(new User() + DbManager.Users.InsertOne(new User() { UserName = user.UserName, DisplayName = user.DisplayName, @@ -116,7 +116,7 @@ namespace Bootstrap.DataAccess.MongoDB var passSalt = LgbCryptography.GenerateSalt(); var newPassword = LgbCryptography.ComputeHash(password, passSalt); var update = Builders.Update.Set(u => u.Password, newPassword).Set(u => u.PassSalt, passSalt).Set(u => u.DisplayName, displayName); - MongoDbAccessManager.Users.FindOneAndUpdate(u => u.Id == id, update); + DbManager.Users.FindOneAndUpdate(u => u.Id == id, update); return true; } @@ -135,7 +135,7 @@ namespace Bootstrap.DataAccess.MongoDB var passSalt = LgbCryptography.GenerateSalt(); var newPassword = LgbCryptography.ComputeHash(password, passSalt); var update = Builders.Update.Set(u => u.Password, newPassword).Set(u => u.PassSalt, passSalt); - MongoDbAccessManager.Users.FindOneAndUpdate(u => u.UserName == UserName, update); + DbManager.Users.FindOneAndUpdate(u => u.UserName == UserName, update); } return ret; } @@ -152,7 +152,7 @@ namespace Bootstrap.DataAccess.MongoDB { list.Add(new DeleteOneModel(Builders.Filter.Eq(u => u.Id, id))); } - MongoDbAccessManager.Users.BulkWrite(list); + DbManager.Users.BulkWrite(list); return true; } @@ -176,23 +176,23 @@ namespace Bootstrap.DataAccess.MongoDB /// public override bool SaveByRoleId(string roleId, IEnumerable userIds) { - var users = MongoDbAccessManager.Users.Find(md => md.Roles != null && md.Roles.Contains(roleId)).ToList(); + var users = DbManager.Users.Find(md => md.Roles != null && md.Roles.Contains(roleId)).ToList(); // Remove roles users.ForEach(p => { var roles = p.Roles == null ? new List() : p.Roles.ToList(); roles.Remove(roleId); - MongoDbAccessManager.Users.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles)); + DbManager.Users.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles)); }); - users = MongoDbAccessManager.Users.Find(md => userIds.Contains(md.Id)).ToList(); + users = DbManager.Users.Find(md => userIds.Contains(md.Id)).ToList(); // Add roles users.ForEach(p => { var roles = p.Roles == null ? new List() : p.Roles.ToList(); roles.Add(roleId); - MongoDbAccessManager.Users.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles)); + DbManager.Users.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Roles, roles)); }); return true; } @@ -217,23 +217,23 @@ namespace Bootstrap.DataAccess.MongoDB /// public override bool SaveByGroupId(string groupId, IEnumerable userIds) { - var users = MongoDbAccessManager.Users.Find(md => md.Groups != null && md.Groups.Contains(groupId)).ToList(); + var users = DbManager.Users.Find(md => md.Groups != null && md.Groups.Contains(groupId)).ToList(); // Remove roles users.ForEach(p => { var groups = p.Groups == null ? new List() : p.Groups.ToList(); groups.Remove(groupId); - MongoDbAccessManager.Users.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Groups, groups)); + DbManager.Users.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Groups, groups)); }); - users = MongoDbAccessManager.Users.Find(md => userIds.Contains(md.Id)).ToList(); + users = DbManager.Users.Find(md => userIds.Contains(md.Id)).ToList(); // Add roles users.ForEach(p => { var groups = p.Groups == null ? new List() : p.Groups.ToList(); groups.Add(groupId); - MongoDbAccessManager.Users.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Groups, groups)); + DbManager.Users.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Groups, groups)); }); return true; }