维护用户、角色、组、菜单的级联删除操作,修改字典表的显示排序
This commit is contained in:
parent
5828feb27d
commit
7c1f96bca3
|
@ -39,8 +39,24 @@ namespace Bootstrap.Admin.Models
|
|||
}
|
||||
var ret = new QueryData<Dict>();
|
||||
ret.total = data.Count();
|
||||
// 通过option.Sort属性判断对那列进行排序,现在对字典表Category列排序
|
||||
data = Order == "asc" ? data.OrderBy(t => t.Category) : data.OrderByDescending(t => t.Category);
|
||||
// 通过option.Sort属性判断对那列进行排序
|
||||
switch (Sort)
|
||||
{
|
||||
case "ID":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.ID) : data.OrderByDescending(t => t.ID);
|
||||
break;
|
||||
case "Category":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.Category) : data.OrderByDescending(t => t.Category);
|
||||
break;
|
||||
case "Name":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.Name) : data.OrderByDescending(t => t.Name);
|
||||
break;
|
||||
case "Define":
|
||||
data = Order == "asc" ? data.OrderBy(t => t.Define) : data.OrderByDescending(t => t.Define);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ret.rows = data.Skip(Offset).Take(Limit);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -61,21 +61,27 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
var ret = false;
|
||||
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret;
|
||||
try
|
||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
||||
{
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Groups where ID in ({0})", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
try
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Groups where ID in ({0})", ids);
|
||||
sql += string.Format("delete from RoleGroup where GroupID in ({0});", ids);
|
||||
sql += string.Format("delete from UserGroup where GroupID in ({0});", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(groupIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存新建/更新的群组信息
|
||||
|
|
|
@ -130,19 +130,24 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
bool ret = false;
|
||||
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret;
|
||||
try
|
||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
||||
{
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Navigations where ID in ({0})", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
try
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Navigations where ID in ({0})", ids);
|
||||
sql += string.Format("delete from NavigationRole where NavigationID in ({0});", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(menuIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
}
|
||||
CacheCleanUtility.ClearCache(menuIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -145,19 +145,26 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
bool ret = false;
|
||||
if (string.IsNullOrEmpty(IDs) || IDs.Contains("'")) return ret;
|
||||
try
|
||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
||||
{
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Roles where ID in ({0})", IDs);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
try
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Roles where ID in ({0});", IDs);
|
||||
sql += string.Format("delete from UserRole where RoleID in ({0});", IDs);
|
||||
sql += string.Format("delete from RoleGroup where RoleID in ({0});", IDs);
|
||||
sql += string.Format("delete from NavigationRole where RoleID in ({0});", IDs);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(roleIds: IDs);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -103,19 +103,25 @@ namespace Bootstrap.DataAccess
|
|||
{
|
||||
bool ret = false;
|
||||
if (string.IsNullOrEmpty(ids) || ids.Contains("'")) return ret;
|
||||
try
|
||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
||||
{
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Users where ID in ({0})", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
try
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
string sql = string.Format(CultureInfo.InvariantCulture, "Delete from Users where ID in ({0})", ids);
|
||||
sql += string.Format("delete from UserRole where UserID in ({0});", ids);
|
||||
sql += string.Format("delete from UserGroup where UserID in ({0});", ids);
|
||||
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
|
||||
{
|
||||
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
||||
}
|
||||
CacheCleanUtility.ClearCache(userIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
transaction.RollbackTransaction();
|
||||
}
|
||||
CacheCleanUtility.ClearCache(userIds: ids);
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionManager.Publish(ex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Bootstrap.DataAccess.Tests
|
|||
[TestInitialize]
|
||||
public void Initialized()
|
||||
{
|
||||
Dict = new Dict() { Category = "__测试菜单__", Name = "__测试子菜单1__", Code = "2",Define = 0 };
|
||||
Dict = new Dict() { Category = "__测试字典__", Name = "__测试子字典1__", Code = "2",Define = 0 };
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
|
@ -42,7 +42,7 @@ namespace Bootstrap.DataAccess.Tests
|
|||
|
||||
// 测试更新字典记录方法 ID != 0
|
||||
var dict = dicts.FirstOrDefault(d => d.Category == Dict.Category);
|
||||
dict.Name = "__测试子菜单2__";
|
||||
dict.Name = "__测试子字典2__";
|
||||
Assert.IsTrue(DictHelper.SaveDict(dict), string.Format("更新字典记录ID = {0} 操作失败,请检查 DictHelper.SaveDict 方法", dict.ID));
|
||||
var dest = DictHelper.RetrieveDicts(dict.ID);
|
||||
Assert.IsTrue(dest.Count() == 1, "带参数的DictHelper.RetrieveDicts方法调用失败");
|
||||
|
|
Loading…
Reference in New Issue