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

71 lines
1.8 KiB
C#
Raw Normal View History

2020-04-28 14:51:17 +02:00
using Microsoft.AspNetCore.Mvc;
2020-04-13 12:41:22 +02:00
using System.Threading.Tasks;
using zero.Core;
using zero.Core.Api;
using zero.Core.Entities;
2020-04-16 00:56:22 +02:00
using zero.Core.Identity;
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>
2020-04-21 16:23:43 +02:00
public async Task<IActionResult> GetById([FromQuery] string id)
{
2020-04-29 12:11:35 +02:00
return await As<Country, CountryEditModel>(await Api.GetById(id));
2020-04-21 16:23:43 +02:00
}
2020-04-17 15:32:33 +02:00
2020-05-08 14:00:01 +02:00
/// <summary>
/// Get new country
/// </summary>
public IActionResult GetEmpty()
{
return Json(new CountryEditModel());
}
2020-04-21 16:23:43 +02:00
/// <summary>
/// Get all countries
/// </summary>
public async Task<IActionResult> GetAll([FromQuery] ListQuery<Country> query)
2020-04-13 12:41:22 +02:00
{
2020-04-29 12:11:35 +02:00
return await 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>
[ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Write)]
2020-04-22 15:46:35 +02:00
public async Task<IActionResult> Save([FromBody] CountryEditModel model)
{
2020-04-29 12:11:35 +02:00
Country country = await Mapper.Map(model, await Api.GetById(model.Id));
2020-04-24 12:46:25 +02:00
return Json(await Api.Save(country));
2020-04-22 15:46:35 +02:00
}
/// <summary>
/// Deletes a country
/// </summary>
[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
}
}