Reviewed-on: http://10.4.0.131/DI1-P4-E1/Webzine/pulls/62 Reviewed-by: j.vetu <josephine.vetu@diiage.org> Reviewed-by: Loic Masi <loic.masi@diiage.org>
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Webzine.Entity;
|
||||
using Webzine.Entity.Fixtures;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
{
|
||||
[Area("Administration")]
|
||||
public class StylesController : Controller
|
||||
{
|
||||
private readonly ILogger<StylesController> _logger;
|
||||
private readonly List<Style> _styles;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise une nouvelle instance du <see cref="StylesController"/>.
|
||||
/// Les données sont générées dynamiquement via <see cref="DataFactory"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecté.</param>
|
||||
public StylesController(ILogger<StylesController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
_logger.LogInformation("Initialisation du contrôleur StylesController.");
|
||||
|
||||
var factory = new DataFactory();
|
||||
|
||||
_styles = factory.GenerateStyles(10);
|
||||
|
||||
_logger.LogInformation("Données fictives générées avec succès.");
|
||||
}
|
||||
|
||||
// GET: Administration/Styles
|
||||
public ActionResult Index()
|
||||
{
|
||||
// Création de données "bouchon" (mock) pour tester l'affichage
|
||||
var listeStyles = new List<Style>
|
||||
{
|
||||
new Style
|
||||
{
|
||||
IdStyle = 1,
|
||||
Libelle = "Rock",
|
||||
},
|
||||
new Style
|
||||
{
|
||||
IdStyle = 2,
|
||||
Libelle = "Pop",
|
||||
},
|
||||
new Style
|
||||
{
|
||||
IdStyle = 3,
|
||||
Libelle = "Jazz",
|
||||
},
|
||||
};
|
||||
|
||||
// Initialisation du ViewModel
|
||||
var viewModel = new StyleViewModel
|
||||
{
|
||||
Styles = listeStyles,
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
|
||||
// GET: Administration/Styles/Delete/5
|
||||
public ActionResult Delete(int id)
|
||||
{
|
||||
var style = this._styles
|
||||
.FirstOrDefault(c => c.IdStyle == id);
|
||||
|
||||
if (style == null)
|
||||
{
|
||||
return this.NotFound();
|
||||
}
|
||||
|
||||
var vm = new StyleDeleteViewModel
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
// POST: Administration/Styles/Delete/5
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Delete(int id, StyleDeleteViewModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Log de l'erreur
|
||||
_logger.LogError(e, "Erreur lors de la suppression du style avec l'ID {StyleId}", id);
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// <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 suppression d'un style en administration.
|
||||
/// </summary>
|
||||
|
||||
public class StyleDeleteViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Obtient ou définit l'identifiant du style à supprimer.
|
||||
/// </summary>
|
||||
|
||||
public int IdStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Obtient ou définit le libellé du style.
|
||||
/// </summary>
|
||||
|
||||
public string Libelle { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// <copyright file="StyleViewModel.cs" company="Webzine">
|
||||
// Copyright (c) Webzine. Tout droit réservé.
|
||||
// </copyright>
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Style
|
||||
{
|
||||
/// <summary>
|
||||
/// ViewModel pour afficher la liste des commentaires en administration.
|
||||
/// </summary>
|
||||
public class StyleViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Obtient ou définit la liste des commentaires.
|
||||
/// </summary>
|
||||
public IEnumerable<Entity.Style> Styles { get; set; } = new List<Entity.Style>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Style.StyleDeleteViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Supprimer un style";
|
||||
}
|
||||
|
||||
<div class="container mt-4">
|
||||
|
||||
<h1 class="mb-3">Supprimer un style</h1>
|
||||
<hr />
|
||||
|
||||
<p class="mb-4">
|
||||
Êtes-vous sûr de vouloir supprimer le style suivant ?
|
||||
</p>
|
||||
|
||||
<div class="mb-4">
|
||||
@* On affiche le Libellé en gros *@
|
||||
<h4>@Model.Libelle</h4>
|
||||
|
||||
@* On affiche l'ID discrètement en dessous *@
|
||||
<div class="text-muted">
|
||||
Identifiant technique : @Model.IdStyle
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form asp-action="Delete" method="post">
|
||||
@* Champ caché indispensable pour transmettre l'ID au contrôleur en POST *@
|
||||
<input type="hidden" asp-for="IdStyle" />
|
||||
|
||||
<button type="submit" class="btn btn-danger">
|
||||
Supprimer
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<a asp-action="Index"
|
||||
class="btn-link">
|
||||
Retour à l'administration des styles
|
||||
</a>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,55 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Style.StyleViewModel
|
||||
|
||||
@{
|
||||
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) *@
|
||||
<a asp-action="Create" class="btn btn-primary">
|
||||
<i class="fas fa-plus"></i> Nouveau Style
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover table-bordered">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th scope="col" style="width: 10%;">#</th>
|
||||
<th scope="col">Libellé</th>
|
||||
<th scope="col" class="text-center" style="width: 15%;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@if (Model.Styles != null && Model.Styles.Any())
|
||||
{
|
||||
@foreach (Webzine.Entity.Style style in Model.Styles)
|
||||
{
|
||||
<tr class="align-middle">
|
||||
<td>
|
||||
@style.IdStyle
|
||||
</td>
|
||||
<td>
|
||||
@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">
|
||||
<i class="fas fa-trash"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<tr>
|
||||
<td colspan="3" class="text-center">Aucun style disponible.</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user