Вытащил солюшен на уровень выше, чтобы прощё было дотнетить
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is failing
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	continuous-integration/drone/push Build is failing
				
			This commit is contained in:
		
							
								
								
									
										192
									
								
								BlazorWebAssemblyVisaApiClient/Pages/Register.razor
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										192
									
								
								BlazorWebAssemblyVisaApiClient/Pages/Register.razor
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,192 @@ | ||||
| @page "/register" | ||||
| @using System.Net | ||||
| @using AutoMapper | ||||
| @using BlazorWebAssemblyVisaApiClient.Components | ||||
| @using BlazorWebAssemblyVisaApiClient.Components.FormComponents | ||||
| @using BlazorWebAssemblyVisaApiClient.Components.FormComponents.Applicants | ||||
| @using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers | ||||
| @using BlazorWebAssemblyVisaApiClient.Validation | ||||
| @using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models | ||||
| @using FluentValidation | ||||
| @using Newtonsoft.Json | ||||
| @using Newtonsoft.Json.Linq | ||||
| @using VisaApiClient | ||||
| @inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase | ||||
|  | ||||
| <PageTitle>Registration</PageTitle> | ||||
|  | ||||
| <div class="horizontal-centered-content"> | ||||
|     <h3>Registration data</h3> | ||||
|     <EditForm class="form" Model="requestModel" OnValidSubmit="TryRegisterApplicant"> | ||||
|         <ObjectGraphDataAnnotationsValidator/> | ||||
|  | ||||
|         <div class="form-block"> | ||||
|             <h5>Authentication data@(Constants.RequiredFieldMarkup)</h5> | ||||
|             <AuthDataInput AuthData="requestModel.RegisterRequest.AuthData"/> | ||||
|         </div> | ||||
|  | ||||
|         <div class="form-block"> | ||||
|             <h5>Your Fullname</h5> | ||||
|             <NameInput Name="requestModel.ApplicantName"/> | ||||
|         </div> | ||||
|  | ||||
|         <div class="form-block"> | ||||
|             <h5>Fullname of your mother</h5> | ||||
|             <NameInput Name="requestModel.MotherName"/> | ||||
|         </div> | ||||
|  | ||||
|         <div class="form-block"> | ||||
|             <h5>Fullname of your father</h5> | ||||
|             <NameInput Name="requestModel.FatherName"/> | ||||
|         </div> | ||||
|  | ||||
|         <div class="form-block"> | ||||
|             <h5>Your passport@(Constants.RequiredFieldMarkup)</h5> | ||||
|             <PassportInput Passport="requestModel.Passport"/> | ||||
|         </div> | ||||
|  | ||||
|         <div class="form-block"> | ||||
|             <h5>Birth data@(Constants.RequiredFieldMarkup)</h5> | ||||
|             <div > | ||||
|                 <label> | ||||
|                     Country of birth:<br/> | ||||
|                     <InputText DisplayName="Country of birth" class="rounded" @bind-Value="requestModel.CountryOfBirth"/> | ||||
|                 </label><br/> | ||||
|                 <ValidationMessage For="() => requestModel.CountryOfBirth"></ValidationMessage><br/> | ||||
|                 <label> | ||||
|                     City of birth:<br/> | ||||
|                     <InputText DisplayName="City of birth" class="rounded" @bind-Value="requestModel.CityOfBirth"/> | ||||
|                 </label><br/> | ||||
|                 <ValidationMessage For="() => requestModel.CityOfBirth"></ValidationMessage><br/> | ||||
|                 <label> | ||||
|                     Birth date:<br/> | ||||
|                     <InputDate DisplayName="Birth date" class="rounded" @bind-Value="requestModel.BirthDate" max="@formattedMaxBirthdayDate"/> | ||||
|                 </label><br/> | ||||
|                 <ValidationMessage For="() => requestModel.BirthDate"></ValidationMessage> | ||||
|             </div> | ||||
|         </div> | ||||
|  | ||||
|         <div class="form-block"> | ||||
|             <h5>Citizenship@(Constants.RequiredFieldMarkup)</h5> | ||||
|             <div > | ||||
|                 <label> | ||||
|                     Citizenship:<br/> | ||||
|                     <InputText class="rounded" @bind-Value="requestModel.Citizenship"/> | ||||
|                 </label><br/> | ||||
|                 <ValidationMessage For="() => requestModel.Citizenship"></ValidationMessage><br/> | ||||
|                 <label> | ||||
|                     Citizenship by birth:<br/> | ||||
|                     <InputText DisplayName="Citizenship by birth" class="rounded" @bind-Value="requestModel.CitizenshipByBirth"/> | ||||
|                 </label><br/> | ||||
|                 <ValidationMessage For="() => requestModel.CitizenshipByBirth"></ValidationMessage> | ||||
|             </div> | ||||
|         </div> | ||||
|  | ||||
|         <div class="form-block"> | ||||
|             <h5>Address of your place of work@(Constants.RequiredFieldMarkup)</h5> | ||||
|             <div > | ||||
|                 <AddressInput Address="requestModel.PlaceOfWork.Address"/> | ||||
|             </div> | ||||
|         </div> | ||||
|  | ||||
|         <div class="form-block"> | ||||
|             <h5>Place of work data@(Constants.RequiredFieldMarkup)</h5> | ||||
|             <div > | ||||
|                 <PlaceOfWorkInput PlaceOfWork="requestModel.PlaceOfWork"/><br/> | ||||
|  | ||||
|                 <label> | ||||
|                     Job title:<br/> | ||||
|                     <InputText DisplayName="Job title" class="rounded" @bind-Value="requestModel.JobTitle"/> | ||||
|                 </label><br/> | ||||
|                 <ValidationMessage For="() => requestModel.JobTitle"></ValidationMessage> | ||||
|             </div> | ||||
|         </div> | ||||
|  | ||||
|         <div class="form-block"> | ||||
|             <h5>Other</h5> | ||||
|  | ||||
|             <div > | ||||
|                 <label> | ||||
|                     Gender: <EnumInputList Model="requestModel" EnumProperty="r => r.Gender"/> | ||||
|                 </label> | ||||
|             </div><br/> | ||||
|  | ||||
|             <div > | ||||
|                 <label> | ||||
|                     Marital status: <EnumInputList Model="requestModel" EnumProperty="r => r.MaritalStatus"/> | ||||
|                 </label> | ||||
|             </div><br/> | ||||
|  | ||||
|             <div > | ||||
|                 <label> | ||||
|                     Non-resident: <InputCheckbox @bind-Value="requestModel.IsNonResident"/> | ||||
|                 </label> | ||||
|             </div> | ||||
|         </div><br/> | ||||
|  | ||||
|         <input type="submit" class="btn-outline-primary" value="Register"/> | ||||
|         <Status @ref="status"/> | ||||
|     </EditForm> | ||||
| </div> | ||||
|  | ||||
| @code | ||||
| { | ||||
|     private RegisterApplicantRequestModel requestModel = new(); | ||||
|     private Status status = null!; | ||||
|     private string formattedMaxBirthdayDate = null!; | ||||
|  | ||||
|     [Inject] IValidator<RegisterApplicantRequestModel> RegisterApplicantRequestValidator { get; set; } = null!; | ||||
|  | ||||
|     [Inject] IMapper Mapper { get; set; } = null!; | ||||
|  | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         requestModel.BirthDate = DateTime.Now.AddYears(-ConfigurationConstraints.ApplicantMinAge); | ||||
|         formattedMaxBirthdayDate = requestModel.BirthDate.ToString("yyyy-MM-dd"); | ||||
|     } | ||||
|  | ||||
|     private async void TryRegisterApplicant() | ||||
|     { | ||||
|         var validationResult = await RegisterApplicantRequestValidator.ValidateAsync(requestModel); | ||||
|         if (!validationResult.IsValid) | ||||
|         { | ||||
|             var errorsString = validationResult.ToErrorsString(); | ||||
|             status.SetError(errorsString); | ||||
|  | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         status.SetMessage("Wait..."); | ||||
|  | ||||
|         var request = Mapper.Map<RegisterApplicantRequest>(requestModel); | ||||
|         try | ||||
|         { | ||||
|             await Client.RegisterAsync(request); | ||||
|             status.SetSuccess("Register successful. Now log in."); | ||||
|         } | ||||
|         catch (ApiException<ProblemDetails> e) | ||||
|         { | ||||
|             if (e.StatusCode == (int)HttpStatusCode.BadRequest | ||||
|                 && e.Result.AdditionalProperties.TryGetValue("errors", out var errors)) | ||||
|             { | ||||
|                 var errorsList = ((JArray)errors).ToObject<List<string>>(); | ||||
|                 if (errorsList is null) | ||||
|                 { | ||||
|                     ErrorHandler.Handle(new JsonException("Can't convert validation errors to list")); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 status.SetError(string.Join("<br/>", errorsList)); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             status.SetError("Error occured"); | ||||
|             ErrorHandler.Handle(e); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user