BootstrapAdmin/Bootstrap.Admin/Controllers/Api/GroupsController.cs

106 lines
2.2 KiB
C#
Raw Normal View History

2018-06-07 00:45:47 +08:00
using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Controllers.Api
{
/// <summary>
///
/// </summary>
[Route("api/[controller]")]
public class GroupsController : Controller
{
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public QueryData<Group> Get(QueryGroupOption value)
{
return value.RetrieveData();
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
public Group Get(int id)
{
return GroupHelper.RetrieveGroups().FirstOrDefault(t => t.Id == id);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
[HttpPost]
2018-06-07 14:39:45 +08:00
public bool Post([FromBody]Group value)
2018-06-07 00:45:47 +08:00
{
return GroupHelper.SaveGroup(value);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
[HttpDelete]
2018-06-08 12:54:05 +08:00
public bool Delete([FromBody]IEnumerable<int> value)
2018-06-07 00:45:47 +08:00
{
return GroupHelper.DeleteGroup(value);
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="value"></param>
/// <returns></returns>
[HttpPost("{id}")]
2018-06-07 14:39:45 +08:00
public IEnumerable<Group> Post(int id, [FromBody]JObject value)
2018-06-07 00:45:47 +08:00
{
var ret = new List<Group>();
dynamic json = value;
switch ((string)json.type)
{
case "user":
ret = GroupHelper.RetrieveGroupsByUserId(id).ToList();
break;
case "role":
ret = GroupHelper.RetrieveGroupsByRoleId(id).ToList();
break;
default:
break;
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="value"></param>
/// <returns></returns>
[HttpPut("{id}")]
2018-06-07 14:39:45 +08:00
public bool Put(int id, [FromBody]JObject value)
2018-06-07 00:45:47 +08:00
{
var ret = false;
dynamic json = value;
string groupIds = json.groupIds;
switch ((string)json.type)
{
case "user":
ret = GroupHelper.SaveGroupsByUserId(id, groupIds);
break;
case "role":
ret = GroupHelper.SaveGroupsByRoleId(id, groupIds);
break;
default:
break;
}
return ret;
}
}
}