Authority adding
This commit is contained in:
@@ -46,6 +46,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
}
|
}
|
||||||
|
@if (UserDataProvider.CurrentRole is Constants.AdminRole)
|
||||||
|
{
|
||||||
|
<nav class="flex-column">
|
||||||
|
<div class="nav-item px-3">
|
||||||
|
<NavLink class="nav-link" href="authorities/add" Match="NavLinkMatch.All">
|
||||||
|
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Add authority
|
||||||
|
</NavLink>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
@page "/authorities/add"
|
||||||
|
@using AutoMapper
|
||||||
|
@using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models
|
||||||
|
@using VisaApiClient
|
||||||
|
@using BlazorWebAssemblyVisaApiClient.Components
|
||||||
|
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
|
||||||
|
@using FluentValidation
|
||||||
|
@inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase
|
||||||
|
|
||||||
|
<EditForm Model="requestModel" class="with-centered-content">
|
||||||
|
<ObjectGraphDataAnnotationsValidator/>
|
||||||
|
<div >
|
||||||
|
<label>
|
||||||
|
Email:<br/>
|
||||||
|
<InputText class="rounded" @bind-Value="requestModel.AuthData.Email"/>
|
||||||
|
<ValidationMessage For="() => requestModel.AuthData.Email"/>
|
||||||
|
</label><br/>
|
||||||
|
<p/>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
Password:<br/>
|
||||||
|
<InputText class="rounded" @bind-Value="requestModel.AuthData.Password"/>
|
||||||
|
<ValidationMessage For="() => requestModel.AuthData.Password"/>
|
||||||
|
</label><br/>
|
||||||
|
<p/>
|
||||||
|
|
||||||
|
<button class="btn-primary rounded" @onclick="Add">Add</button><br/>
|
||||||
|
<Status @ref="status"/>
|
||||||
|
</div>
|
||||||
|
</EditForm>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
private RegisterRequestModel requestModel = new();
|
||||||
|
private Status status = new();
|
||||||
|
|
||||||
|
[Inject] private IValidator<RegisterRequestModel> RegisterRequestModelValidator { get; set; } = null!;
|
||||||
|
[Inject] private IMapper Mapper { get; set; } = null!;
|
||||||
|
|
||||||
|
private async Task Add()
|
||||||
|
{
|
||||||
|
var validationResult = await RegisterRequestModelValidator.ValidateAsync(requestModel);
|
||||||
|
if (!validationResult.IsValid)
|
||||||
|
{
|
||||||
|
status.SetError(validationResult.ToErrorsString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
status.SetMessage("Wait...");
|
||||||
|
await Client.RegisterAuthorityAsync(Mapper.Map<RegisterRequest>(requestModel));
|
||||||
|
status.SetSuccess("Success");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
ErrorHandler.Handle(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
<NavLink href="@path">
|
<NavLink href="@path">
|
||||||
<button class="btn-outline-primary">Change</button>
|
<button class="btn-outline-primary">Change</button>
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
|
|
||||||
|
<button class="btn-outline-danger" @onclick="() => Delete(authority)">Delete</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
@@ -25,13 +27,27 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private IEnumerable<UserModel> authorities = [];
|
private List<UserModel> authorities = [];
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
authorities = await Client.GetAuthorityAccountsAsync();
|
authorities = (await Client.GetAuthorityAccountsAsync()).ToList();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
ErrorHandler.Handle(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Delete(UserModel authority)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Client.RemoveAuthorityAccountAsync(authority.Id);
|
||||||
|
authorities.Remove(authority);
|
||||||
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ using VisaApiClient;
|
|||||||
|
|
||||||
namespace BlazorWebAssemblyVisaApiClient.Validation.Auth;
|
namespace BlazorWebAssemblyVisaApiClient.Validation.Auth;
|
||||||
|
|
||||||
public class RegisterRequestValidator : AbstractValidator<RegisterRequestModel>
|
public class RegisterRequestModelValidator : AbstractValidator<RegisterRequestModel>
|
||||||
{
|
{
|
||||||
public RegisterRequestValidator(IValidator<AuthData> authDataValidator)
|
public RegisterRequestModelValidator(IValidator<AuthData> authDataValidator)
|
||||||
{
|
{
|
||||||
RuleFor(r => r.AuthData)
|
RuleFor(r => r.AuthData)
|
||||||
.NotEmpty()
|
.NotEmpty()
|
||||||
Reference in New Issue
Block a user