2016-01-05 17:14:10 +08:00
|
|
|
|
using Infrastructure;
|
2015-12-19 21:48:17 +08:00
|
|
|
|
using OpenAuth.App;
|
|
|
|
|
using OpenAuth.Domain;
|
2015-12-22 15:04:15 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Mvc;
|
2016-07-14 00:14:24 +08:00
|
|
|
|
using OpenAuth.App.SSO;
|
2016-05-26 20:10:22 +08:00
|
|
|
|
using OpenAuth.Mvc.Models;
|
2015-12-19 21:48:17 +08:00
|
|
|
|
|
|
|
|
|
namespace OpenAuth.Mvc.Controllers
|
|
|
|
|
{
|
2015-12-22 15:04:15 +08:00
|
|
|
|
public class ResourceManagerController : BaseController
|
2015-12-19 21:48:17 +08:00
|
|
|
|
{
|
|
|
|
|
private ResourceManagerApp _app;
|
|
|
|
|
|
|
|
|
|
public ResourceManagerController()
|
|
|
|
|
{
|
|
|
|
|
_app = AutofacExt.GetFromFac<ResourceManagerApp>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET: /UserManager/
|
2016-05-26 20:10:22 +08:00
|
|
|
|
[Authenticate]
|
2015-12-19 21:48:17 +08:00
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加或修改Resource
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public string Add(Resource model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_app.AddOrUpdate(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
BjuiResponse.statusCode = "300";
|
|
|
|
|
BjuiResponse.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(BjuiResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载某分类的所有Resources
|
|
|
|
|
/// </summary>
|
2016-09-02 18:05:17 +08:00
|
|
|
|
public string Load(Guid categoryId, int pageCurrent = 1, int pageSize = 30)
|
2015-12-19 21:48:17 +08:00
|
|
|
|
{
|
2016-07-14 00:14:24 +08:00
|
|
|
|
return JsonHelper.Instance.Serialize(_app.Load(AuthUtil.GetUserName(), categoryId, pageCurrent, pageSize));
|
2015-12-19 21:48:17 +08:00
|
|
|
|
}
|
2015-12-22 15:04:15 +08:00
|
|
|
|
|
|
|
|
|
public string LoadForTree()
|
|
|
|
|
{
|
|
|
|
|
var models = _app.LoadAll();
|
|
|
|
|
return JsonHelper.Instance.Serialize(models);
|
|
|
|
|
}
|
2015-12-19 21:48:17 +08:00
|
|
|
|
|
2016-09-02 18:05:17 +08:00
|
|
|
|
public string Delete(Guid Id)
|
2015-12-19 21:48:17 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_app.Delete(Id);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
BjuiResponse.statusCode = "300";
|
|
|
|
|
BjuiResponse.message = e.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JsonHelper.Instance.Serialize(BjuiResponse);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-17 23:16:58 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 为用户或角色分配权限
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="firstId">关联表中的firstId.</param>
|
|
|
|
|
/// <param name="key">关联表中的Key
|
|
|
|
|
/// <para>如:UserResource/RoleResource</para>
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <returns>ActionResult.</returns>
|
2016-09-02 18:05:17 +08:00
|
|
|
|
public ActionResult AssignRes(Guid firstId, string key)
|
2015-12-22 15:04:15 +08:00
|
|
|
|
{
|
2016-04-17 23:16:58 +08:00
|
|
|
|
ViewBag.FirstId = firstId;
|
|
|
|
|
ViewBag.ModuleType = key;
|
2015-12-22 15:04:15 +08:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-17 23:16:58 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载带有授权的资源信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cId">分类ID</param>
|
|
|
|
|
/// <param name="firstId">关联表中的firstId</param>
|
|
|
|
|
/// <param name="key">关联表中的key</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
2016-09-02 18:05:17 +08:00
|
|
|
|
public string LoadWithAccess(Guid cId, Guid firstId, string key)
|
2015-12-22 15:04:15 +08:00
|
|
|
|
{
|
2016-07-14 00:14:24 +08:00
|
|
|
|
return JsonHelper.Instance.Serialize(_app.LoadWithAccess(AuthUtil.GetUserName(),key,firstId, cId));
|
2015-12-22 15:04:15 +08:00
|
|
|
|
}
|
2015-12-19 21:48:17 +08:00
|
|
|
|
}
|
2015-11-22 23:54:21 +08:00
|
|
|
|
}
|