@page "/applications" @using System.Net @using System.Text @using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers @using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider @using VisaApiClient @inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase Applications @((MarkupString)htmlHead) @((MarkupString)htmlBody)
@code { private string htmlBody = null!; private string htmlHead = null!; [Inject] private IUserDataProvider UserDataProvider { get; set; } = null!; [Inject] private NavigationManager Nav { get; set; } = null!; protected override async Task OnInitializedAsync() { var stringBuilder = new StringBuilder(); try { switch (UserDataProvider.GetCurrentRole()) { case "Applicant": htmlHead = "Destination CountryVisa CategoryRequest dateDays requestedStatus"; var applications = await Client.GetForApplicantAsync(); foreach (var application in applications) { var rowClass = application.Status switch { ApplicationStatus.Pending => "", ApplicationStatus.Approved => "table-success", ApplicationStatus.Rejected => "table-danger", ApplicationStatus.Closed => "table-danger", _ => throw new ArgumentOutOfRangeException() }; stringBuilder.AppendLine($"{application.DestinationCountry}{application.VisaCategory.GetDisplayName()}{application.RequestDate.ToString("d")}{application.ValidDaysRequested}{application.Status.GetDisplayName()}"); } htmlBody = stringBuilder.ToString(); break; default: Nav.NavigateTo("/"); //todo feedback break; } } catch (Exception e) { if (e is ApiException { Result.Status: (int)HttpStatusCode.Unauthorized } problemDetailsException) { htmlBody = $"

{problemDetailsException.Result.Detail!}

"; } else { ErrorHandler.Handle(e); } } } }