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

59 lines
1.8 KiB
C#
Raw Normal View History

2020-04-28 14:51:17 +02:00
using Microsoft.AspNetCore.Mvc;
2020-11-18 12:00:51 +01:00
using Raven.Client.Documents.Linq;
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-11-18 12:00:51 +01:00
using zero.Core.Extensions;
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
}
2020-11-18 12:00:51 +01:00
public override void OnScopeChanged(string scope)
{
Service.ApplyScope(scope);
}
public async Task<EditModel<ICountry>> GetById([FromQuery] string id) => Edit(await Service.GetById(id));
2020-04-13 12:41:22 +02:00
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
2020-11-18 12:00:51 +01:00
public async Task<ListResult<ICountry>> GetByQuery([FromQuery] ListQuery<ICountry> query)
{
query.SearchSelector = country => country.Name;
return await Service.Query.OrderByDescending(x => x.IsPreferred).ThenBy(x => x.Name).ToQueriedListAsync(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-11-18 12:00:51 +01: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
{
2020-11-18 12:00:51 +01:00
return Previews(await Service.GetByIds(ids.ToArray()), (item, model) => model.Icon = "flag flag-" + item.Code.ToLowerInvariant());
2020-06-30 12:12:31 +02:00
}
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
}
}