finishing edit form
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -7,30 +7,41 @@
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
<PageHeader Name="Point d'intéret" NameType="Modifier" LinkType="LinkType.Details" Link="@($"/city/{CityId}/pointofinterest/{PointOfInterestId}")"></PageHeader>
|
<PageHeader Name="Point d'intéret" NameType="Modifier" LinkType="LinkType.Details" Link="@($"/city/{CityId}/pointofinterest/{PointOfInterestId}")"></PageHeader>
|
||||||
<Card HeaderTitle="Modifier le point d'intéret">
|
@if (ReturnData)
|
||||||
<EditForm Model="PointOfInterest" OnValidSubmit="HandleValidSubmit" OnInvalidSubmit="HandleInvalidSubmit">
|
{
|
||||||
<div>
|
<Card HeaderTitle="Modifier le point d'intéret">
|
||||||
<label for="PointOfInterestName" class="form-label">Nom</label>
|
<div class="alert @StatusClass">@ReturnMessage</div>
|
||||||
|
</Card>
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
<Card HeaderTitle="Modifier le point d'intéret">
|
||||||
|
<EditForm Model="PointOfInterest" OnValidSubmit="HandleValidSubmit" OnInvalidSubmit="HandleInvalidSubmit">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="PointOfInterestName" class="form-label">Nom</label>
|
||||||
|
|
||||||
<div class="input-icon">
|
<div class="input-icon">
|
||||||
<span class="input-icon-addon">
|
<span class="input-icon-addon">
|
||||||
<i class="fa-solid fa-location-dot"></i>
|
<i class="fa-solid fa-location-dot"></i>
|
||||||
</span>
|
</span>
|
||||||
<InputText id="PointOfInterestName" @bind-Value="PointOfInterest.Name" class="form-control"></InputText>
|
<InputText id="PointOfInterestName" @bind-Value="PointOfInterest.Name" class="form-control"></InputText>
|
||||||
<ValidationMessage class="offset-md-3 col-md-8 text-danger" For="@(() => PointOfInterest.Name)" />
|
<ValidationMessage class="offset-md-3 col-md-8 text-danger" For="@(() => PointOfInterest.Name)" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="mb-3">
|
||||||
<div>
|
<label for="PointOfInterestDescription" class="form-label">Description</label>
|
||||||
<label for="PointOfInterestDescription" class="form-label">Description</label>
|
<div class="input-icon">
|
||||||
<div class="input-icon">
|
<span class="input-icon-addon">
|
||||||
<span class="input-icon-addon">
|
<i class="fa-solid fa-align-left"></i>
|
||||||
<i class="fa-solid fa-align-left"></i>
|
</span>
|
||||||
</span>
|
<InputText id="PointOfInterestDescription" @bind-Value="PointOfInterest.Description" class="form-control"></InputText>
|
||||||
<InputText id="PointOfInterestDescription" @bind-Value="PointOfInterest.Description" class="form-control"></InputText>
|
<ValidationMessage class="offset-md-3 col-md-8 text-danger" For="@(() => PointOfInterest.Description)" />
|
||||||
<ValidationMessage class="offset-md-3 col-md-8 text-danger" For="@(() => PointOfInterest.Description)" />
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="container d-flex mb-3 justify-content-end">
|
||||||
</EditForm>
|
<a class="btn btn-danger" href="@($"/city/{CityId}/pointofinterest/{PointOfInterestId}")">Annuler</a>
|
||||||
</Card>
|
<button type="submit" class="btn btn-success ms-1">Mettre à jour</button>
|
||||||
|
</div>
|
||||||
|
</EditForm>
|
||||||
|
</Card>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,10 @@ namespace CityInfo.WEB.Pages
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public int PointOfInterestId { get; set; }
|
public int PointOfInterestId { get; set; }
|
||||||
public PointOfInterest? PointOfInterest { get; set; }
|
public PointOfInterest? PointOfInterest { get; set; }
|
||||||
|
|
||||||
|
public bool ReturnData { get; set; } = false;
|
||||||
|
public string StatusClass { get; set; } = string.Empty;
|
||||||
|
public string ReturnMessage { get; set; } = string.Empty;
|
||||||
protected async override Task OnInitializedAsync()
|
protected async override Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
PointOfInterest = await PointOfInterestDataService.GetPointOfInterest(CityId, PointOfInterestId);
|
PointOfInterest = await PointOfInterestDataService.GetPointOfInterest(CityId, PointOfInterestId);
|
||||||
@@ -28,10 +32,33 @@ namespace CityInfo.WEB.Pages
|
|||||||
}
|
}
|
||||||
private async Task HandleValidSubmit()
|
private async Task HandleValidSubmit()
|
||||||
{
|
{
|
||||||
|
if(PointOfInterest != null)
|
||||||
|
{
|
||||||
|
var isAdded = await PointOfInterestDataService.UpdatePointOfInterest(CityId, PointOfInterest);
|
||||||
|
if (isAdded)
|
||||||
|
{
|
||||||
|
ReturnData = true;
|
||||||
|
ReturnMessage = "Le point d'intérer à été mis à jour.";
|
||||||
|
StatusClass = "alert-success";
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
ReturnData = true;
|
||||||
|
ReturnMessage = "Une erreur est survenue lors de la mise à jour du point d'intéret.";
|
||||||
|
StatusClass = "alert-danger";
|
||||||
|
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
ReturnData = true;
|
||||||
|
ReturnMessage = "Une erreur est arrivée avec les données entrées";
|
||||||
|
StatusClass = "alert-danger";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private async Task HandleInvalidSubmit()
|
private async Task HandleInvalidSubmit()
|
||||||
{
|
{
|
||||||
|
ReturnData = true;
|
||||||
|
ReturnMessage = "Les données entrées sont incorrectes.";
|
||||||
|
StatusClass = "alert-danger";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,9 +66,18 @@ namespace CityInfo.WEB.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> UpdatePointOfInterest(int cityId, PointOfInterest pointOfInterest)
|
public async Task<bool> UpdatePointOfInterest(int cityId, PointOfInterest pointOfInterest)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
try
|
||||||
|
{
|
||||||
|
var response = await _httpClient.PutAsJsonAsync($"/api/cities/{cityId}/pointsofinterest/{pointOfInterest.Id}", pointOfInterest);
|
||||||
|
return response.IsSuccessStatusCode;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, $"Erreur lors de la mise à jour du point d'intéret {pointOfInterest.Id}", pointOfInterest.Id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user