203 lines
6.8 KiB
Plaintext
203 lines
6.8 KiB
Plaintext
@page "/register"
|
|
@using System.Net
|
|
@using System.Text
|
|
@using AutoMapper
|
|
@using VisaApiClient
|
|
@using BlazorWebAssemblyVisaApiClient.Components.FormComponents.Applicants
|
|
@using global::FluentValidation
|
|
@using Newtonsoft.Json
|
|
@using Newtonsoft.Json.Linq
|
|
@using BlazorWebAssemblyVisaApiClient.Components
|
|
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
|
|
@using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models
|
|
@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</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</h5>
|
|
<PassportInput Passport="requestModel.Passport"/>
|
|
</div>
|
|
|
|
<div class="form-block">
|
|
<h5>Birth data</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="@DateTimeProvider.FormattedNow()"/>
|
|
</label><br/>
|
|
<ValidationMessage For="() => requestModel.BirthDate"></ValidationMessage>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-block">
|
|
<h5>Citizenship</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</h5>
|
|
<div >
|
|
<AddressInput Address="requestModel.PlaceOfWork.Address"/>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-block">
|
|
<h5>Place of work data</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!;
|
|
|
|
[Inject] IValidator<RegisterApplicantRequestModel> RegisterApplicantRequestValidator { get; set; } = null!;
|
|
|
|
[Inject] IMapper Mapper { get; set; } = null!;
|
|
|
|
[Inject] IDateTimeProvider DateTimeProvider { get; set; } = null!;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
requestModel.BirthDate = DateTime.Now;
|
|
}
|
|
|
|
private string ErrorsToString(IEnumerable<string> errors)
|
|
{
|
|
var stringBuilder = new StringBuilder();
|
|
foreach (var error in errors)
|
|
{
|
|
stringBuilder.Append($"{error}<br/>");
|
|
}
|
|
|
|
return stringBuilder.ToString();
|
|
}
|
|
|
|
private async void TryRegisterApplicant()
|
|
{
|
|
var validationResult = await RegisterApplicantRequestValidator.ValidateAsync(requestModel);
|
|
if (!validationResult.IsValid)
|
|
{
|
|
var errorsString = ErrorsToString(validationResult.Errors.Select(e => e.ErrorMessage));
|
|
status.SetError(errorsString);
|
|
|
|
return;
|
|
}
|
|
|
|
status.SetMessage("Wait...");
|
|
|
|
var request = Mapper.Map<RegisterApplicantRequest>(requestModel);
|
|
try
|
|
{
|
|
await Client.RegisterAsync(request);
|
|
status.SetSucces("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(ErrorsToString(errorsList));
|
|
}
|
|
else
|
|
{
|
|
ErrorHandler.Handle(e);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
ErrorHandler.Handle(e);
|
|
}
|
|
}
|
|
}
|