Merge pull request 'feat/admin_artiste_crud_pages' (#78) from feat/admin_artiste_crud_pages into dev
Reviewed-on: http://10.4.0.131/DI1-P4-E1/Webzine/pulls/78
This commit is contained in:
@@ -12,53 +12,86 @@ public class ArtisteController : Controller
|
||||
{
|
||||
// Injection du logger via le constructeur
|
||||
private readonly ILogger<ArtisteController> _logger;
|
||||
private readonly List<Artiste> _artistes;
|
||||
|
||||
|
||||
public ArtisteController(ILogger<ArtisteController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
this._logger.LogDebug(1, "initialisation du ArtisteController d'administration");
|
||||
var factory = new DataFactory();
|
||||
|
||||
_artistes = factory.GenerateArtists(10);
|
||||
}
|
||||
/// <summary>
|
||||
/// Affiche la liste des artistes. Pour l'instant, les artistes sont générés à partir de noms prédéfinis via la méthode SeedArtisteByName de la classe ArtisteFactory.
|
||||
/// Chaque artiste est ensuite ajouté à une liste d'artistes qui est passée à la vue via un objet GroupeArtisteViewModel.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>Redirection.</returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
var nomsArtistes = new List<string> { "The Beatles", "Théa", "Thédora", "Ricchi E Poveri", "Bad Bunny", "horsegiirL" };
|
||||
List<Artiste> artistes = new List<Artiste>();
|
||||
|
||||
foreach (var nom in nomsArtistes)
|
||||
{
|
||||
Artiste artiste = ArtisteFactory.SeedArtisteByName(nom);
|
||||
artistes.Add(artiste);
|
||||
}
|
||||
var _artistes_ordre = _artistes.OrderBy(t => t.Nom).ToList();
|
||||
|
||||
_logger.LogInformation("Initialisation du contrôleur TitreController pour l'Administration.");
|
||||
|
||||
GroupeArtisteViewModel groupeArtisteModel = new GroupeArtisteViewModel
|
||||
{
|
||||
Artistes = artistes
|
||||
Artistes = _artistes_ordre
|
||||
};
|
||||
|
||||
return View(groupeArtisteModel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renvoie à la page modifier un artiste.
|
||||
/// Méthode vide pour le moment.
|
||||
/// Renvoie à la page pour créer un artiste.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult Edit()
|
||||
/// <returns>Redirection.</returns>
|
||||
public IActionResult Create()
|
||||
{
|
||||
return View();
|
||||
var model = new AdminArtisteForm
|
||||
{
|
||||
Id = 0,
|
||||
Nom = string.Empty,
|
||||
Biographie = string.Empty
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renvoie à la page modifier un artiste.
|
||||
/// </summary>
|
||||
/// <param name="id">L'identifiant de l'artiste à modifier. </param>
|
||||
/// <returns>Redirection.</returns>
|
||||
public IActionResult Edit(int id)
|
||||
{
|
||||
var artiste = _artistes.First(t => t.IdArtiste == id);
|
||||
|
||||
var model = new AdminArtisteForm
|
||||
{
|
||||
Id = artiste.IdArtiste,
|
||||
Nom = artiste.Nom,
|
||||
Biographie = artiste.Biographie
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renvoie à la page supprimer un artiste.
|
||||
/// Méthode vide pour le moment.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult Delete()
|
||||
/// <param name="id">L'identifiant de l'artiste à supprimer. </param>
|
||||
/// <returns>Redirection.></returns>
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
return View();
|
||||
var artiste = _artistes.First(t => t.IdArtiste == id);
|
||||
var model = new AdminArtisteForm
|
||||
{
|
||||
Id = id,
|
||||
Nom = artiste.Nom,
|
||||
Biographie = artiste.Biographie
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
@@ -9,21 +9,21 @@ using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
{
|
||||
[Area("Administration")]
|
||||
public class StylesController : Controller
|
||||
public class StyleController : Controller
|
||||
{
|
||||
private readonly ILogger<StylesController> _logger;
|
||||
private readonly ILogger<StyleController> _logger;
|
||||
private readonly List<Style> _styles;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise une nouvelle instance du <see cref="StylesController"/>.
|
||||
/// Initialise une nouvelle instance du <see cref="StyleController"/>.
|
||||
/// 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)
|
||||
public StyleController(ILogger<StyleController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
_logger.LogInformation("Initialisation du contrôleur StylesController.");
|
||||
_logger.LogInformation("Initialisation du contrôleur StyleController.");
|
||||
|
||||
var factory = new DataFactory();
|
||||
|
||||
@@ -24,7 +24,7 @@ public class TitreController : Controller
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
_logger.LogInformation("Initialisation du contrôleur TitreController.");
|
||||
_logger.LogInformation("Initialisation du contrôleur TitreController pour l'Administration.");
|
||||
|
||||
var factory = new DataFactory();
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Artiste
|
||||
{
|
||||
/// <summary>
|
||||
/// ViewModel pour la création et la modification d'un artiste dans l'administration.
|
||||
/// </summary>
|
||||
public class AdminArtisteForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Définit l'identifiant de l'artiste.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// Définit le nom de l'artiste.
|
||||
/// </summary>
|
||||
public string Nom { get; set; }
|
||||
/// <summary>
|
||||
/// Définit la biographie de l'artiste.
|
||||
/// </summary>
|
||||
public string Biographie { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.AdminArtisteForm
|
||||
|
||||
<h1>Créer un artiste</h1>
|
||||
|
||||
<hr />
|
||||
|
||||
<form asp-action="Create" method="post">
|
||||
|
||||
<partial name="_Form" />
|
||||
|
||||
</form>
|
||||
@@ -0,0 +1,32 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.AdminArtisteForm
|
||||
|
||||
<div class="container mt-4">
|
||||
|
||||
<h1 class="mb-3">Supprimer un artiste</h1>
|
||||
|
||||
<hr />
|
||||
|
||||
<p>
|
||||
Etes-vous sûr de vouloir supprimer l'artiste
|
||||
"@Model.Nom" ?
|
||||
</p>
|
||||
|
||||
<form asp-action="Delete" method="post">
|
||||
|
||||
<input type="hidden" asp-for="Id" />
|
||||
|
||||
<button type="submit" class="btn btn-danger">
|
||||
Supprimer
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
||||
|
||||
<a asp-action="Index">
|
||||
Retour à l'administration des artistes
|
||||
</a>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,13 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.AdminArtisteForm
|
||||
|
||||
<h1>Editer un artiste</h1>
|
||||
|
||||
<hr />
|
||||
|
||||
<form asp-action="Edit" method="post">
|
||||
|
||||
<input type="hidden" asp-for="Id"/>
|
||||
|
||||
<partial name="_Form" />
|
||||
|
||||
</form>
|
||||
@@ -8,39 +8,34 @@
|
||||
<div class="container mt-4">
|
||||
<h1 class="mb-4">Artiste</h1>
|
||||
<hr />
|
||||
<a asp-action="" class="btn btn-primary mb-3">
|
||||
<i class="fa fa-plus"></i> Ajouter un nouvel titre
|
||||
<a asp-action="Create" class="btn btn-primary mb-3">
|
||||
<i class="fa fa-plus"></i> Ajouter un nouvel artiste
|
||||
</a>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover table-bordered">
|
||||
<table class="table table-striped table-hover table-bordered table-sm">
|
||||
<thead class="table-active">
|
||||
<tr>
|
||||
<th scope="col">Nom de l'artiste</th>
|
||||
<th scope="col" class="text-center">Actions</th>
|
||||
<th scope="col" class="p-2">Nom</th>
|
||||
<th scope="col" class="text-center p-2" style="width: 100px;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@* On groupe les artistes par nom *@
|
||||
@{
|
||||
var artistes = Model.Artistes
|
||||
.OrderBy(t => t.Nom); // Trie les artistes par ordre alphabétique
|
||||
}
|
||||
|
||||
@foreach (var artiste in artistes)
|
||||
@foreach (var artiste in Model.Artistes)
|
||||
{
|
||||
<tr class="align-middle">
|
||||
<td class="col-10">
|
||||
<td class="p-2">
|
||||
@artiste.Nom
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<td class="text-center p-2">
|
||||
|
||||
<a asp-action="Edit" asp-route-id="@artiste.IdArtiste"
|
||||
class="btn btn-sm text-primary">
|
||||
<i class="fa fa-pen"></i>
|
||||
class="text-primary">
|
||||
<i class="fa fa-edit"></i>
|
||||
</a>
|
||||
|
||||
<a asp-action="Delete" asp-route-id="@artiste.IdArtiste"
|
||||
class="btn btn-sm text-primary">
|
||||
class="text-primary">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.AdminArtisteForm
|
||||
|
||||
<div class="container">
|
||||
<!-- ARTISTE -->
|
||||
<div class="row mb-3 align-items-center">
|
||||
<label class="col-md-3 col-form-label">Nom de l'artiste<span class="text-danger">*</span></label>
|
||||
<div class="col-md-9">
|
||||
<input asp-for="Nom" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- BIOGRAPHIE -->
|
||||
<div class="row mb-3 align-items-center">
|
||||
<label class="col-md-3 col-form-label">Biographie<span class="text-danger">*</span></label>
|
||||
<div class="col-md-9">
|
||||
<input asp-for="Biographie" class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- BOUTONS -->
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-9 offset-md-3">
|
||||
|
||||
<button type="submit" class="btn btn-primary me-2">
|
||||
Sauvegarder
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<a asp-action="Index"
|
||||
class="btn text-primary">
|
||||
Retour à l'administration des artistes
|
||||
</a>
|
||||
</div>
|
||||
@@ -5,18 +5,19 @@
|
||||
}
|
||||
|
||||
|
||||
<div class="justify-content-center m-5">
|
||||
<div class="container mt-4">
|
||||
<h1 class="mb-4">Commentaires</h1>
|
||||
<hr />
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover table-bordered">
|
||||
<thead class="table-light">
|
||||
<thead class="table-active">
|
||||
<tr>
|
||||
<th scope="col">Titre</th>
|
||||
<th scope="col">Auteur</th>
|
||||
<th scope="col">Commentaire</th>
|
||||
<th scope="col">Date de création</th>
|
||||
<th scope="col" class="text-center">Actions</th>
|
||||
<th scope="col" class="text-center p-2" style="width: 100px" ;>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
<h1 class="mb-3">Titres</h1>
|
||||
<hr />
|
||||
|
||||
<a asp-action="" class="btn btn-primary mb-3">
|
||||
<i class="fa fa-plus"></i> Ajouter un nouvel titre
|
||||
<a asp-action="Create" class="btn btn-primary mb-3">
|
||||
<i class="fa fa-plus"></i> Ajouter un nouveau titre
|
||||
</a>
|
||||
<div class="table-responsive">
|
||||
|
||||
<table class="table table-striped table-bordered align-middle">
|
||||
<thead class="table-light">
|
||||
<table class="table table-striped table-hover table-bordered">
|
||||
<thead class="table-active">
|
||||
<tr>
|
||||
<th>Artiste</th>
|
||||
<th>Titre</th>
|
||||
@@ -28,6 +29,7 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
@@ -43,12 +45,12 @@
|
||||
<td class="text-center action-column">
|
||||
|
||||
<a asp-action="Edit" asp-route-id="@item.Id"
|
||||
class="btn btn-sm btn-outline-primary">
|
||||
<i class="fa fa-pen"></i>
|
||||
class="btn btn-sm text-primary">
|
||||
<i class="fa fa-edit"></i>
|
||||
</a>
|
||||
|
||||
<a asp-action="Delete" asp-route-id="@item.Id"
|
||||
class="btn btn-sm btn-outline-danger">
|
||||
class="btn btn-sm text-primary">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
|
||||
@@ -57,5 +59,5 @@
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user