2016-11-01 08:10:59 +08:00
|
|
|
|
using Bootstrap.Admin.Models;
|
2016-10-31 16:57:59 +08:00
|
|
|
|
using Bootstrap.DataAccess;
|
2016-12-06 11:04:49 +08:00
|
|
|
|
using Longbow.Web.Mvc;
|
2016-10-27 17:56:00 +08:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2016-11-01 08:10:59 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Http;
|
2016-10-27 17:56:00 +08:00
|
|
|
|
|
2016-10-24 22:10:17 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class RolesController : ApiController
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public QueryData<Role> Get([FromUri]QueryRoleOption value)
|
|
|
|
|
{
|
|
|
|
|
return value.RetrieveData();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
2016-10-26 21:32:54 +08:00
|
|
|
|
[HttpPost]
|
2016-10-28 13:36:43 +08:00
|
|
|
|
public IEnumerable<Role> Post(int id, [FromBody]JObject value)
|
2016-10-24 22:10:17 +08:00
|
|
|
|
{
|
2016-10-28 13:36:43 +08:00
|
|
|
|
var ret = new List<Role>();
|
|
|
|
|
dynamic json = value;
|
|
|
|
|
switch ((string)json.type)
|
2016-10-28 11:12:25 +08:00
|
|
|
|
{
|
2016-10-28 13:36:43 +08:00
|
|
|
|
case "user":
|
|
|
|
|
ret = RoleHelper.RetrieveRolesByUserId(id).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case "group":
|
|
|
|
|
ret = RoleHelper.RetrieveRolesByGroupId(id).ToList();
|
|
|
|
|
break;
|
2016-10-28 14:45:09 +08:00
|
|
|
|
case "menu":
|
|
|
|
|
ret = RoleHelper.RetrieveRolesByMenuId(id).ToList();
|
|
|
|
|
break;
|
2016-10-28 13:36:43 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2016-10-28 11:12:25 +08:00
|
|
|
|
}
|
2016-10-28 14:45:09 +08:00
|
|
|
|
return ret;
|
2016-10-25 18:47:33 +08:00
|
|
|
|
}
|
2016-10-27 17:56:00 +08:00
|
|
|
|
/// <summary>根据GroupID获取
|
2016-10-25 18:47:33 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
2016-10-27 17:56:00 +08:00
|
|
|
|
/// <returns></returns>
|
2016-10-25 18:47:33 +08:00
|
|
|
|
[HttpPut]
|
2016-10-26 21:32:54 +08:00
|
|
|
|
public bool Put(int id, [FromBody]JObject value)
|
2016-10-25 18:47:33 +08:00
|
|
|
|
{
|
2016-10-28 13:36:43 +08:00
|
|
|
|
var ret = false;
|
2016-10-26 21:32:54 +08:00
|
|
|
|
dynamic json = value;
|
|
|
|
|
string roleIds = json.roleIds;
|
2016-10-28 13:36:43 +08:00
|
|
|
|
switch ((string)json.type)
|
|
|
|
|
{
|
|
|
|
|
case "user":
|
|
|
|
|
ret = RoleHelper.SaveRolesByUserId(id, roleIds);
|
|
|
|
|
break;
|
|
|
|
|
case "group":
|
|
|
|
|
ret = RoleHelper.SaveRolesByGroupId(id, roleIds);
|
|
|
|
|
break;
|
2016-10-28 14:45:09 +08:00
|
|
|
|
case "menu":
|
|
|
|
|
ret = RoleHelper.SavaRolesByMenuId(id, roleIds);
|
|
|
|
|
break;
|
2016-10-28 13:36:43 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
2016-10-24 22:10:17 +08:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool Post([FromBody]Role value)
|
|
|
|
|
{
|
|
|
|
|
return RoleHelper.SaveRole(value);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
[HttpDelete]
|
|
|
|
|
public bool Delete([FromBody]string value)
|
|
|
|
|
{
|
|
|
|
|
return RoleHelper.DeleteRole(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|