J1: Admin/Styles/Edit #65:
- Création de StyleEditViewModel - Création de la vue edit - Integration du edit dans le controller
This commit is contained in:
@@ -94,6 +94,7 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
}
|
||||
|
||||
|
||||
|
||||
// GET: Administration/Styles/Delete/5
|
||||
public ActionResult Delete(int id)
|
||||
{
|
||||
@@ -130,5 +131,55 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
|
||||
// GET: Administration/Styles/Edit/5
|
||||
[HttpGet]
|
||||
public ActionResult Edit(int id)
|
||||
{
|
||||
// Recherche du style (simulation avec la liste _styles)
|
||||
var style = _styles.FirstOrDefault(s => s.IdStyle == id);
|
||||
|
||||
if (style == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
// Mapping vers le ViewModel
|
||||
var model = new StyleEditViewModel
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
// POST: Administration/Styles/Edit/5
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Edit(int id, StyleEditViewModel model)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return View(model);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// TODO : Mettre à jour en base de données ici
|
||||
// var styleDb = _context.Styles.Find(id);
|
||||
// styleDb.Libelle = model.Libelle;
|
||||
// _context.SaveChanges();
|
||||
|
||||
_logger.LogInformation("Style {Id} mis à jour : {Libelle}", id, model.Libelle);
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Erreur lors de la modification du style {Id}", id);
|
||||
ModelState.AddModelError("", "Une erreur est survenue lors de la modification.");
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// <copyright file="StyleDeleteViewModel.cs" company="Webzine">
|
||||
// Copyright (c) Webzine. Tout droit réservé.
|
||||
// </copyright>
|
||||
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Style
|
||||
{
|
||||
/// <summary>
|
||||
/// ViewModel pour la modification d'un style en administration.
|
||||
/// </summary>
|
||||
|
||||
public class StyleEditViewModel
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Obtient ou définit le libellé du style.
|
||||
/// </summary>
|
||||
|
||||
public int IdStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Obtient ou définit le libellé du style.
|
||||
/// </summary>
|
||||
|
||||
public string Libelle { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Style.StyleEditViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Editer un style";
|
||||
}
|
||||
|
||||
<div class="container mt-4">
|
||||
<h1 class="mb-3">Editer un style</h1>
|
||||
<hr />
|
||||
|
||||
<form asp-action="Edit" method="post" class="mt-4">
|
||||
|
||||
@* Champ caché pour l'ID *@
|
||||
<input type="hidden" asp-for="IdStyle" />
|
||||
|
||||
@* Conteneur Flex pour alignement horizontal (Label - Input - Bouton) *@
|
||||
<div class="d-flex align-items-center">
|
||||
|
||||
@* Label *@
|
||||
<div class="me-3">
|
||||
<label asp-for="Libelle" class="col-form-label fw-bold">
|
||||
Libellé<span class="text-danger">*</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@* Input *@
|
||||
<div class="me-3">
|
||||
<input asp-for="Libelle" class="form-control" style="width: 250px;" />
|
||||
</div>
|
||||
|
||||
@* Bouton *@
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary">Sauvegarder</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* Zone d'erreur spécifique au champ *@
|
||||
<div class="mt-2">
|
||||
<span asp-validation-for="Libelle" class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
<div class="mt-4">
|
||||
<a asp-action="Index" class="btn-link">Retour à l'administration des styles</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -4,22 +4,23 @@
|
||||
ViewData["Title"] = "Styles";
|
||||
}
|
||||
|
||||
<div class="justify-content-center m-5">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1>Gestion des Styles</h1>
|
||||
@* Lien vers la création (optionnel si vous n'avez pas encore fait l'action Create) *@
|
||||
<div class="container mt-4">
|
||||
|
||||
<h1 class="mb-3">Styles</h1>
|
||||
<hr />
|
||||
|
||||
<div class="mb-3">
|
||||
<a asp-action="Create" class="btn btn-primary">
|
||||
<i class="fas fa-plus"></i> Nouveau Style
|
||||
<i class="fas fa-plus"></i> Ajouter un nouvel style
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover table-bordered">
|
||||
<thead class="table-light">
|
||||
<table class="table table-striped table-hover table-bordered table-sm">
|
||||
<thead class="table-active">
|
||||
<tr>
|
||||
<th scope="col" style="width: 10%;">#</th>
|
||||
<th scope="col">Libellé</th>
|
||||
<th scope="col" class="text-center" style="width: 15%;">Actions</th>
|
||||
<th scope="col" class="p-2">Libellé</th>
|
||||
<th scope="col" class="text-center p-2" style="width: 100px;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -28,15 +29,14 @@
|
||||
@foreach (Webzine.Entity.Style style in Model.Styles)
|
||||
{
|
||||
<tr class="align-middle">
|
||||
<td>
|
||||
@style.IdStyle
|
||||
</td>
|
||||
<td>
|
||||
<td class="p-2">
|
||||
@style.Libelle
|
||||
</td>
|
||||
<td class="text-center">
|
||||
@* Bouton Supprimer (correspond à votre action Delete) *@
|
||||
<a asp-action="Delete" asp-route-id="@style.IdStyle" class="d-inline btn btn-link text-main" title="Supprimer">
|
||||
<td class="text-center p-2">
|
||||
<a asp-action="Edit" asp-route-id="@style.IdStyle" class="text-primary me-2" title="Éditer">
|
||||
<i class="fas fa-edit"></i>
|
||||
</a>
|
||||
<a asp-action="Delete" asp-route-id="@style.IdStyle" class="text-primary" title="Supprimer">
|
||||
<i class="fas fa-trash"></i>
|
||||
</a>
|
||||
</td>
|
||||
@@ -46,7 +46,7 @@
|
||||
else
|
||||
{
|
||||
<tr>
|
||||
<td colspan="3" class="text-center">Aucun style disponible.</td>
|
||||
<td colspan="2" class="text-center p-2">Aucun style disponible.</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user