using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Controllers.Api
{
///
///
///
[Route("api/[controller]")]
[ApiController]
public class GroupsController : ControllerBase
{
///
///
///
///
///
[HttpGet]
public QueryData Get([FromQuery]QueryGroupOption value)
{
return value.RetrieveData();
}
///
///
///
///
///
[HttpGet("{id}")]
public Group Get(string id)
{
return GroupHelper.Retrieves().FirstOrDefault(t => t.Id == id);
}
///
///
///
///
[HttpPost]
[ButtonAuthorize(Url = "~/Admin/Groups", Auth = "add,edit")]
public bool Post([FromBody]Group value)
{
return GroupHelper.Save(value);
}
///
///
///
///
[HttpDelete]
[ButtonAuthorize(Url = "~/Admin/Groups", Auth = "del")]
public bool Delete([FromBody]IEnumerable value)
{
return GroupHelper.Delete(value);
}
///
/// 获取部门授权
///
///
///
///
[HttpPost("{id}")]
public IEnumerable Post(string id, [FromQuery]string type)
{
IEnumerable ret = new List();
switch (type)
{
case "user":
ret = GroupHelper.RetrievesByUserId(id);
break;
case "role":
ret = GroupHelper.RetrievesByRoleId(id);
break;
}
return ret;
}
///
/// 保存部门授权
///
///
///
///
///
[HttpPut("{id}")]
[ButtonAuthorize(Url = "~/Admin/Groups", Auth = "assignUser,assignRole")]
public bool Put(string id, [FromBody]IEnumerable values, [FromQuery]string type)
{
var ret = false;
switch (type)
{
case "user":
ret = UserHelper.SaveByGroupId(id, values);
break;
case "role":
ret = RoleHelper.SaveByGroupId(id, values);
break;
}
return ret;
}
}
}