2016-11-17 20:01:28 +08:00
|
|
|
|
using Bootstrap.Admin.Models;
|
|
|
|
|
using Bootstrap.DataAccess;
|
|
|
|
|
using Longbow.Security.Principal;
|
2016-12-06 11:04:49 +08:00
|
|
|
|
using Longbow.Web.Mvc;
|
2016-11-17 20:01:28 +08:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Http;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class DictsController : ApiController
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public QueryData<Dict> Get([FromUri]QueryDictOption value)
|
|
|
|
|
{
|
|
|
|
|
return value.RetrieveData();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public Dict Get(int id)
|
|
|
|
|
{
|
|
|
|
|
return DictHelper.RetrieveDicts().FirstOrDefault(t => t.ID == id);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public bool Post([FromBody]Dict value)
|
|
|
|
|
{
|
|
|
|
|
return DictHelper.SaveDict(value);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
2016-12-09 20:13:22 +08:00
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public IEnumerable<Dict> Post(int id, [FromBody]JObject value)
|
2016-11-17 20:01:28 +08:00
|
|
|
|
{
|
2016-12-09 20:13:22 +08:00
|
|
|
|
IEnumerable<Dict> ret = new List<Dict>();
|
2016-11-17 20:01:28 +08:00
|
|
|
|
dynamic json = value;
|
|
|
|
|
switch ((string)json.type)
|
|
|
|
|
{
|
|
|
|
|
case "category":
|
2016-12-09 20:13:22 +08:00
|
|
|
|
ret = DictHelper.RetrieveCategories();
|
|
|
|
|
break;
|
|
|
|
|
case "css":
|
|
|
|
|
ret = DictHelper.RetrieveWebCss();
|
|
|
|
|
break;
|
|
|
|
|
case "activeCss":
|
|
|
|
|
ret = DictHelper.RetrieveActiveCss();
|
2016-11-17 20:01:28 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
[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 ? "成功!" : "失败" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|