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]")]
public class GroupsController : Controller
{
///
///
///
///
///
[HttpGet]
public QueryData Get(QueryGroupOption value)
{
return value.RetrieveData();
}
///
///
///
///
///
[HttpGet("{id}")]
public Group Get(int id)
{
return GroupHelper.RetrieveGroups().FirstOrDefault(t => t.Id == id);
}
///
///
///
///
[HttpPost]
public bool Post([FromBody]Group value)
{
return GroupHelper.SaveGroup(value);
}
///
///
///
///
[HttpDelete]
public bool Delete([FromBody]IEnumerable value)
{
return GroupHelper.DeleteGroup(value);
}
///
///
///
///
///
///
[HttpPost("{id}")]
public IEnumerable Post(int id, [FromQuery]string type)
{
var ret = new List();
switch (type)
{
case "user":
ret = GroupHelper.RetrieveGroupsByUserId(id).ToList();
break;
case "role":
ret = GroupHelper.RetrieveGroupsByRoleId(id).ToList();
break;
default:
break;
}
return ret;
}
///
///
///
///
///
///
///
[HttpPut("{id}")]
public bool Put(int id, [FromBody]IEnumerable groupIds, [FromQuery]string type)
{
var ret = false;
switch (type)
{
case "user":
ret = GroupHelper.SaveGroupsByUserId(id, groupIds);
break;
case "role":
ret = GroupHelper.SaveGroupsByRoleId(id, groupIds);
break;
default:
break;
}
return ret;
}
}
}