2020-04-13 12:41:22 +02:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using zero.Core;
|
|
|
|
|
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-22 15:46:35 +02:00
|
|
|
using zero.Web.Filters;
|
2020-04-21 16:23:43 +02:00
|
|
|
using zero.Web.Mapper;
|
|
|
|
|
using zero.Web.Models;
|
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-04-13 12:41:22 +02:00
|
|
|
public class CountriesController : BackofficeController
|
|
|
|
|
{
|
|
|
|
|
private ICountriesApi Api { get; set; }
|
|
|
|
|
|
2020-04-22 15:46:35 +02:00
|
|
|
public CountriesController(IZeroConfiguration config, ICountriesApi api, IMapper mapper, IToken token) : base(config, mapper, token)
|
2020-04-13 12:41:22 +02:00
|
|
|
{
|
|
|
|
|
Api = api;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-04-21 16:23:43 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Get country by id
|
2020-04-22 15:46:35 +02:00
|
|
|
/// </summary>
|
|
|
|
|
[AddToken]
|
2020-04-21 16:23:43 +02:00
|
|
|
public async Task<IActionResult> GetById([FromQuery] string id)
|
|
|
|
|
{
|
2020-04-24 12:46:25 +02:00
|
|
|
return As<Country, CountryEditModel>(await Api.GetById(id));
|
2020-04-21 16:23:43 +02:00
|
|
|
}
|
2020-04-17 15:32:33 +02:00
|
|
|
|
|
|
|
|
|
2020-04-21 16:23:43 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Get all countries
|
|
|
|
|
/// </summary>
|
2020-04-17 12:28:03 +02:00
|
|
|
public async Task<IActionResult> GetAll([FromQuery] ListQuery<Country> query)
|
2020-04-13 12:41:22 +02:00
|
|
|
{
|
2020-04-24 12:46:25 +02:00
|
|
|
return As<Country, CountryListModel>(await Api.GetByQuery("en-US", query));
|
2020-04-13 12:41:22 +02:00
|
|
|
}
|
2020-04-22 15:46:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Save country
|
|
|
|
|
/// </summary>
|
|
|
|
|
[VerifyToken]
|
2020-04-23 15:35:15 +02:00
|
|
|
[ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Write)]
|
2020-04-22 15:46:35 +02:00
|
|
|
public async Task<IActionResult> Save([FromBody] CountryEditModel model)
|
|
|
|
|
{
|
2020-04-24 12:46:25 +02:00
|
|
|
Country country = Mapper.Map(model, await Api.GetById(model.Id));
|
|
|
|
|
return Json(await Api.Save(country));
|
2020-04-22 15:46:35 +02:00
|
|
|
}
|
2020-04-23 15:35:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes a country
|
|
|
|
|
/// </summary>
|
|
|
|
|
[VerifyToken]
|
|
|
|
|
[ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Write)]
|
|
|
|
|
public async Task<IActionResult> Delete([FromQuery] string id)
|
|
|
|
|
{
|
|
|
|
|
return Json(await Api.Delete(id));
|
|
|
|
|
}
|
2020-04-13 12:41:22 +02:00
|
|
|
}
|
|
|
|
|
}
|