Вытащил солюшен на уровень выше, чтобы прощё было дотнетить
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
@using System.Net
|
||||
@using BlazorWebAssemblyVisaApiClient.ErrorHandling
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
|
||||
@using VisaApiClient
|
||||
@code {
|
||||
public static AuthData? AuthData;
|
||||
|
||||
[CascadingParameter] private GlobalErrorHandler ErrorHandler { get; set; } = null!;
|
||||
|
||||
[CascadingParameter] private Status? Status { get; set; }
|
||||
|
||||
[Inject] private IClient Client { get; set; } = null!;
|
||||
|
||||
[Inject] private NavigationManager Nav { get; set; } = null!;
|
||||
|
||||
[Inject] private IUserDataProvider UserDataProvider { get; set; } = null!;
|
||||
|
||||
///Authorize with email and password
|
||||
/// <returns>Message to user</returns>
|
||||
public async Task TryAuthorize(AuthData authData)
|
||||
{
|
||||
Status?.SetMessage("Wait...");
|
||||
try
|
||||
{
|
||||
var token = await Client.LoginAsync(authData.Email, authData.Password);
|
||||
Client.AuthToken = token;
|
||||
AuthData = authData;
|
||||
UserDataProvider.UpdateCurrentRole();
|
||||
|
||||
Status?.SetSuccess("Logged in successfully.");
|
||||
}
|
||||
catch (ApiException<ProblemDetails> e)
|
||||
{
|
||||
if (e.Result.Status == (int)HttpStatusCode.Forbidden)
|
||||
{
|
||||
Status?.SetError(e.Result.Detail!);
|
||||
}
|
||||
else
|
||||
{
|
||||
Status?.SetError("Error occured");
|
||||
ErrorHandler.Handle(e);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Status?.SetError("Error occured");
|
||||
ErrorHandler.Handle(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
{
|
||||
Client.AuthToken = null;
|
||||
AuthData = null;
|
||||
try
|
||||
{
|
||||
UserDataProvider.UpdateCurrentRole();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorHandler.Handle(e);
|
||||
}
|
||||
}
|
||||
|
||||
///Re-auth if token expired or something
|
||||
public async Task ReAuthenticate()
|
||||
{
|
||||
if (AuthData is not null)
|
||||
{
|
||||
await TryAuthorize(AuthData);
|
||||
}
|
||||
else
|
||||
{
|
||||
Client.AuthToken = null;
|
||||
AuthData = null;
|
||||
Nav.NavigateTo("/");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@using BlazorWebAssemblyVisaApiClient.ErrorHandling
|
||||
@using VisaApiClient
|
||||
@code
|
||||
{
|
||||
[CascadingParameter] protected GlobalErrorHandler ErrorHandler { get; set; } = null!;
|
||||
|
||||
[Inject] protected IClient Client { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
@using VisaApiClient
|
||||
<div>
|
||||
<div >
|
||||
<label >
|
||||
Country:<br/>
|
||||
<InputText class="rounded" @bind-Value="Address.Country"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => Address.Country"></ValidationMessage><br/>
|
||||
</div>
|
||||
|
||||
<div >
|
||||
<label >
|
||||
City:<br/>
|
||||
<InputText class="rounded" @bind-Value="Address.City"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => Address.City"></ValidationMessage><br/>
|
||||
</div>
|
||||
|
||||
<div >
|
||||
<label >
|
||||
Street:<br/>
|
||||
<InputText class="rounded" @bind-Value="Address.Street"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => Address.Street"></ValidationMessage><br/>
|
||||
</div>
|
||||
|
||||
<div >
|
||||
<label >
|
||||
Building:<br/>
|
||||
<InputText class="rounded" @bind-Value="Address.Building"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => Address.Building"></ValidationMessage>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired] public AddressModel Address { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
@using VisaApiClient
|
||||
<div>
|
||||
<div >
|
||||
<label >
|
||||
Email:<br/>
|
||||
<InputText class="rounded" @bind-Value="AuthData.Email"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => AuthData.Email"></ValidationMessage><br/>
|
||||
</div>
|
||||
|
||||
<div >
|
||||
<label >
|
||||
Password:<br/>
|
||||
<InputText type="password" class="rounded" @bind-Value="AuthData.Password"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => AuthData.Password"></ValidationMessage>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired] public AuthData AuthData { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
@using VisaApiClient
|
||||
<div>
|
||||
<div >
|
||||
<label>
|
||||
First name@(Constants.RequiredFieldMarkup):<br/>
|
||||
<InputText DisplayName="First name" class="rounded" @bind-Value="Name.FirstName"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => Name.FirstName"></ValidationMessage>
|
||||
</div><br/>
|
||||
|
||||
<div >
|
||||
<label>
|
||||
Surname@(Constants.RequiredFieldMarkup):<br/>
|
||||
<InputText class="rounded" @bind-Value="Name.Surname"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => Name.Surname"></ValidationMessage>
|
||||
</div><br/>
|
||||
|
||||
<div >
|
||||
<label>
|
||||
Patronymic:<br/>
|
||||
<InputText class="rounded" @bind-Value="Name.Patronymic"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => Name.Patronymic"></ValidationMessage>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired] public NameModel Name { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
|
||||
@using VisaApiClient
|
||||
<div>
|
||||
<div >
|
||||
<label>
|
||||
Passport number:<br/>
|
||||
<InputText DisplayName="Passport number" class="rounded" @bind-Value="Passport.Number"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => Passport.Number"></ValidationMessage>
|
||||
</div><br/>
|
||||
|
||||
<div >
|
||||
<label>
|
||||
Issuer:<br/>
|
||||
<InputText class="rounded" @bind-Value="Passport.Issuer"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => Passport.Issuer"></ValidationMessage>
|
||||
</div><br/>
|
||||
|
||||
<div >
|
||||
<label>
|
||||
Issue date:<br/>
|
||||
<InputDate DisplayName="Issue date" class="rounded" @bind-Value="Passport.IssueDate" max="@formattedDate"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => Passport.IssueDate"></ValidationMessage>
|
||||
</div><br/>
|
||||
|
||||
<div >
|
||||
<label>
|
||||
Expiration date:<br/>
|
||||
<InputDate DisplayName="Expiration date" class="rounded" @bind-Value="Passport.ExpirationDate" min="@formattedDate"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => Passport.ExpirationDate"></ValidationMessage>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string formattedDate = null!;
|
||||
|
||||
[Parameter, EditorRequired] public PassportModel Passport { get; set; } = null!;
|
||||
|
||||
[Inject] IDateTimeProvider DateTimeProvider { get; set; } = null!;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Passport.IssueDate = DateTime.Now;
|
||||
Passport.ExpirationDate = DateTime.Now;
|
||||
formattedDate = DateTimeProvider.FormattedNow();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
@using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models
|
||||
<div>
|
||||
<div >
|
||||
<label >
|
||||
Name:<br/>
|
||||
<InputText class="rounded" @bind-Value="PlaceOfWork.Name"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => PlaceOfWork.Name"></ValidationMessage><br/>
|
||||
</div>
|
||||
|
||||
<div >
|
||||
<label >
|
||||
Phone number:<br/>
|
||||
<InputText DisplayName="Phone number" class="rounded" @bind-Value="PlaceOfWork.PhoneNum"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => PlaceOfWork.PhoneNum"></ValidationMessage>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired] public PlaceOfWorkModel PlaceOfWork { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
@typeparam TItem where TItem : class
|
||||
@using System.Linq.Expressions
|
||||
@using System.Reflection
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
|
||||
@typeparam TMember where TMember : struct, Enum
|
||||
|
||||
<InputSelect TValue="TMember" @bind-Value="selected">
|
||||
@foreach (var value in enumValues)
|
||||
{
|
||||
<option value="@value.Key">@value.Value</option>
|
||||
}
|
||||
</InputSelect><br/>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired] public TItem Model { get; set; } = default!;
|
||||
|
||||
[Parameter, EditorRequired] public Expression<Func<TItem, TMember>> EnumProperty { get; set; } = null!;
|
||||
|
||||
[Parameter] public Action? OnChanged { get; set; }
|
||||
|
||||
private Dictionary<TMember, string> enumValues = new();
|
||||
private PropertyInfo modelMemberInfo = null!;
|
||||
private TMember selected;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var modelMemberName = ((MemberExpression)EnumProperty.Body).Member.Name;
|
||||
modelMemberInfo = typeof(TItem).GetProperty(modelMemberName)!;
|
||||
|
||||
foreach (var value in Enum.GetValues<TMember>())
|
||||
{
|
||||
enumValues.Add(value, value.GetDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
var current = (TMember)modelMemberInfo.GetValue(Model)!;
|
||||
if (!current.Equals(selected))
|
||||
{
|
||||
OnValueChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnValueChanged()
|
||||
{
|
||||
modelMemberInfo.SetValue(Model, selected);
|
||||
OnChanged?.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
|
||||
@using VisaApiClient
|
||||
<div>
|
||||
<label>
|
||||
Issuer:<br/>
|
||||
<InputText DisplayName="Issuer of permission to destination Country" class="rounded"
|
||||
@bind-Value="PermissionToDestCountry.Issuer"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => PermissionToDestCountry.Issuer"></ValidationMessage><br/>
|
||||
|
||||
<label>
|
||||
Expiration date:<br/>
|
||||
<InputDate DisplayName="Expiration date of permission to destination Country" class="rounded"
|
||||
@bind-Value="PermissionToDestCountry.ExpirationDate"
|
||||
min="@formattedDate"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => PermissionToDestCountry.ExpirationDate"></ValidationMessage>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string formattedDate = null!;
|
||||
|
||||
[Parameter, EditorRequired] public PermissionToDestCountryModel PermissionToDestCountry { get; set; } = null!;
|
||||
|
||||
[Inject] IDateTimeProvider DateTimeProvider { get; set; } = null!;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
formattedDate = DateTimeProvider.FormattedNow();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
|
||||
@using VisaApiClient
|
||||
<div>
|
||||
<label>
|
||||
Number:<br/>
|
||||
<InputText DisplayName="Number of re-entry permit" class="rounded"
|
||||
@bind-Value="ReentryPermit.Number"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => ReentryPermit.Number"></ValidationMessage><br/>
|
||||
|
||||
<label>
|
||||
Expiration date:<br/>
|
||||
<InputDate DisplayName="Expiration date of re-entry permit" class="rounded"
|
||||
@bind-Value="ReentryPermit.ExpirationDate"
|
||||
min="@formattedDate"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => ReentryPermit.ExpirationDate"></ValidationMessage>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string formattedDate = null!;
|
||||
|
||||
[Parameter, EditorRequired] public ReentryPermitModel ReentryPermit { get; set; } = null!;
|
||||
|
||||
[Inject] IDateTimeProvider DateTimeProvider { get; set; } = null!;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
formattedDate = DateTimeProvider.FormattedNow();
|
||||
ReentryPermit.ExpirationDate = DateTimeProvider.Now();
|
||||
}
|
||||
|
||||
}
|
||||
34
BlazorWebAssemblyVisaApiClient/Components/Status.razor
Normal file
34
BlazorWebAssemblyVisaApiClient/Components/Status.razor
Normal file
@@ -0,0 +1,34 @@
|
||||
<p class="@statusClass">@((MarkupString)StatusText)</p>
|
||||
<CascadingValue Value="this">
|
||||
@ChildContent
|
||||
</CascadingValue>
|
||||
|
||||
@code {
|
||||
private string statusClass = string.Empty;
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
public string StatusText { get; private set; } = string.Empty;
|
||||
|
||||
public void SetMessage(string message)
|
||||
{
|
||||
statusClass = string.Empty;
|
||||
StatusText = message;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void SetError(string message)
|
||||
{
|
||||
statusClass = "validation-message";
|
||||
StatusText = message;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public void SetSuccess(string message)
|
||||
{
|
||||
statusClass = "text-success";
|
||||
StatusText = message;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user