using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace Bootstrap.Admin.Controllers
{
///
///
///
public class UsersController : ApiController
{
///
///
///
///
///
[HttpGet]
public QueryData Get([FromUri]QueryUserOption value)
{
return value.RetrieveData();
}
///
///
///
///
///
///
[HttpPost]
public IEnumerable Post(int id, [FromBody]JObject value)
{
var ret = new List();
dynamic json = value;
switch ((string)json.type)
{
case "role":
ret = UserHelper.RetrieveUsersByRoleId(id).ToList();
break;
case "group":
ret = UserHelper.RetrieveUsersByGroupId(id).ToList();
break;
default:
break;
}
return ret;
}
///
///
///
///
///
[HttpGet]
public User Get(int id)
{
return UserHelper.RetrieveUsers().FirstOrDefault(t => t.ID == id);
}
///
///
///
///
[HttpPost]
public bool Post([FromBody]User value)
{
return UserHelper.SaveUser(value);
}
[HttpPut]
public bool Put(int id, [FromBody]JObject value)
{
var ret = false;
dynamic json = value;
string userIds = json.userIds;
switch ((string)json.type)
{
case "role":
ret = UserHelper.SaveUsersByRoleId(id, userIds);
break;
case "group":
ret = UserHelper.SaveUsersByGroupId(id, userIds);
break;
default:
break;
}
return ret;
}
///
///
///
///
[HttpDelete]
public bool Delete([FromBody]string value)
{
return UserHelper.DeleteUser(value);
}
}
}