2020-04-28 14:51:17 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-06-30 12:12:31 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-04-13 12:41:22 +02:00
|
|
|
using System.Threading.Tasks;
|
2020-06-30 12:12:31 +02:00
|
|
|
using zero.Core;
|
2020-04-13 12:41:22 +02:00
|
|
|
using zero.Core.Api;
|
2020-04-17 12:28:03 +02:00
|
|
|
using zero.Core.Entities;
|
2020-04-16 00:56:22 +02:00
|
|
|
using zero.Core.Identity;
|
2020-04-13 12:41:22 +02:00
|
|
|
|
|
|
|
|
namespace zero.Web.Controllers
|
|
|
|
|
{
|
2020-04-16 00:56:22 +02:00
|
|
|
[ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Read)]
|
2020-05-24 18:23:56 +02:00
|
|
|
public class CountriesController<T> : BackofficeController where T : ICountry, new()
|
2020-04-13 12:41:22 +02:00
|
|
|
{
|
2020-05-24 18:23:56 +02:00
|
|
|
ICountriesApi<T> Api;
|
2020-04-13 12:41:22 +02:00
|
|
|
|
2020-05-24 18:23:56 +02:00
|
|
|
public CountriesController(ICountriesApi<T> api)
|
2020-04-13 12:41:22 +02:00
|
|
|
{
|
|
|
|
|
Api = api;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-06-03 12:57:29 +02:00
|
|
|
public async Task<IActionResult> GetById([FromQuery] string id) => Edit(await Api.GetById(id));
|
2020-04-17 15:32:33 +02:00
|
|
|
|
|
|
|
|
|
2020-06-03 12:57:29 +02:00
|
|
|
public IActionResult GetEmpty() => Edit(new T());
|
2020-05-08 14:00:01 +02:00
|
|
|
|
|
|
|
|
|
2020-05-24 18:23:56 +02:00
|
|
|
public async Task<IActionResult> GetAll([FromQuery] ListQuery<T> query) => Json(await Api.GetByQuery("languages.1-A", query)); // TODO correct language
|
2020-04-22 15:46:35 +02:00
|
|
|
|
|
|
|
|
|
2020-06-30 12:12:31 +02:00
|
|
|
public async Task<IActionResult> GetForPicker() => Json((await Api.GetAll("languages.1-A")).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 = "flag flag-" + item.Code.ToLowerInvariant(),
|
|
|
|
|
Name = item.Name
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-04-23 15:35:15 +02:00
|
|
|
[ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Write)]
|
2020-05-24 18:23:56 +02:00
|
|
|
public async Task<IActionResult> Save([FromBody] T model) => Json(await Api.Save(model));
|
2020-04-23 15:35:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
[ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Write)]
|
2020-05-24 18:23:56 +02:00
|
|
|
public async Task<IActionResult> Delete([FromQuery] string id) => Json(await Api.Delete(id));
|
2020-04-13 12:41:22 +02:00
|
|
|
}
|
|
|
|
|
}
|