using Microsoft.AspNetCore.Mvc; namespace zero.Backoffice.Modules.Countries; public class CountriesController : ZeroBackofficeApiController { protected ICountryStore Store { get; set; } public CountriesController(ICountryStore store) { Store = store; } [HttpGet("empty")] public virtual async Task> Empty() { Country model = await Store.Empty(); if (model == null) { return NotFound(); } return Mapper.Map(model); } [HttpGet("{id}")] public virtual async Task> Get(string id, string changeVector = null) { Country model = await Store.Load(id, changeVector); if (model == null) { return NotFound(); } return Mapper.Map(model); } [HttpGet] public virtual async Task> Get(ListQuery query) { Paged result = await Store.Load(query.Page, query.PageSize, q => q.Filter(query)); return Mapper.Map(result); } [HttpPost] public virtual async Task> Create(CountrySave saveModel) { Country model = Mapper.Map(saveModel); Result result = await Store.Create(model); if (result.IsSuccess) { Result mappedResult = Mapper.Map(result); return CreatedAtAction(nameof(CountriesController.Get), new { id = model.Id }, mappedResult); } return result.WithoutModel(); } [HttpPut("{id}")] public virtual async Task> Update(string id, CountrySave updateModel) { if (id != updateModel.Id) { return BadRequest(BackofficeConstants.HttpErrors.NoIdMatchOnUpdate); } Country model = Mapper.Map(updateModel); model.Id = id; Result result = await Store.Update(model); if (result.IsSuccess) { return NoContent(); } return result.WithoutModel(); } [HttpDelete("{id}")] public virtual async Task> Delete(string id) { Country model = await Store.Load(id); if (model == null) { return NotFound(); } Result result = await Store.Delete(model); if (result.IsSuccess) { return NoContent(); } return result.WithoutModel(); } }