try rewirte of all backoffice controllers to ApiControllers

This commit is contained in:
2020-10-27 15:47:23 +01:00
parent edfb6ec2e5
commit 6eb81a5eeb
37 changed files with 315 additions and 354 deletions
+13 -36
View File
@@ -4,8 +4,8 @@ using System.Linq;
using System.Threading.Tasks;
using zero.Core.Api;
using zero.Core.Entities;
using zero.Core.Extensions;
using zero.Core.Identity;
using zero.Web.Models;
namespace zero.Web.Controllers
{
@@ -13,56 +13,39 @@ namespace zero.Web.Controllers
public class LanguagesController : BackofficeController
{
ILanguagesApi Api;
ILanguage Blueprint;
public LanguagesController(ILanguagesApi api, ILanguage blueprint)
public LanguagesController(ILanguagesApi api)
{
Api = api;
Blueprint = blueprint;
}
/// <summary>
/// Get empty language model
/// </summary>
public IActionResult GetEmpty() => Edit(Blueprint.Clone());
public EditModel<ILanguage> GetEmpty([FromServices] ILanguage blueprint) => Edit(blueprint);
/// <summary>
/// Get language by id
/// </summary>
public async Task<IActionResult> GetById([FromQuery] string id) => Edit(await Api.GetById(id));
public async Task<EditModel<ILanguage>> GetById([FromQuery] string id) => Edit(await Api.GetById(id));
/// <summary>
/// Get all languages
/// </summary>
public async Task<IActionResult> GetAll([FromQuery] ListQuery<ILanguage> query) => Json(await Api.GetByQuery(query));
public async Task<ListResult<ILanguage>> GetAll([FromQuery] ListQuery<ILanguage> query) => await Api.GetByQuery(query);
/// <summary>
/// Returns all cultures available for creating languages.
/// </summary>
public IActionResult GetAllCultures() => Json(Api.GetAllCultures());
public IList<Culture> GetAllCultures() => Api.GetAllCultures();
/// <summary>
/// Returns all available backoffice cultures.
/// </summary>
public IActionResult GetSupportedCultures() => Json(Api.GetAllCultures(Options.SupportedLanguages));
public IList<Culture> GetSupportedCultures() => Api.GetAllCultures(Options.SupportedLanguages);
public async Task<IActionResult> GetForPicker() => Json((await Api.GetAll()).Select(x => new SelectModel()
public async Task<IEnumerable<SelectModel>> GetForPicker() => (await Api.GetAll()).Select(x => new SelectModel()
{
Id = x.Id,
Name = x.Name,
IsActive = x.IsActive
}));
});
public async Task<IActionResult> GetPreviews(List<string> ids)
public async Task<IList<PreviewModel>> GetPreviews(List<string> ids)
{
return JsonPreviews(await Api.GetByIds(ids.ToArray()), item => new PreviewModel()
return Previews(await Api.GetByIds(ids.ToArray()), item => new PreviewModel()
{
Id = item.Id,
Icon = "fth-globe",
@@ -71,17 +54,11 @@ namespace zero.Web.Controllers
}
/// <summary>
/// Save language
/// </summary>
[ZeroAuthorize(Permissions.Settings.Languages, PermissionsValue.Update)]
public async Task<IActionResult> Save([FromBody] ILanguage model) => Json(await Api.Save(model));
public async Task<EntityResult<ILanguage>> Save([FromBody] ILanguage model) => await Api.Save(model);
/// <summary>
/// Deletes a language
/// </summary>
[ZeroAuthorize(Permissions.Settings.Languages, PermissionsValue.Update)]
public async Task<IActionResult> Delete([FromQuery] string id) => Json(await Api.Delete(id));
public async Task<EntityResult<ILanguage>> Delete([FromQuery] string id) => await Api.Delete(id);
}
}