OpenAuth.Net/OpenAuth.Mvc/Controllers/ModuleManagerController.cs

126 lines
3.5 KiB
C#
Raw Normal View History

using Infrastructure;
2015-11-21 23:56:39 +08:00
using OpenAuth.App;
using OpenAuth.Domain;
2015-11-25 23:29:00 +08:00
using System;
2015-11-30 00:12:42 +08:00
using System.Linq;
2015-11-25 23:29:00 +08:00
using System.Web.Mvc;
using Infrastructure.Helper;
using OpenAuth.App.ViewModel;
2015-10-26 21:58:12 +08:00
namespace OpenAuth.Mvc.Controllers
{
public class ModuleManagerController : BaseController
{
2015-11-21 23:56:39 +08:00
private ModuleManagerApp _app;
public ModuleManagerController()
{
_app = AutofacExt.GetFromFac<ModuleManagerApp>();
2015-11-21 23:56:39 +08:00
}
2015-10-26 21:58:12 +08:00
//
2015-11-21 23:56:39 +08:00
// GET: /ModuleManager/
2015-10-26 21:58:12 +08:00
public ActionResult Index()
{
return View();
}
2015-11-21 23:56:39 +08:00
2016-04-20 16:33:27 +08:00
public ActionResult Assign(int firstId, string key)
2015-11-25 23:29:00 +08:00
{
2016-04-20 16:33:27 +08:00
ViewBag.FirstId = firstId;
ViewBag.ModuleType = key;
return View();
}
2015-11-21 23:56:39 +08:00
/// <summary>
2015-11-22 15:55:26 +08:00
/// 加载模块下面的所有模块
2015-11-21 23:56:39 +08:00
/// </summary>
public string Load(int orgId, int pageCurrent = 1, int pageSize = 30)
{
return JsonHelper.Instance.Serialize(_app.Load(orgId, pageCurrent, pageSize));
}
2015-11-22 15:55:26 +08:00
/// <summary>
2015-11-27 18:10:11 +08:00
/// 直接加载所有的模块
2015-11-22 15:55:26 +08:00
/// </summary>
2015-11-27 18:10:11 +08:00
public string LoadForTree()
2015-11-22 15:55:26 +08:00
{
var orgs = AutofacExt.GetFromFac<LoginApp>().GetLoginUser().Modules;
return JsonHelper.Instance.Serialize(orgs);
}
public string LoadModuleWithRoot()
{
var orgs = AutofacExt.GetFromFac<LoginApp>().GetLoginUser().Modules.MapToList<ModuleView>();
//添加根节点
2015-11-22 15:55:26 +08:00
orgs.Add(new Module
{
Id = 0,
ParentId = -1,
2015-11-22 21:32:38 +08:00
Name = "根节点",
2015-11-22 15:55:26 +08:00
CascadeId = "0"
2015-11-27 18:10:11 +08:00
});
return JsonHelper.Instance.Serialize(orgs);
}
2016-04-18 23:36:40 +08:00
/// <summary>
/// 加载用户模块
/// </summary>
2016-04-20 16:33:27 +08:00
/// <param name="firstId">The user identifier.</param>
2016-04-18 23:36:40 +08:00
/// <returns>System.String.</returns>
2016-04-20 16:33:27 +08:00
public string LoadForUser(int firstId)
2015-11-27 18:10:11 +08:00
{
2016-04-20 16:33:27 +08:00
var orgs = _app.LoadForUser(firstId);
2015-11-27 18:10:11 +08:00
return JsonHelper.Instance.Serialize(orgs);
}
2016-04-18 23:36:40 +08:00
/// <summary>
/// 加载角色模块
/// </summary>
2016-04-20 16:33:27 +08:00
/// <param name="firstId">The role identifier.</param>
2016-04-18 23:36:40 +08:00
/// <returns>System.String.</returns>
2016-04-20 16:33:27 +08:00
public string LoadForRole(int firstId)
{
2016-04-20 16:33:27 +08:00
var orgs = _app.LoadForRole(firstId);
return JsonHelper.Instance.Serialize(orgs);
}
2015-11-30 00:12:42 +08:00
2015-12-02 16:28:01 +08:00
#region
2015-11-22 21:32:38 +08:00
//添加或修改模块
[HttpPost]
public string Add(Module model)
2015-11-21 23:56:39 +08:00
{
2015-11-22 21:32:38 +08:00
try
{
_app.AddOrUpdate(model);
}
catch (Exception ex)
{
BjuiResponse.statusCode = "300";
BjuiResponse.message = ex.Message;
}
return JsonHelper.Instance.Serialize(BjuiResponse);
2015-11-21 23:56:39 +08:00
}
public string Delete(string Id)
{
try
{
foreach (var obj in Id.Split(','))
{
_app.Delete(int.Parse(obj));
}
}
catch (Exception e)
{
BjuiResponse.statusCode = "300";
BjuiResponse.message = e.Message;
}
return JsonHelper.Instance.Serialize(BjuiResponse);
}
2015-11-27 18:10:11 +08:00
#endregion
2015-12-02 16:28:01 +08:00
2015-11-21 23:56:39 +08:00
}
2015-10-26 21:58:12 +08:00
}