重构代码:精简通过角色ID保存菜单选项方法
This commit is contained in:
parent
efc0106f39
commit
8dd846824c
|
@ -16,7 +16,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
public class MenusController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// 获得所有菜单列表调用
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
|
@ -26,7 +26,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
return value.RetrieveData(User.Identity.Name);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// 保存菜单调用
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpPost]
|
||||
|
@ -35,7 +35,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
return MenuHelper.SaveMenu(value);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// 删除菜单调用
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[HttpDelete]
|
||||
|
@ -68,26 +68,15 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// 角色管理页面分配菜单时调用
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="id">角色ID</param>
|
||||
/// <param name="value">菜单ID集合</param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{id}")]
|
||||
public bool Put(int id, [FromBody]JObject value)
|
||||
public bool Put(int id, [FromBody]IEnumerable<int> value)
|
||||
{
|
||||
var ret = false;
|
||||
dynamic json = value;
|
||||
string menuIds = json.menuIds.ToString();
|
||||
switch ((string)json.type)
|
||||
{
|
||||
case "role":
|
||||
ret = MenuHelper.SaveMenusByRoleId(id, menuIds);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
return MenuHelper.SaveMenusByRoleId(id, value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -87,17 +87,10 @@
|
|||
},
|
||||
'#btnSubmitMenu': function (row) {
|
||||
var roleId = row.Id;
|
||||
var type = $btnSubmitMenu.data('type');
|
||||
switch (type) {
|
||||
case "menu":
|
||||
var menuIds = $nestMenuInput.find('input:checkbox:checked').map(function (index, element) {
|
||||
return $(element).val();
|
||||
}).toArray().join(',');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$.bc({ id: roleId, url: Menu.url, method: "put", data: { type: "role", menuIds: menuIds }, modal: '#dialogMenu', title: Menu.title });
|
||||
var menuIds = $nestMenuInput.find('input:checkbox:checked').map(function (index, element) {
|
||||
return $(element).val();
|
||||
}).toArray();
|
||||
$.bc({ id: roleId, url: Menu.url, method: "put", data: menuIds, modal: '#dialogMenu', title: Menu.title });
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="menuIds"></param>
|
||||
/// <param name="dictIds"></param>
|
||||
/// <param name="cacheKey"></param>
|
||||
internal static void ClearCache(string roleIds = null, string userIds = null, string groupIds = null, string menuIds = null, string dictIds = null, string cacheKey = null)
|
||||
internal static void ClearCache(string roleIds = null, string userIds = null, string groupIds = null, IEnumerable<int> menuIds = null, string dictIds = null, string cacheKey = null)
|
||||
{
|
||||
var cacheKeys = new List<string>();
|
||||
var corsKeys = new List<string>();
|
||||
|
@ -62,7 +62,7 @@ namespace Bootstrap.DataAccess
|
|||
}
|
||||
if (menuIds != null)
|
||||
{
|
||||
menuIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id =>
|
||||
menuIds.ToList().ForEach(id =>
|
||||
{
|
||||
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id));
|
||||
});
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Bootstrap.DataAccess
|
|||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == value.Count();
|
||||
}
|
||||
CacheCleanUtility.ClearCache(menuIds: ids);
|
||||
CacheCleanUtility.ClearCache(menuIds: value);
|
||||
return ret;
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -64,7 +64,7 @@ namespace Bootstrap.DataAccess
|
|||
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
|
||||
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
|
||||
}
|
||||
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? string.Empty : p.Id.ToString());
|
||||
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -103,13 +103,13 @@ namespace Bootstrap.DataAccess
|
|||
/// <param name="id"></param>
|
||||
/// <param name="menuIds"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SaveMenusByRoleId(int id, string menuIds)
|
||||
public static bool SaveMenusByRoleId(int id, IEnumerable<int> menuIds)
|
||||
{
|
||||
bool ret = false;
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add("RoleID", typeof(int));
|
||||
dt.Columns.Add("NavigationID", typeof(int));
|
||||
if (!string.IsNullOrEmpty(menuIds)) menuIds.Split(',').ToList().ForEach(menuId => dt.Rows.Add(id, Convert.ToInt32(menuId)));
|
||||
menuIds.ToList().ForEach(menuId => dt.Rows.Add(id, menuId));
|
||||
using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
|
||||
{
|
||||
try
|
||||
|
|
|
@ -223,7 +223,7 @@ namespace Bootstrap.DataAccess
|
|||
transaction.CommitTransaction();
|
||||
}
|
||||
}
|
||||
CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: id.ToString());
|
||||
CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List<int>() { id });
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
Loading…
Reference in New Issue