try rewirte of all backoffice controllers to ApiControllers
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user