2016-01-05 17:14:10 +08:00
|
|
|
|
using Infrastructure;
|
2015-11-21 23:56:39 +08:00
|
|
|
|
using OpenAuth.App;
|
2016-10-18 17:34:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using OpenAuth.App.Interface;
|
2017-11-30 17:47:41 +08:00
|
|
|
|
using OpenAuth.App.Response;
|
2017-11-29 20:49:14 +08:00
|
|
|
|
using OpenAuth.Repository.Domain;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
using System.Collections.Generic;
|
2015-10-26 21:58:12 +08:00
|
|
|
|
|
|
|
|
|
namespace OpenAuth.Mvc.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class ModuleManagerController : BaseController
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
private ModuleManagerApp _app;
|
|
|
|
|
public ModuleManagerController(IAuth authUtil, ModuleManagerApp app) : base(authUtil)
|
|
|
|
|
{
|
|
|
|
|
_app = app;
|
|
|
|
|
}
|
2015-11-21 23:56:39 +08:00
|
|
|
|
|
|
|
|
|
// GET: /ModuleManager/
|
2020-10-22 14:59:36 +08:00
|
|
|
|
|
2015-10-26 21:58:12 +08:00
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2015-11-21 23:56:39 +08:00
|
|
|
|
|
2020-10-22 14:59:36 +08:00
|
|
|
|
|
2017-12-13 17:50:58 +08:00
|
|
|
|
public ActionResult Assign()
|
2015-11-25 23:29:00 +08:00
|
|
|
|
{
|
2017-12-13 17:50:58 +08:00
|
|
|
|
return View();
|
|
|
|
|
}
|
2018-04-14 15:21:09 +08:00
|
|
|
|
|
2016-10-20 16:47:35 +08:00
|
|
|
|
/// <summary>
|
2020-10-22 14:59:36 +08:00
|
|
|
|
/// 加载角色模块
|
2016-10-20 16:47:35 +08:00
|
|
|
|
/// </summary>
|
2020-10-22 14:59:36 +08:00
|
|
|
|
/// <param name="firstId">The role identifier.</param>
|
2016-10-20 16:47:35 +08:00
|
|
|
|
/// <returns>System.String.</returns>
|
2020-10-22 14:59:36 +08:00
|
|
|
|
public string LoadForRole(string firstId)
|
2016-10-20 16:47:35 +08:00
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
var modules = _app.LoadForRole(firstId);
|
2017-12-16 23:29:38 +08:00
|
|
|
|
return JsonHelper.Instance.Serialize(modules);
|
|
|
|
|
}
|
2020-10-22 14:59:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取角色已经分配的字段
|
2017-12-16 23:29:38 +08:00
|
|
|
|
/// </summary>
|
2020-10-22 14:59:36 +08:00
|
|
|
|
/// <param name="roleId">角色id</param>
|
|
|
|
|
/// <param name="moduleCode">模块代码,如Category</param>
|
2017-12-16 23:29:38 +08:00
|
|
|
|
/// <returns></returns>
|
2020-10-22 14:59:36 +08:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public string LoadPropertiesForRole(string roleId, string moduleCode)
|
2016-10-20 16:47:35 +08:00
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var props = _app.LoadPropertiesForRole(roleId, moduleCode);
|
|
|
|
|
var data = new Response<IEnumerable<string>>
|
|
|
|
|
{
|
|
|
|
|
Result = props.ToList(),
|
|
|
|
|
};
|
|
|
|
|
return JsonHelper.Instance.Serialize(data);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return JsonHelper.Instance.Serialize(new Response
|
|
|
|
|
{
|
|
|
|
|
Message =ex.Message,
|
|
|
|
|
Code = 500,
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-12-16 23:29:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据某角色ID获取可访问某模块的菜单项
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string LoadMenusForRole(string moduleId, string firstId)
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
var menus = _app.LoadMenusForRole(moduleId, firstId);
|
2017-12-16 23:29:38 +08:00
|
|
|
|
return JsonHelper.Instance.Serialize(menus);
|
2016-10-20 16:47:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 17:36:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取发起页面的菜单权限
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
public string LoadAuthorizedMenus(string modulecode)
|
2018-04-04 11:59:18 +08:00
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
var user = _authUtil.GetCurrentUser();
|
2018-04-04 17:36:41 +08:00
|
|
|
|
var module = user.Modules.First(u =>u.Code == modulecode);
|
|
|
|
|
if (module != null)
|
|
|
|
|
{
|
|
|
|
|
return JsonHelper.Instance.Serialize(module.Elements);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return "";
|
2018-04-04 11:59:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-12-02 16:28:01 +08:00
|
|
|
|
#region 添加编辑模块
|
2016-10-18 17:34:41 +08:00
|
|
|
|
|
2017-12-11 22:59:36 +08:00
|
|
|
|
//添加模块
|
2015-11-22 21:32:38 +08:00
|
|
|
|
[HttpPost]
|
2020-10-22 14:59:36 +08:00
|
|
|
|
|
2017-12-11 17:49:59 +08:00
|
|
|
|
public string Add(Module model)
|
2015-11-21 23:56:39 +08:00
|
|
|
|
{
|
2015-11-22 21:32:38 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
_app.Add(model);
|
2017-12-11 17:49:59 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Result.Code = 500;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
Result.Message = ex.InnerException?.Message??ex.Message;
|
2017-12-11 17:49:59 +08:00
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-11 22:59:36 +08:00
|
|
|
|
//修改模块
|
2017-12-11 17:49:59 +08:00
|
|
|
|
[HttpPost]
|
2020-10-22 14:59:36 +08:00
|
|
|
|
|
2017-12-11 17:49:59 +08:00
|
|
|
|
public string Update(Module model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
_app.Update(model);
|
2015-11-22 21:32:38 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2017-11-28 23:54:49 +08:00
|
|
|
|
Result.Code = 500;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
Result.Message = ex.InnerException?.Message ?? ex.Message;
|
2015-11-22 21:32:38 +08:00
|
|
|
|
}
|
2016-10-14 11:22:16 +08:00
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
2015-11-21 23:56:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-17 00:20:55 +08:00
|
|
|
|
[HttpPost]
|
2017-10-11 16:19:34 +08:00
|
|
|
|
public string Delete(string[] ids)
|
2015-11-21 23:56:39 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
_app.Delete(ids);
|
2015-11-21 23:56:39 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2017-11-28 23:54:49 +08:00
|
|
|
|
Result.Code = 500;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
Result.Message = e.InnerException?.Message ?? e.Message;
|
2015-11-21 23:56:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 11:22:16 +08:00
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
2015-11-21 23:56:39 +08:00
|
|
|
|
}
|
2015-12-02 16:28:01 +08:00
|
|
|
|
|
2016-10-18 17:34:41 +08:00
|
|
|
|
#endregion 添加编辑模块
|
2017-12-11 17:49:59 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-11 22:59:36 +08:00
|
|
|
|
/// 加载当前用户可访问模块的菜单
|
2017-12-11 17:49:59 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="moduleId">The module identifier.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
public string LoadMenus(string moduleId)
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
var user = _authUtil.GetCurrentUser();
|
2017-12-11 17:49:59 +08:00
|
|
|
|
|
|
|
|
|
var module = user.Modules.Single(u => u.Id == moduleId);
|
|
|
|
|
|
|
|
|
|
var data = new TableData
|
|
|
|
|
{
|
|
|
|
|
data = module.Elements,
|
|
|
|
|
count = module.Elements.Count(),
|
|
|
|
|
};
|
|
|
|
|
return JsonHelper.Instance.Serialize(data);
|
|
|
|
|
}
|
2017-12-11 22:59:36 +08:00
|
|
|
|
|
|
|
|
|
//添加菜单
|
|
|
|
|
[HttpPost]
|
2020-10-22 14:59:36 +08:00
|
|
|
|
|
2017-12-11 22:59:36 +08:00
|
|
|
|
public string AddMenu(ModuleElement model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
_app.AddMenu(model);
|
2017-12-11 22:59:36 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Result.Code = 500;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
Result.Message = ex.InnerException?.Message ?? ex.Message;
|
2017-12-11 22:59:36 +08:00
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-05 12:35:05 +08:00
|
|
|
|
//添加菜单
|
|
|
|
|
[HttpPost]
|
2020-10-22 14:59:36 +08:00
|
|
|
|
|
2018-04-05 12:35:05 +08:00
|
|
|
|
public string UpdateMenu(ModuleElement model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
_app.UpdateMenu(model);
|
2018-04-05 12:35:05 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Result.Code = 500;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
Result.Message = ex.InnerException?.Message ?? ex.Message;
|
2018-04-05 12:35:05 +08:00
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-12-11 22:59:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除菜单
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public string DelMenu(params string[] ids)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
_app.DelMenu(ids);
|
2017-12-11 22:59:36 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Result.Code = 500;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
Result.Message = e.InnerException?.Message ?? e.Message;
|
2017-12-11 22:59:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
2020-10-22 14:59:36 +08:00
|
|
|
|
|
|
|
|
|
|
2015-11-21 23:56:39 +08:00
|
|
|
|
}
|
2015-10-26 21:58:12 +08:00
|
|
|
|
}
|