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

49 lines
1.6 KiB
C#
Raw Normal View History

2020-04-28 14:51:17 +02:00
using Microsoft.AspNetCore.Mvc;
2020-06-30 12:12:31 +02:00
using System.Collections.Generic;
2020-04-13 12:41:22 +02:00
using System.Threading.Tasks;
using zero.Core.Backoffice;
using zero.Core.Entities;
2020-04-16 00:56:22 +02:00
using zero.Core.Identity;
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)]
public class CountriesController : BackofficeController
2020-04-13 12:41:22 +02:00
{
ICountriesBackofficeService Service;
2020-04-13 12:41:22 +02:00
public CountriesController(ICountriesBackofficeService service)
2020-04-13 12:41:22 +02:00
{
Service = service;
2020-04-13 12:41:22 +02:00
}
public async Task<EditModel<ICountry>> GetById([FromQuery] string id) => Edit(await Service.GetById(id));
2020-04-17 15:32:33 +02:00
public EditModel<ICountry> GetEmpty([FromServices] ICountry blueprint) => Edit(blueprint);
2020-05-08 14:00:01 +02:00
public async Task<ListResult<ICountry>> GetAll([FromQuery] ListQuery<ICountry> query) => await Service.GetByQuery(query);
2020-05-08 14:00:01 +02:00
public async Task<IEnumerable<SelectModel>> GetForPicker() => await SelectList(Service.Stream());
2020-06-30 12:12:31 +02:00
2020-10-29 19:29:30 +01:00
public async Task<IList<PreviewModel>> GetPreviews([FromQuery] List<string> ids)
2020-06-30 12:12:31 +02:00
{
return Previews(await Service.GetByIds(ids.ToArray()), item => new PreviewModel()
2020-06-30 12:12:31 +02:00
{
Id = item.Id,
Icon = "flag flag-" + item.Code.ToLowerInvariant(),
Name = item.Name
});
}
2020-08-11 16:01:10 +02:00
[ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Update)]
public async Task<EntityResult<ICountry>> Save([FromBody] ICountry model) => await Service.Save(model);
2020-08-11 16:01:10 +02:00
[ZeroAuthorize(Permissions.Settings.Countries, PermissionsValue.Update)]
public async Task<EntityResult<ICountry>> Delete([FromQuery] string id) => await Service.DeleteById(id);
2020-04-13 12:41:22 +02:00
}
}