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

118 lines
3.2 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;
using System.Web.Mvc;
2016-07-19 11:44:48 +08:00
using OpenAuth.App.SSO;
using OpenAuth.App.ViewModel;
using OpenAuth.Mvc.Models;
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
}
// GET: /ModuleManager/
[Authenticate]
2015-10-26 21:58:12 +08:00
public ActionResult Index()
{
return View();
}
2015-11-21 23:56:39 +08:00
public ActionResult Assign(Guid 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(Guid orgId, int pageCurrent = 1, int pageSize = 30)
2015-11-21 23:56:39 +08:00
{
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
{
2016-07-19 11:44:48 +08:00
var orgs = AuthUtil.GetCurrentUser().Modules;
return JsonHelper.Instance.Serialize(orgs);
}
public string LoadModuleWithRoot()
{
2016-07-19 11:44:48 +08:00
var orgs = AuthUtil.GetCurrentUser().Modules.MapToList<ModuleView>();
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>
public string LoadForUser(Guid 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>
public string LoadForRole(Guid 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)
{
2016-10-14 11:22:16 +08:00
Result.Status = false;
Result.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
}
public string Delete(string Id)
{
try
{
foreach (var obj in Id.Split(','))
{
_app.Delete(Guid.Parse(obj));
2015-11-21 23:56:39 +08:00
}
}
catch (Exception e)
{
2016-10-14 11:22:16 +08:00
Result.Status = false;
Result.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-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
}