using Bootstrap.Admin.Models; using Bootstrap.DataAccess; using Longbow.Web.Mvc; using Newtonsoft.Json.Linq; using System.Collections.Generic; using System.Linq; using System.Web.Http; namespace Bootstrap.Admin.Controllers { public class GroupsController : ApiController { /// /// /// /// /// [HttpGet] public QueryData Get([FromUri]QueryGroupOption value) { return value.RetrieveData(); } /// /// /// /// /// [HttpGet] 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]string value) { return GroupHelper.DeleteGroup(value); } /// /// /// /// /// /// [HttpPost] public IEnumerable Post(int id, [FromBody]JObject value) { var ret = new List(); 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; } /// /// /// /// /// /// [HttpPut] public bool Put(int id, [FromBody]JObject value) { 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; } } }