@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 Registration

Registration data

Authentication data@(Constants.RequiredFieldMarkup)
Your Fullname
Fullname of your mother
Fullname of your father
Your passport@(Constants.RequiredFieldMarkup)
Birth data@(Constants.RequiredFieldMarkup)





Citizenship@(Constants.RequiredFieldMarkup)



Address of your place of work@(Constants.RequiredFieldMarkup)
Place of work data@(Constants.RequiredFieldMarkup)


Other



@code { private RegisterApplicantRequestModel requestModel = new(); private Status status = null!; private string formattedMaxBirthdayDate = null!; [Inject] IValidator 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(requestModel); try { await Client.RegisterAsync(request); status.SetSuccess("Register successful. Now log in."); } catch (ApiException e) { if (e.StatusCode == (int)HttpStatusCode.BadRequest && e.Result.AdditionalProperties.TryGetValue("errors", out var errors)) { var errorsList = ((JArray)errors).ToObject>(); if (errorsList is null) { ErrorHandler.Handle(new JsonException("Can't convert validation errors to list")); return; } status.SetError(string.Join("
", errorsList)); } else { throw; } } catch (Exception e) { status.SetError("Error occured"); ErrorHandler.Handle(e); } } }