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-08-17 14:46:13 +02:00
|
|
|
IRevisionsApi RevisionsApi;
|
2020-05-19 15:53:01 +02:00
|
|
|
|
2020-08-17 14:46:13 +02:00
|
|
|
public PagesController(IPagesApi<T> api, IRevisionsApi revisionsApi)
|
2020-05-19 15:53:01 +02:00
|
|
|
{
|
|
|
|
|
Api = api;
|
2020-08-17 14:46:13 +02:00
|
|
|
RevisionsApi = revisionsApi;
|
2020-05-19 15:53:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-08-17 14:46:13 +02:00
|
|
|
public async Task<IActionResult> GetRevisions([FromQuery] string id) => Json(await RevisionsApi.GetPaged<T>(id));
|
2020-07-08 13:59:46 +02:00
|
|
|
|
|
|
|
|
public async Task<IActionResult> Save([FromBody] T model) => Json(await Api.Save(model));
|
|
|
|
|
|
2020-08-13 14:58:01 +02:00
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> SaveSorting([FromBody] string[] ids) => Json(await Api.SaveSorting(ids));
|
|
|
|
|
|
2020-08-13 15:55:59 +02:00
|
|
|
[HttpPost]
|
2020-08-14 13:26:48 +02:00
|
|
|
public async Task<IActionResult> Move([FromBody] CopyModel model) => Json(await Api.Move(model.Id, model.DestinationId));
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Copy([FromBody] CopyModel model) => Json(await Api.Copy(model.Id, model.DestinationId, model.IncludeDescendants));
|
2020-08-13 15:55:59 +02:00
|
|
|
|
2020-07-08 13:59:46 +02:00
|
|
|
|
2020-08-14 14:42:31 +02:00
|
|
|
public async Task<IActionResult> Delete([FromQuery] string id, [FromQuery] bool moveToRecycleBin = false) => Json(await Api.Delete(id, moveToRecycleBin));
|
2020-08-14 13:26:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public class CopyModel
|
|
|
|
|
{
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
public string DestinationId { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool IncludeDescendants { get; set; }
|
|
|
|
|
}
|
2020-05-19 15:53:01 +02:00
|
|
|
}
|
|
|
|
|
}
|