Application creating but without past visas and visits

This commit is contained in:
2024-09-06 23:31:07 +03:00
parent f90a0e7e82
commit c197a45f83
24 changed files with 516 additions and 86 deletions

View File

@@ -1,5 +1,4 @@
@page "/applications"
@using System.Net
@using System.Text
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
@@ -61,14 +60,7 @@
}
catch (Exception e)
{
if (e is ApiException<ProblemDetails> { Result.Status: (int)HttpStatusCode.Unauthorized } problemDetailsException)
{
htmlBody = $"<p>{problemDetailsException.Result.Detail!}</p>";
}
else
{
ErrorHandler.Handle(e);
}
}
}

View File

@@ -1,10 +1,17 @@
@page "/visaApplications/new"
@page "/applications/new"
@using System.Net
@using AutoMapper
@using BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models
@using BlazorWebAssemblyVisaApiClient.Components.FormComponents.Applicants
@using VisaApiClient
@using BlazorWebAssemblyVisaApiClient.Components
@using BlazorWebAssemblyVisaApiClient.Components.FormComponents.VisaApplications
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
@using FluentValidation
@using Newtonsoft.Json
@using Newtonsoft.Json.Linq
@inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase
<PageTitle>New Application</PageTitle>
@@ -23,9 +30,10 @@
<ValidationMessage For="() => requestModel.DestinationCountry"></ValidationMessage><br/>
<label>
Category: <EnumInputList Model="requestModel"
EnumProperty="r => r.VisaCategory"
OnChanged="StateHasChanged"/>
Category:
<EnumInputList Model="requestModel"
EnumProperty="r => r.VisaCategory"
OnChanged="StateHasChanged"/>
</label><br/>
<ValidationMessage For="() => requestModel.VisaCategory"></ValidationMessage><br/>
@@ -46,33 +54,98 @@
<ValidationMessage For="() => requestModel.ValidDaysRequested"></ValidationMessage><br/>
</div>
<div class="form-block">
<fieldset disabled="@(requestModel.VisaCategory is not VisaCategory.Transit)">
@if (requestModel.VisaCategory is VisaCategory.Transit)
{
<div class="form-block">
<h5>Permission to destination Country</h5>
<PermissionToDestCountryInput PermissionToDestCountry="requestModel.PermissionToDestCountry" />
</fieldset>
</div><br/>
<PermissionToDestCountryInput PermissionToDestCountry="requestModel.PermissionToDestCountry"/>
</div>
}
@if (isNonResident)
{
<div class="form-block">
<h5>Re-entry permission</h5>
<ReentryPermitInput ReentryPermit="requestModel.ReentryPermit" />
</div>
<br/>
}
<input type="submit" class="btn-outline-primary" value="Register"/>
<ValidationSummary/>
<Status @ref="status"/>
</EditForm>
</div>
//todo past visas and visits
@code {
private VisaApplicationCreateRequestModel requestModel = new();
private Status status = null!;
private bool isNonResident;
[Inject] IDateTimeProvider DateTimeProvider { get; set; } = null!;
protected override void OnInitialized()
[Inject] IUserDataProvider UserDataProvider { get; set; } = null!;
[Inject] IValidator<VisaApplicationCreateRequestModel> VisaApplicationCreateRequestValidator { get; set; } = null!;
[Inject] IMapper Mapper { get; set; } = null!;
protected override async Task OnInitializedAsync()
{
try
{
isNonResident = (await UserDataProvider.GetApplicant()).IsNonResident;
}
catch (Exception e)
{
ErrorHandler.Handle(e);
}
requestModel.PermissionToDestCountry!.ExpirationDate = DateTimeProvider.Now();
}
private static void TryCreate()
private async Task TryCreate()
{
var validationResult = await VisaApplicationCreateRequestValidator.ValidateAsync(requestModel);
if (!validationResult.IsValid)
{
var errorsString = validationResult.ToErrorsString();
status.SetError(errorsString);
}
status.SetMessage("Wait...");
var request = Mapper.Map<VisaApplicationCreateRequest>(requestModel);
try
{
await Client.CreateApplicationAsync(request);
status.SetSucces("Application created successfully.");
}
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
{
ErrorHandler.Handle(e);
}
}
catch (Exception e)
{
ErrorHandler.Handle(e);
}
}
}

View File

@@ -1,6 +1,5 @@
@page "/register"
@using System.Net
@using System.Text
@using AutoMapper
@using VisaApiClient
@using BlazorWebAssemblyVisaApiClient.Components.FormComponents.Applicants
@@ -8,6 +7,7 @@
@using Newtonsoft.Json
@using Newtonsoft.Json.Linq
@using BlazorWebAssemblyVisaApiClient.Components
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
@using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models
@inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase
@@ -144,23 +144,12 @@
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));
var errorsString = validationResult.ToErrorsString();
status.SetError(errorsString);
return;
@@ -187,7 +176,7 @@
return;
}
status.SetError(ErrorsToString(errorsList));
status.SetError(string.Join("<br/>", errorsList));
}
else
{
@@ -196,6 +185,7 @@
}
catch (Exception e)
{
status.SetError("Error occured");
ErrorHandler.Handle(e);
}
}