using Bootstrap.Admin.Models; using Bootstrap.DataAccess; using Longbow.Security.Principal; using Newtonsoft.Json.Linq; using System.Collections.Generic; using System.Linq; using System.Web.Http; namespace Bootstrap.Admin.Controllers { public class DictsController : ApiController { /// /// /// /// /// [HttpGet] public QueryData Get([FromUri]QueryDictOption value) { return value.RetrieveData(); } /// /// /// /// /// [HttpGet] public Dict Get(int id) { return DictHelper.RetrieveDicts().FirstOrDefault(t => t.ID == id); } /// /// /// /// [HttpPost] public bool Post([FromBody]Dict value) { return DictHelper.SaveDict(value); } /// /// /// /// [HttpPost] public IEnumerable Post(int id, [FromBody]JObject value) { var ret = new List(); dynamic json = value; switch ((string)json.type) { case "category": ret = DictHelper.RetrieveCategories().ToList(); break; default: break; } return ret; } /// /// /// /// [HttpDelete] public dynamic Delete([FromBody]string value) { if (!LgbPrincipal.IsAdmin(User.Identity.Name) && !User.IsInRole("Administrators")) return new { result = false, msg = "当前用户权限不够" }; var result = DictHelper.DeleteDict(value); return new { result = result, msg = result ? "成功!" : "失败" }; } } }