2020-05-05 13:13:19 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
2020-04-06 00:26:31 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using zero.Core;
|
|
|
|
|
using zero.Core.Api;
|
2020-05-05 13:13:19 +02:00
|
|
|
using zero.Core.Entities;
|
|
|
|
|
using zero.Core.Extensions;
|
|
|
|
|
using zero.Core.Identity;
|
|
|
|
|
using zero.Web.Mapper;
|
|
|
|
|
using zero.Web.Models;
|
2020-04-06 00:26:31 +02:00
|
|
|
|
|
|
|
|
namespace zero.Web.Controllers
|
|
|
|
|
{
|
2020-05-05 13:13:19 +02:00
|
|
|
[ZeroAuthorize(Permissions.Settings.Applications, PermissionsValue.Read)]
|
2020-04-06 00:26:31 +02:00
|
|
|
public class ApplicationsController : BackofficeController
|
|
|
|
|
{
|
|
|
|
|
private IApplicationsApi Api { get; set; }
|
|
|
|
|
|
2020-05-05 13:13:19 +02:00
|
|
|
private ZeroOptions Options { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ApplicationsController(IZeroConfiguration config, IApplicationsApi api, IMapper mapper, IToken token, IOptionsMonitor<ZeroOptions> options) : base(config, mapper, token)
|
2020-04-06 00:26:31 +02:00
|
|
|
{
|
|
|
|
|
Api = api;
|
2020-05-05 13:13:19 +02:00
|
|
|
Options = options.CurrentValue;
|
2020-04-06 00:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-05-05 13:13:19 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Get translation by id
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IActionResult GetEmpty()
|
2020-04-06 00:26:31 +02:00
|
|
|
{
|
2020-05-05 13:13:19 +02:00
|
|
|
return Json(new ApplicationEditModel());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get translation by id
|
|
|
|
|
/// </summary>
|
|
|
|
|
public async Task<IActionResult> GetById([FromQuery] string id)
|
|
|
|
|
{
|
|
|
|
|
return await As<Application, ApplicationEditModel>(await Api.GetById(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get all translations
|
|
|
|
|
/// </summary>
|
|
|
|
|
public async Task<IActionResult> GetAll([FromQuery] ListQuery<Application> query = null)
|
|
|
|
|
{
|
|
|
|
|
if (query == null)
|
|
|
|
|
{
|
|
|
|
|
return await As<Application, ApplicationListModel>(await Api.GetAll());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await As<Application, ApplicationListModel>(await Api.GetByQuery(query));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get all available features to select
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IActionResult GetAllFeatures()
|
|
|
|
|
{
|
|
|
|
|
return Json(Options.Features);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Save translation
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ZeroAuthorize(Permissions.Settings.Applications, PermissionsValue.Write)]
|
|
|
|
|
public async Task<IActionResult> Save([FromBody] ApplicationEditModel model)
|
|
|
|
|
{
|
|
|
|
|
Application entity = await Mapper.Map(model, await Api.GetById(model.Id));
|
|
|
|
|
return await As<Application, ApplicationEditModel>(await Api.Save(entity));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes a translation
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ZeroAuthorize(Permissions.Settings.Applications, PermissionsValue.Write)]
|
|
|
|
|
public async Task<IActionResult> Delete([FromQuery] string id)
|
|
|
|
|
{
|
|
|
|
|
return await As<Application, ApplicationEditModel>(await Api.Delete(id));
|
2020-04-06 00:26:31 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|