2020-05-19 15:53:01 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using zero.Core.Api;
|
2020-05-25 11:27:23 +02:00
|
|
|
using zero.Core.Entities;
|
2020-05-19 15:53:01 +02:00
|
|
|
|
|
|
|
|
namespace zero.Web.Controllers
|
|
|
|
|
{
|
2020-08-12 14:16:28 +02:00
|
|
|
public class PagesController<T> : BackofficeController where T : IPage, new()
|
2020-05-19 15:53:01 +02:00
|
|
|
{
|
2020-05-25 11:27:23 +02:00
|
|
|
IPagesApi<T> Api;
|
2020-05-19 15:53:01 +02:00
|
|
|
|
2020-05-25 11:27:23 +02:00
|
|
|
public PagesController(IPagesApi<T> api)
|
2020-05-19 15:53:01 +02:00
|
|
|
{
|
|
|
|
|
Api = api;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-07-08 13:59:46 +02:00
|
|
|
public async Task<ActionResult> GetAllowedPageTypes([FromQuery] string parent = null) => Json(await Api.GetAllowedPageTypes(parent));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IActionResult GetPageType([FromQuery] string alias) => Json(Api.GetPageType(alias));
|
2020-05-25 11:27:23 +02:00
|
|
|
|
|
|
|
|
|
2020-06-03 12:57:29 +02:00
|
|
|
public async Task<IActionResult> GetById([FromQuery] string id) => Edit(await Api.GetById(id));
|
2020-07-08 13:59:46 +02:00
|
|
|
|
2020-08-12 14:16:28 +02:00
|
|
|
public IActionResult GetEmpty(string type, string parent = null) => Edit(new T()
|
|
|
|
|
{
|
|
|
|
|
PageTypeAlias = type,
|
|
|
|
|
ParentId = parent
|
|
|
|
|
});
|
|
|
|
|
|
2020-07-08 13:59:46 +02:00
|
|
|
|
|
|
|
|
public async Task<IActionResult> Save([FromBody] T model) => Json(await Api.Save(model));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> Delete([FromQuery] string id) => Json(await Api.Delete(id));
|
2020-05-19 15:53:01 +02:00
|
|
|
}
|
|
|
|
|
}
|