Authority adding
This commit is contained in:
		| @@ -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"> | ||||
|                     <button class="btn-outline-primary">Change</button> | ||||
|                 </NavLink> | ||||
|                 | | ||||
|                     <button class="btn-outline-danger" @onclick="() => Delete(authority)">Delete</button> | ||||
|             </td> | ||||
|         </tr> | ||||
|     } | ||||
| @@ -25,13 +27,27 @@ | ||||
| </table> | ||||
|  | ||||
| @code { | ||||
|     private IEnumerable<UserModel> authorities = []; | ||||
|     private List<UserModel> authorities = []; | ||||
|  | ||||
|     protected override async Task OnInitializedAsync() | ||||
|     { | ||||
|         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) | ||||
|         { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user