2020-05-19 15:53:01 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-09-02 11:52:33 +02:00
|
|
|
using System;
|
2020-10-27 15:47:23 +01:00
|
|
|
using System.Collections.Generic;
|
2020-05-19 15:53:01 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using zero.Core.Api;
|
2020-05-25 11:27:23 +02:00
|
|
|
using zero.Core.Entities;
|
2020-08-27 14:22:13 +02:00
|
|
|
using zero.Core.Extensions;
|
2020-08-20 14:35:08 +02:00
|
|
|
using zero.Web.Models;
|
2020-05-19 15:53:01 +02:00
|
|
|
|
|
|
|
|
namespace zero.Web.Controllers
|
|
|
|
|
{
|
2020-08-27 14:22:13 +02:00
|
|
|
public class PagesController : BackofficeController
|
2020-05-19 15:53:01 +02:00
|
|
|
{
|
2020-08-27 14:22:13 +02:00
|
|
|
IPagesApi Api;
|
2020-08-17 14:46:13 +02:00
|
|
|
IRevisionsApi RevisionsApi;
|
2020-05-19 15:53:01 +02:00
|
|
|
|
2020-09-02 11:52:33 +02:00
|
|
|
public PagesController(IPagesApi 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-10-27 15:47:23 +01:00
|
|
|
public async Task<IList<PageType>> GetAllowedPageTypes([FromQuery] string parent = null) => await Api.GetAllowedPageTypes(parent);
|
2020-07-08 13:59:46 +02:00
|
|
|
|
|
|
|
|
|
2020-10-27 15:47:23 +01:00
|
|
|
public PageType GetPageType([FromQuery] string alias) => Api.GetPageType(alias);
|
2020-05-25 11:27:23 +02:00
|
|
|
|
2020-10-27 15:47:23 +01:00
|
|
|
public async Task<PageEditModel<IPage>> GetById([FromQuery] string id)
|
2020-08-20 14:35:08 +02:00
|
|
|
{
|
2020-08-27 14:22:13 +02:00
|
|
|
IPage entity = await Api.GetById(id);
|
2020-08-20 14:35:08 +02:00
|
|
|
|
2020-09-06 15:34:47 +02:00
|
|
|
if (entity == null)
|
|
|
|
|
{
|
2020-10-27 15:47:23 +01:00
|
|
|
return null;
|
2020-09-06 15:34:47 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-27 14:22:13 +02:00
|
|
|
return Edit<IPage, PageEditModel<IPage>>(new PageEditModel<IPage>()
|
2020-08-20 14:35:08 +02:00
|
|
|
{
|
|
|
|
|
Entity = entity,
|
2020-08-28 14:26:26 +02:00
|
|
|
//Revisions = await RevisionsApi.GetPaged<IPage>(id),
|
2020-08-20 14:35:08 +02:00
|
|
|
PageType = Api.GetPageType(entity.PageTypeAlias)
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-07-08 13:59:46 +02:00
|
|
|
|
2020-10-27 15:47:23 +01:00
|
|
|
|
|
|
|
|
public EditModel<IPage> GetEmpty(string type, string parent = null)
|
2020-08-12 14:16:28 +02:00
|
|
|
{
|
2020-09-02 11:52:33 +02:00
|
|
|
PageType pageType = Api.GetPageType(type);
|
|
|
|
|
IPage model = Activator.CreateInstance(pageType.ContentType) as IPage;
|
2020-08-12 14:16:28 +02:00
|
|
|
|
2020-09-02 11:52:33 +02:00
|
|
|
model.PageTypeAlias = type;
|
2020-10-12 13:14:23 +02:00
|
|
|
model.ParentId = parent;
|
2020-09-02 11:52:33 +02:00
|
|
|
|
|
|
|
|
return Edit(model);
|
2020-08-27 14:22:13 +02:00
|
|
|
}
|
2020-07-08 13:59:46 +02:00
|
|
|
|
2020-08-27 14:22:13 +02:00
|
|
|
|
2020-10-27 15:47:23 +01:00
|
|
|
public async Task<ListResult<Revision>> GetRevisions([FromQuery] string id, [FromQuery] int page = 1) => await RevisionsApi.GetPaged<IPage>(id, page);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<EntityResult<IPage>> Save([FromBody] IPage model) => await Api.Save(model);
|
|
|
|
|
|
2020-07-08 13:59:46 +02:00
|
|
|
|
2020-08-13 14:58:01 +02:00
|
|
|
[HttpPost]
|
2020-10-27 15:47:23 +01:00
|
|
|
public async Task<EntityResult<IList<IPage>>> SaveSorting([FromBody] string[] ids) => await Api.SaveSorting(ids);
|
|
|
|
|
|
2020-08-13 14:58:01 +02:00
|
|
|
|
2020-08-13 15:55:59 +02:00
|
|
|
[HttpPost]
|
2020-10-27 15:47:23 +01:00
|
|
|
public async Task<EntityResult<IPage>> Move([FromBody] ActionCopyModel model) => await Api.Move(model.Id, model.DestinationId);
|
|
|
|
|
|
2020-08-14 13:26:48 +02:00
|
|
|
|
|
|
|
|
[HttpPost]
|
2020-10-27 15:47:23 +01:00
|
|
|
public async Task<EntityResult<IPage>> Copy([FromBody] ActionCopyModel model) => await Api.Copy(model.Id, model.DestinationId, model.IncludeDescendants);
|
|
|
|
|
|
2020-08-13 15:55:59 +02:00
|
|
|
|
2020-08-27 11:41:40 +02:00
|
|
|
[HttpPost]
|
2020-10-27 15:47:23 +01:00
|
|
|
public async Task<EntityResult<string[]>> Restore([FromBody] ActionCopyModel model) => await Api.Restore(model.Id, model.IncludeDescendants);
|
2020-07-08 13:59:46 +02:00
|
|
|
|
2020-10-27 15:47:23 +01:00
|
|
|
|
|
|
|
|
public async Task<EntityResult<string[]>> Delete([FromQuery] string id) => await Api.Delete(id, true);
|
2020-05-19 15:53:01 +02:00
|
|
|
}
|
|
|
|
|
}
|