diff --git a/Bootstrap.DataAccess.MongoDB/App.cs b/Bootstrap.DataAccess.MongoDB/App.cs
index 7c67b585..b95e95fe 100644
--- a/Bootstrap.DataAccess.MongoDB/App.cs
+++ b/Bootstrap.DataAccess.MongoDB/App.cs
@@ -32,6 +32,9 @@ namespace Bootstrap.DataAccess.MongoDB
///
public override bool SaveByRoleId(string roleId, IEnumerable appIds)
{
+ if (string.IsNullOrEmpty(roleId)) throw new ArgumentNullException(nameof(roleId));
+
+ if (appIds == null) appIds = new string[0];
var ret = DbManager.Roles.UpdateOne(md => md.Id == roleId, Builders.Update.Set(md => md.Apps, appIds));
return true;
}
diff --git a/Bootstrap.DataAccess.MongoDB/DbManager.cs b/Bootstrap.DataAccess.MongoDB/DbManager.cs
index 43780fca..d12714b1 100644
--- a/Bootstrap.DataAccess.MongoDB/DbManager.cs
+++ b/Bootstrap.DataAccess.MongoDB/DbManager.cs
@@ -195,13 +195,6 @@ namespace Bootstrap.DataAccess.MongoDB
{
BsonSerializer.RegisterSerializer(DateTimeSerializer.LocalInstance);
- if (!BsonClassMap.IsClassMapRegistered(typeof(Dict)))
- {
- BsonClassMap.RegisterClassMap(md =>
- {
- md.AutoMap();
- });
- }
if (!BsonClassMap.IsClassMapRegistered(typeof(BootstrapDict)))
{
BsonClassMap.RegisterClassMap(md =>
@@ -209,7 +202,6 @@ namespace Bootstrap.DataAccess.MongoDB
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
- md.AddKnownType(typeof(Dict));
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.User)))
diff --git a/Bootstrap.DataAccess.MongoDB/Trace.cs b/Bootstrap.DataAccess.MongoDB/Trace.cs
index 7bcaafd0..f95cc5c7 100644
--- a/Bootstrap.DataAccess.MongoDB/Trace.cs
+++ b/Bootstrap.DataAccess.MongoDB/Trace.cs
@@ -1,4 +1,4 @@
-using Longbow.Web.Mvc;
+using Longbow.Web.Mvc;
using MongoDB.Driver;
using PetaPoco;
using System;
@@ -93,7 +93,6 @@ namespace Bootstrap.DataAccess.MongoDB
///
public override bool Save(DataAccess.Trace p)
{
- p.Id = null;
DbManager.Traces.InsertOne(p);
ClearTraces();
return true;
diff --git a/Bootstrap.DataAccess.MongoDB/User.cs b/Bootstrap.DataAccess.MongoDB/User.cs
index d3f34a92..f0f27419 100644
--- a/Bootstrap.DataAccess.MongoDB/User.cs
+++ b/Bootstrap.DataAccess.MongoDB/User.cs
@@ -115,6 +115,7 @@ namespace Bootstrap.DataAccess.MongoDB
Description = user.Description,
IsReset = 0
});
+ user.Id = DbManager.Users.Find(r => r.UserName == user.UserName).FirstOrDefault().Id;
return true;
}
diff --git a/Bootstrap.DataAccess/App.cs b/Bootstrap.DataAccess/App.cs
index 9dd4f90b..960def19 100644
--- a/Bootstrap.DataAccess/App.cs
+++ b/Bootstrap.DataAccess/App.cs
@@ -56,7 +56,10 @@ namespace Bootstrap.DataAccess
///
public virtual bool SaveByRoleId(string roleId, IEnumerable appIds)
{
+ if (string.IsNullOrEmpty(roleId)) throw new ArgumentNullException(nameof(roleId));
+
bool ret = false;
+ if (appIds == null) appIds = new string[0];
var db = DbManager.Create();
try
{
diff --git a/Bootstrap.DataAccess/Dict.cs b/Bootstrap.DataAccess/Dict.cs
index 523105e4..2d11aa8b 100644
--- a/Bootstrap.DataAccess/Dict.cs
+++ b/Bootstrap.DataAccess/Dict.cs
@@ -1,4 +1,4 @@
-using Bootstrap.Security;
+using Bootstrap.Security;
using Bootstrap.Security.DataAccess;
using Longbow;
using PetaPoco;
@@ -107,11 +107,7 @@ namespace Bootstrap.DataAccess
if (appCode != "0")
{
var appUrl = dicts.FirstOrDefault(d => d.Name.Equals(appCode, StringComparison.OrdinalIgnoreCase) && d.Category == "应用首页" && d.Define == 0)?.Code;
- if (!string.IsNullOrEmpty(appUrl))
- {
- url = appUrl;
- return url;
- }
+ if (!string.IsNullOrEmpty(appUrl)) return appUrl;
}
var defaultUrl = dicts.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0)?.Code;
if (!string.IsNullOrEmpty(defaultUrl)) url = defaultUrl;
diff --git a/Bootstrap.DataAccess/Group.cs b/Bootstrap.DataAccess/Group.cs
index 37489531..1d4aac42 100644
--- a/Bootstrap.DataAccess/Group.cs
+++ b/Bootstrap.DataAccess/Group.cs
@@ -55,7 +55,7 @@ namespace Bootstrap.DataAccess
db.BeginTransaction();
db.Execute($"delete from UserGroup where GroupID in ({ids})");
db.Execute($"delete from RoleGroup where GroupID in ({ids})");
- db.Execute($"delete from {db.Provider.EscapeSqlIdentifier("Groups")} where ID in ({ids})");
+ db.Delete($"where ID in ({ids})");
db.CompleteTransaction();
ret = true;
}
diff --git a/Bootstrap.DataAccess/Helper/DictHelper.cs b/Bootstrap.DataAccess/Helper/DictHelper.cs
index 03fdd1ae..04e34354 100644
--- a/Bootstrap.DataAccess/Helper/DictHelper.cs
+++ b/Bootstrap.DataAccess/Helper/DictHelper.cs
@@ -41,14 +41,10 @@ namespace Bootstrap.DataAccess
///
public static bool Delete(IEnumerable value)
{
- if (RetrieveSystemModel())
- {
- // 禁止删除系统数据与测试平台数据
- var systemDicts = RetrieveProtectedDicts();
- value = value.Where(v => !systemDicts.Any(d => d.Id == v));
- if (!value.Any()) return true;
- }
if (!value.Any()) return true;
+
+ // 禁止删除系统数据与测试平台数据
+ if (RetrieveSystemModel() && RetrieveProtectedDicts().Any(d => value.Any(v => v == d.Id))) return true;
var ret = DbContextManager.Create().Delete(value);
CacheCleanUtility.ClearCache(dictIds: value);
return ret;
@@ -61,7 +57,7 @@ namespace Bootstrap.DataAccess
///
public static bool Save(BootstrapDict p)
{
- if (RetrieveSystemModel() && RetrieveProtectedDicts().Any(m => m.Id == p.Id)) return true;
+ if (RetrieveSystemModel() && !string.IsNullOrEmpty(p.Id) && RetrieveProtectedDicts().Any(m => m.Id == p.Id)) return true;
if (p.Id == string.Empty) p.Id = null;
var ret = DbContextManager.Create().Save(p);
diff --git a/Bootstrap.DataAccess/Helper/MenuHelper.cs b/Bootstrap.DataAccess/Helper/MenuHelper.cs
index 2a93d07f..58af4640 100644
--- a/Bootstrap.DataAccess/Helper/MenuHelper.cs
+++ b/Bootstrap.DataAccess/Helper/MenuHelper.cs
@@ -31,20 +31,8 @@ namespace Bootstrap.DataAccess
///
public static bool Save(BootstrapMenu p)
{
- if (DictHelper.RetrieveSystemModel())
- {
- if (p.Id.IsNullOrEmpty())
- {
- if (p.Category == "0") p.Category = "1";
- }
- else
- {
- if (RetrieveAllMenus("Admin").Where(m => m.Category == "0").Any(m => m.Id == p.Id))
- {
- return true;
- }
- }
- }
+ if (DictHelper.RetrieveSystemModel() && !string.IsNullOrEmpty(p.Id) && RetrieveAllMenus("Admin").Where(m => m.Category == "0" || m.Application == "2").Any(m => m.Id == p.Id)) return true;
+
if (p.Id == string.Empty) p.Id = null;
var ret = DbContextManager.Create