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

87 lines
2.3 KiB
C#
Raw Normal View History

2020-05-04 16:00:39 +02:00
using Microsoft.AspNetCore.Mvc;
2020-07-20 12:02:02 +02:00
using System.Collections.Generic;
using System.Linq;
2020-05-04 16:00:39 +02:00
using System.Threading.Tasks;
using zero.Core.Api;
using zero.Core.Entities;
using zero.Core.Identity;
using zero.Web.Filters;
2020-05-04 16:00:39 +02:00
namespace zero.Web.Controllers
{
[ZeroAuthorize(Permissions.Settings.Languages, PermissionsValue.Read)]
2020-05-24 18:32:47 +02:00
public class LanguagesController<T> : BackofficeController where T : ILanguage, new()
2020-05-04 16:00:39 +02:00
{
2020-05-24 18:32:47 +02:00
ILanguagesApi<T> Api;
2020-05-04 16:00:39 +02:00
public LanguagesController(ILanguagesApi<T> api)
2020-05-04 16:00:39 +02:00
{
Api = api;
}
/// <summary>
2020-05-25 16:15:33 +02:00
/// Get empty language model
2020-05-04 16:00:39 +02:00
/// </summary>
public IActionResult GetEmpty() => Edit(new T());
2020-05-04 16:00:39 +02:00
/// <summary>
2020-05-25 16:15:33 +02:00
/// Get language by id
2020-05-04 16:00:39 +02:00
/// </summary>
public async Task<IActionResult> GetById([FromQuery] string id) => Edit(await Api.GetById(id));
2020-05-04 16:00:39 +02:00
2020-05-25 16:15:33 +02:00
/// <summary>
/// Get all languages
2020-05-04 16:00:39 +02:00
/// </summary>
2020-05-24 18:32:47 +02:00
public async Task<IActionResult> GetAll([FromQuery] ListQuery<T> query) => Json(await Api.GetByQuery(query));
2020-05-04 16:00:39 +02:00
/// <summary>
/// Returns all cultures available for creating languages.
/// </summary>
2020-05-24 18:32:47 +02:00
public IActionResult GetAllCultures() => Json(Api.GetAllCultures());
2020-05-04 16:00:39 +02:00
2020-07-06 14:35:58 +02:00
/// <summary>
/// Returns all available backoffice cultures.
/// </summary>
public IActionResult GetSupportedCultures() => Json(Api.GetAllCultures(Options.SupportedLanguages));
2020-07-20 12:02:02 +02:00
public async Task<IActionResult> GetForPicker() => Json((await Api.GetAll()).Select(x => new SelectModel()
{
Id = x.Id,
Name = x.Name,
IsActive = x.IsActive
}));
public async Task<IActionResult> GetPreviews(List<string> ids)
{
return JsonPreviews(await Api.GetByIds(ids.ToArray()), item => new PreviewModel()
{
Id = item.Id,
Icon = "fth-globe",
Name = item.Name
});
}
2020-05-04 16:00:39 +02:00
/// <summary>
2020-05-25 16:15:33 +02:00
/// Save language
2020-05-04 16:00:39 +02:00
/// </summary>
2020-08-11 16:01:10 +02:00
[ZeroAuthorize(Permissions.Settings.Languages, PermissionsValue.Update)]
2020-05-24 18:32:47 +02:00
public async Task<IActionResult> Save([FromBody] T model) => Json(await Api.Save(model));
2020-05-04 16:00:39 +02:00
/// <summary>
2020-05-25 16:15:33 +02:00
/// Deletes a language
2020-05-04 16:00:39 +02:00
/// </summary>
2020-08-11 16:01:10 +02:00
[ZeroAuthorize(Permissions.Settings.Languages, PermissionsValue.Update)]
2020-05-24 18:32:47 +02:00
public async Task<IActionResult> Delete([FromQuery] string id) => Json(await Api.Delete(id));
2020-05-04 16:00:39 +02:00
}
}