Files
mixtape/zero.Web/Controllers/TranslationsController.cs
T

53 lines
1.4 KiB
C#
Raw Normal View History

2020-05-04 14:13:03 +02:00
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using zero.Core.Api;
using zero.Core.Entities;
using zero.Core.Identity;
using zero.Web.Models;
namespace zero.Web.Controllers
{
[ZeroAuthorize(Permissions.Settings.Translations, PermissionsValue.Read)]
2020-05-24 18:40:30 +02:00
public class TranslationsController<T> : BackofficeController where T : ITranslation, new()
2020-05-04 14:13:03 +02:00
{
2020-05-24 18:40:30 +02:00
ITranslationsApi<T> Api;
2020-05-04 14:13:03 +02:00
2020-05-24 18:40:30 +02:00
public TranslationsController(ITranslationsApi<T> api)
2020-05-04 14:13:03 +02:00
{
Api = api;
}
/// <summary>
/// Get translation by id
/// </summary>
public IActionResult GetEmpty() => Edit(new T());
2020-05-04 14:13:03 +02:00
/// <summary>
/// Get translation by id
/// </summary>
public async Task<IActionResult> GetById([FromQuery] string id) => Edit(await Api.GetById(id));
2020-05-04 14:13:03 +02:00
/// <summary>
/// Get all translations
/// </summary>
2020-05-24 18:40:30 +02:00
public async Task<IActionResult> GetAll([FromQuery] ListQuery<T> query) => Json(await Api.GetByQuery(query));
2020-05-04 14:13:03 +02:00
/// <summary>
/// Save translation
/// </summary>
2020-08-11 16:01:10 +02:00
[ZeroAuthorize(Permissions.Settings.Translations, PermissionsValue.Update)]
2020-05-24 18:40:30 +02:00
public async Task<IActionResult> Save([FromBody] T model) => Json(await Api.Save(model));
2020-05-04 14:13:03 +02:00
/// <summary>
/// Deletes a translation
/// </summary>
2020-08-11 16:01:10 +02:00
[ZeroAuthorize(Permissions.Settings.Translations, PermissionsValue.Update)]
2020-05-24 18:40:30 +02:00
public async Task<IActionResult> Delete([FromQuery] string id) => Json(await Api.Delete(id));
2020-05-04 14:13:03 +02:00
}
}