Files
schengen-visa/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Pages/Applications.razor

68 lines
2.4 KiB
Plaintext

@page "/applications"
@using System.Text
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
@using VisaApiClient
@inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase
<PageTitle>Applications</PageTitle>
<table class="table table-bordered">
<thead>
@((MarkupString)htmlHead)
</thead>
<tbody>
@((MarkupString)htmlBody)
</tbody>
</table >
@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 = "<tr><th>Destination Country</th><th>Visa Category</th><th>Request date</th><th>Days requested</th><th>Status</th></tr>";
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($"<tr class=\"{rowClass}\"><th>{application.DestinationCountry}</th><th>{application.VisaCategory.GetDisplayName()}</th><th>{application.RequestDate.ToString("d")}</th><th>{application.ValidDaysRequested}</th><th>{application.Status.GetDisplayName()}</th></tr>");
}
htmlBody = stringBuilder.ToString();
break;
default:
Nav.NavigateTo("/"); //todo feedback
break;
}
}
catch (Exception e)
{
ErrorHandler.Handle(e);
}
}
}