2016-01-05 17:14:10 +08:00
|
|
|
|
using Infrastructure;
|
2015-11-19 21:49:39 +08:00
|
|
|
|
using OpenAuth.App;
|
|
|
|
|
using OpenAuth.Domain;
|
2015-11-30 00:12:42 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Mvc;
|
2016-05-26 20:10:22 +08:00
|
|
|
|
using OpenAuth.Mvc.Models;
|
2015-11-19 21:49:39 +08:00
|
|
|
|
|
|
|
|
|
namespace OpenAuth.Mvc.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class RoleManagerController : BaseController
|
|
|
|
|
{
|
|
|
|
|
private RoleManagerApp _app;
|
|
|
|
|
|
|
|
|
|
public RoleManagerController()
|
|
|
|
|
{
|
2015-12-16 22:52:23 +08:00
|
|
|
|
_app = AutofacExt.GetFromFac<RoleManagerApp>();
|
2015-11-19 21:49:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET: /RoleManager/
|
2016-05-26 20:10:22 +08:00
|
|
|
|
[Authenticate]
|
2015-11-19 21:49:39 +08:00
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-30 00:12:42 +08:00
|
|
|
|
//添加或修改角色
|
2015-11-19 21:49:39 +08:00
|
|
|
|
[HttpPost]
|
2015-11-19 22:47:56 +08:00
|
|
|
|
public string Add(Role role)
|
2015-11-19 21:49:39 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-11-19 22:47:56 +08:00
|
|
|
|
_app.AddOrUpdate(role);
|
2015-11-19 21:49:39 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
BjuiResponse.statusCode = "300";
|
|
|
|
|
BjuiResponse.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(BjuiResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2015-11-30 00:12:42 +08:00
|
|
|
|
/// 加载角色下面的所有用户
|
2015-11-19 21:49:39 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string Load(int orgId, int pageCurrent = 1, int pageSize = 30)
|
|
|
|
|
{
|
|
|
|
|
return JsonHelper.Instance.Serialize(_app.Load(orgId, pageCurrent, pageSize));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-30 00:12:42 +08:00
|
|
|
|
|
|
|
|
|
#region 为用户设置角色界面
|
2015-12-22 11:55:54 +08:00
|
|
|
|
public ActionResult LookupMulti(int userId)
|
2015-11-30 00:12:42 +08:00
|
|
|
|
{
|
|
|
|
|
ViewBag.UserId = userId;
|
2015-12-22 11:55:54 +08:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string LoadForOrgAndUser(int orgId, int userId)
|
|
|
|
|
{
|
|
|
|
|
return JsonHelper.Instance.Serialize(_app.LoadForOrgAndUser(orgId, userId));
|
2015-11-30 00:12:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string AccessRoles(int userId, string ids)
|
|
|
|
|
{
|
2016-04-13 14:56:34 +08:00
|
|
|
|
var roleids = JsonHelper.Instance.Deserialize<int[]>(ids);
|
2015-11-30 00:12:42 +08:00
|
|
|
|
_app.AccessRole(userId, roleids);
|
|
|
|
|
return JsonHelper.Instance.Serialize(BjuiResponse);
|
|
|
|
|
}
|
2015-12-22 11:55:54 +08:00
|
|
|
|
|
2016-04-13 14:56:34 +08:00
|
|
|
|
public string DelAccessRoles(int userId, string ids)
|
|
|
|
|
{
|
|
|
|
|
var roleids = JsonHelper.Instance.Deserialize<int[]>(ids);
|
|
|
|
|
_app.DelAccessRole(userId, roleids);
|
|
|
|
|
return JsonHelper.Instance.Serialize(BjuiResponse);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 11:55:54 +08:00
|
|
|
|
#endregion 为用户设置角色界面
|
2015-11-19 21:49:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|