PersonEditPage finished
This commit is contained in:
@@ -24,6 +24,9 @@ public class GenderResponse : Gender, IQueryOrderable<GenderResponse>
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
[JsonConstructor]
|
||||
public GenderResponse() { }
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public GenderResponse(Database.Model.Common.Gender gender)
|
||||
{
|
||||
|
||||
@@ -40,6 +40,9 @@ public class PersonResponse : Person, IQueryOrderable<PersonResponse>
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
[JsonConstructor]
|
||||
public PersonResponse() { }
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public PersonResponse(Database.Model.Person.Person person)
|
||||
{
|
||||
|
||||
@@ -45,6 +45,27 @@
|
||||
</InputSelect>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col align-self-center">
|
||||
@if (!string.IsNullOrWhiteSpace(_error))
|
||||
{
|
||||
<span class="text-danger">@(_error)</span>
|
||||
}
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button type="submit" class="btn btn-secondary" disabled="@(_saving)" @onclick="@(Save)">
|
||||
@if (!_saving)
|
||||
{
|
||||
<span>Save</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
|
||||
<span>Saving...</span>
|
||||
}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</EditForm>
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using WatchIt.Common.Model.Genders;
|
||||
using WatchIt.Common.Model.Persons;
|
||||
using WatchIt.Website.Services.WebAPI.Genders;
|
||||
using WatchIt.Website.Services.WebAPI.Persons;
|
||||
|
||||
namespace WatchIt.Website.Components.PersonEditPage;
|
||||
@@ -9,7 +10,9 @@ public partial class PersonEditFormComponent : ComponentBase
|
||||
{
|
||||
#region SERVICES
|
||||
|
||||
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
|
||||
[Inject] private IPersonsWebAPIService PersonsWebAPIService { get; set; } = default!;
|
||||
[Inject] private IGendersWebAPIService GendersWebAPIService { get; set; } = default!;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -27,6 +30,8 @@ public partial class PersonEditFormComponent : ComponentBase
|
||||
#region FIELDS
|
||||
|
||||
private bool _loaded;
|
||||
private bool _saving;
|
||||
private string? _error;
|
||||
|
||||
private IEnumerable<GenderResponse> _genders = [];
|
||||
|
||||
@@ -47,7 +52,7 @@ public partial class PersonEditFormComponent : ComponentBase
|
||||
// STEP 0
|
||||
endTasks.AddRange(
|
||||
[
|
||||
// TODO: Add gender fetch
|
||||
GendersWebAPIService.GetAllGenders(successAction: data => _genders = data)
|
||||
]);
|
||||
if (Id.HasValue)
|
||||
{
|
||||
@@ -65,5 +70,41 @@ public partial class PersonEditFormComponent : ComponentBase
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Save()
|
||||
{
|
||||
void PutSuccess()
|
||||
{
|
||||
_error = null;
|
||||
_saving = false;
|
||||
}
|
||||
|
||||
void PostSuccess(PersonResponse data)
|
||||
{
|
||||
NavigationManager.NavigateTo($"person/{data.Id}/edit");
|
||||
}
|
||||
|
||||
void BadRequest(IDictionary<string, string[]> errors)
|
||||
{
|
||||
_error = errors.SelectMany(x => x.Value).FirstOrDefault() ?? "Unknown error";
|
||||
_saving = false;
|
||||
}
|
||||
|
||||
void AuthError()
|
||||
{
|
||||
_error = "Authentication error";
|
||||
_saving = false;
|
||||
}
|
||||
|
||||
_saving = true;
|
||||
if (Id.HasValue)
|
||||
{
|
||||
await PersonsWebAPIService.PutPerson(Id.Value, _person, PutSuccess, BadRequest, AuthError, AuthError);
|
||||
}
|
||||
else
|
||||
{
|
||||
await PersonsWebAPIService.PostPerson(_person, PostSuccess, BadRequest, AuthError, AuthError);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -7,12 +7,17 @@
|
||||
|
||||
|
||||
<PageTitle>
|
||||
@("WatchIt - ")
|
||||
@switch (Type)
|
||||
{
|
||||
case "movies": @("Movies"); break;
|
||||
case "series": @("Series"); break;
|
||||
case "movies":
|
||||
@("Movies");
|
||||
break;
|
||||
case "series":
|
||||
@("Series");
|
||||
break;
|
||||
}
|
||||
@(" database - WatchIt")
|
||||
@(" database")
|
||||
</PageTitle>
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,35 @@
|
||||
@page "/person/new"
|
||||
|
||||
|
||||
|
||||
<PageTitle>
|
||||
WatchIt -
|
||||
@if (_loaded)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_error) && _user?.IsAdmin == true)
|
||||
{
|
||||
if (_person is not null)
|
||||
{
|
||||
@("Edit \"")@(_person.Name)@("\"")
|
||||
}
|
||||
else
|
||||
{
|
||||
@("Create new person")
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@("Error")
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@("Loading")
|
||||
}
|
||||
</PageTitle>
|
||||
|
||||
|
||||
|
||||
@if (_loaded)
|
||||
{
|
||||
if (_user?.IsAdmin == true)
|
||||
|
||||
@@ -9,6 +9,7 @@ using WatchIt.Website.Services.Utility.Authentication;
|
||||
using WatchIt.Website.Services.Utility.Configuration;
|
||||
using WatchIt.Website.Services.Utility.Tokens;
|
||||
using WatchIt.Website.Services.WebAPI.Accounts;
|
||||
using WatchIt.Website.Services.WebAPI.Genders;
|
||||
using WatchIt.Website.Services.WebAPI.Media;
|
||||
using WatchIt.Website.Services.WebAPI.Movies;
|
||||
using WatchIt.Website.Services.WebAPI.Persons;
|
||||
@@ -72,6 +73,7 @@ public static class Program
|
||||
|
||||
// WebAPI
|
||||
builder.Services.AddScoped<IAccountsWebAPIService, AccountsWebAPIService>();
|
||||
builder.Services.AddSingleton<IGendersWebAPIService, GendersWebAPIService>();
|
||||
builder.Services.AddSingleton<IMediaWebAPIService, MediaWebAPIService>();
|
||||
builder.Services.AddSingleton<IMoviesWebAPIService, MoviesWebAPIService>();
|
||||
builder.Services.AddSingleton<ISeriesWebAPIService, SeriesWebAPIService>();
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.Utility\WatchIt.Website.Services.Utility.Configuration\WatchIt.Website.Services.Utility.Configuration.csproj" />
|
||||
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.Utility\WatchIt.Website.Services.Utility.Tokens\WatchIt.Website.Services.Utility.Tokens.csproj" />
|
||||
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Accounts\WatchIt.Website.Services.WebAPI.Accounts.csproj" />
|
||||
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Genders\WatchIt.Website.Services.WebAPI.Genders.csproj" />
|
||||
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Media\WatchIt.Website.Services.WebAPI.Media.csproj" />
|
||||
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Movies\WatchIt.Website.Services.WebAPI.Movies.csproj" />
|
||||
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Persons\WatchIt.Website.Services.WebAPI.Persons.csproj" />
|
||||
|
||||
Reference in New Issue
Block a user