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.Countries, PermissionsValue.Read)] public class CountriesController : BackofficeController { ICountriesApi Api; public CountriesController(ICountriesApi api) { Api = api; } /// /// Get country by id /// public async Task GetById([FromQuery] string id) { return await As(await Api.GetById(id)); } /// /// Get new country /// public IActionResult GetEmpty() { return Json(new CountryEditModel()); } /// /// Get all countries /// public async Task GetAll([FromQuery] ListQuery query) { return await As(await Api.GetByQuery("en-US", query)); } /// /// Save country /// [ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Write)] public async Task Save([FromBody] CountryEditModel model) { Country country = await Mapper.Map(model, await Api.GetById(model.Id)); return Json(await Api.Save(country)); } /// /// Deletes a country /// [ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Write)] public async Task Delete([FromQuery] string id) { return Json(await Api.Delete(id)); } } }