Add language page
This commit is contained in:
parent
128729d4a0
commit
7d090e51a1
72
Oqtane.Client/Modules/Admin/Languages/Add.razor
Normal file
72
Oqtane.Client/Modules/Admin/Languages/Add.razor
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
@namespace Oqtane.Modules.Admin.Languages
|
||||||
|
@inherits ModuleBase
|
||||||
|
@using System.Globalization
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
|
@inject ILanguageService LanguageService
|
||||||
|
@inject IStringLocalizer<Add> Localizer
|
||||||
|
|
||||||
|
<table class="table table-borderless">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<Label For="name" HelpText="Name Of The Langauage" ResourceKey="Name">Name:</Label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select id="_code" class="form-control" @bind="@_code">
|
||||||
|
@foreach (var culture in GetCultures())
|
||||||
|
{
|
||||||
|
<option value="@culture.Name">@culture.DisplayName</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<Label For="isCurrent" HelpText="Indicates Whether Or Not This Language Is The Default One." ResourceKey="IsCurrent">Default?</Label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select id="isCurrent" class="form-control" @bind="@_isCurrent">
|
||||||
|
<option value="True">@Localizer["Yes"]</option>
|
||||||
|
<option value="False">@Localizer["No"]</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<button type="button" class="btn btn-success" @onclick="SaveLanguage">@Localizer["Save"]</button>
|
||||||
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">@Localizer["Cancel"]</NavLink>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private string _code = string.Empty;
|
||||||
|
private string _isCurrent = "False";
|
||||||
|
|
||||||
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
|
||||||
|
|
||||||
|
private static IEnumerable<Culture> GetCultures()
|
||||||
|
=> CultureInfo.GetCultures(CultureTypes.AllCultures)
|
||||||
|
.Select(c => new Culture { Name = c.Name, DisplayName = c.DisplayName });
|
||||||
|
|
||||||
|
private async Task SaveLanguage()
|
||||||
|
{
|
||||||
|
var language = new Language
|
||||||
|
{
|
||||||
|
SiteId = PageState.Page.SiteId,
|
||||||
|
Name = CultureInfo.GetCultureInfo(_code).DisplayName,
|
||||||
|
Code = _code,
|
||||||
|
IsCurrent = (_isCurrent == null ? false : Boolean.Parse(_isCurrent))
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
language = await LanguageService.AddLanguageAsync(language);
|
||||||
|
|
||||||
|
await logger.LogInformation("Language Added {Language}", language);
|
||||||
|
|
||||||
|
NavigationManager.NavigateTo(NavigateUrl());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await logger.LogError(ex, "Error Adding Language {Language} {Error}", language, ex.Message);
|
||||||
|
|
||||||
|
AddModuleMessage(Localizer["Error Adding Language"], MessageType.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user