2019-03-22 15:46:32 +08:00
|
|
|
using Bootstrap.Admin.Query;
|
2018-06-07 00:45:47 +08:00
|
|
|
using Bootstrap.DataAccess;
|
|
|
|
using Longbow.Web.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Controllers.Api
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
[Route("api/[controller]")]
|
2018-11-24 15:12:44 +08:00
|
|
|
[ApiController]
|
|
|
|
public class GroupsController : ControllerBase
|
2018-09-13 19:21:35 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
2018-11-24 15:12:44 +08:00
|
|
|
public QueryData<object> Get([FromQuery]QueryGroupOption value)
|
2018-09-13 19:21:35 +08:00
|
|
|
{
|
|
|
|
return value.RetrieveData();
|
|
|
|
}
|
2018-10-31 09:51:28 +08:00
|
|
|
|
2018-09-13 19:21:35 +08:00
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("{id}")]
|
2018-10-30 13:07:29 +08:00
|
|
|
public Group Get(string id)
|
2018-09-13 19:21:35 +08:00
|
|
|
{
|
2019-01-11 23:20:28 +08:00
|
|
|
return GroupHelper.Retrieves().FirstOrDefault(t => t.Id == id);
|
2018-09-13 19:21:35 +08:00
|
|
|
}
|
2018-10-31 09:51:28 +08:00
|
|
|
|
2018-09-13 19:21:35 +08:00
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value"></param>
|
|
|
|
[HttpPost]
|
2019-03-22 15:46:32 +08:00
|
|
|
[ButtonAuthorize(Url = "~/Admin/Groups", Auth = "add,edit")]
|
2018-09-13 19:21:35 +08:00
|
|
|
public bool Post([FromBody]Group value)
|
|
|
|
{
|
2019-01-11 23:20:28 +08:00
|
|
|
return GroupHelper.Save(value);
|
2018-09-13 19:21:35 +08:00
|
|
|
}
|
2018-10-31 09:51:28 +08:00
|
|
|
|
2018-06-07 00:45:47 +08:00
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value"></param>
|
|
|
|
[HttpDelete]
|
2019-03-22 15:46:32 +08:00
|
|
|
[ButtonAuthorize(Url = "~/Admin/Groups", Auth = "del")]
|
2018-10-30 13:07:29 +08:00
|
|
|
public bool Delete([FromBody]IEnumerable<string> value)
|
2018-09-13 19:21:35 +08:00
|
|
|
{
|
2019-01-11 23:20:28 +08:00
|
|
|
return GroupHelper.Delete(value);
|
2018-09-13 19:21:35 +08:00
|
|
|
}
|
2018-10-31 09:51:28 +08:00
|
|
|
|
2018-09-13 19:21:35 +08:00
|
|
|
/// <summary>
|
2018-10-31 09:51:28 +08:00
|
|
|
/// 获取部门授权
|
2018-09-13 19:21:35 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="type"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("{id}")]
|
2019-01-16 13:20:26 +08:00
|
|
|
public IEnumerable<Group> Post(string id, [FromQuery]string type)
|
2018-09-13 19:21:35 +08:00
|
|
|
{
|
2018-10-31 16:03:49 +08:00
|
|
|
IEnumerable<Group> ret = new List<Group>();
|
2018-09-13 19:21:35 +08:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case "user":
|
2019-01-11 23:20:28 +08:00
|
|
|
ret = GroupHelper.RetrievesByUserId(id);
|
2018-09-13 19:21:35 +08:00
|
|
|
break;
|
|
|
|
case "role":
|
2019-01-11 23:20:28 +08:00
|
|
|
ret = GroupHelper.RetrievesByRoleId(id);
|
2018-09-13 19:21:35 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-01-16 13:20:26 +08:00
|
|
|
return ret;
|
2018-09-13 19:21:35 +08:00
|
|
|
}
|
2018-10-31 09:51:28 +08:00
|
|
|
|
2018-09-13 19:21:35 +08:00
|
|
|
/// <summary>
|
2018-10-31 09:51:28 +08:00
|
|
|
/// 保存部门授权
|
2018-09-13 19:21:35 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
2019-03-22 15:46:32 +08:00
|
|
|
/// <param name="values"></param>
|
2018-09-13 19:21:35 +08:00
|
|
|
/// <param name="type"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPut("{id}")]
|
2019-03-22 15:46:32 +08:00
|
|
|
[ButtonAuthorize(Url = "~/Admin/Groups", Auth = "assignUser,assignRole")]
|
|
|
|
public bool Put(string id, [FromBody]IEnumerable<string> values, [FromQuery]string type)
|
2018-09-13 19:21:35 +08:00
|
|
|
{
|
|
|
|
var ret = false;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case "user":
|
2019-03-22 15:46:32 +08:00
|
|
|
ret = UserHelper.SaveByGroupId(id, values);
|
2018-09-13 19:21:35 +08:00
|
|
|
break;
|
|
|
|
case "role":
|
2019-03-22 15:46:32 +08:00
|
|
|
ret = RoleHelper.SaveByGroupId(id, values);
|
2018-09-13 19:21:35 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2018-06-07 00:45:47 +08:00
|
|
|
}
|