#26 Page artiste admin. Controlleur, viewmodel et vue ok
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using Webzine.Entity;
|
||||||
|
using Webzine.Entity.Fixtures;
|
||||||
|
using Webzine.WebApplication.Areas.Administration.ViewModels.Artiste;
|
||||||
|
using Webzine.WebApplication.Areas.Administration.ViewModels.Titre;
|
||||||
|
|
||||||
|
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||||
|
|
||||||
|
[Area("Administration")]
|
||||||
|
public class ArtisteController : Controller
|
||||||
|
{
|
||||||
|
// Injection du logger via le constructeur
|
||||||
|
private readonly ILogger<ArtisteController> _logger;
|
||||||
|
|
||||||
|
public ArtisteController(ILogger<ArtisteController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
this._logger.LogDebug(1, "initialisation du ArtisteController d'administration");
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupeArtisteViewModel groupeArtisteModel = new GroupeArtisteViewModel
|
||||||
|
{
|
||||||
|
Artistes = artistes
|
||||||
|
};
|
||||||
|
|
||||||
|
return View(groupeArtisteModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult Edit()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult Delete()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Artiste
|
||||||
|
{
|
||||||
|
using Webzine.Entity;
|
||||||
|
public class GroupeArtisteViewModel
|
||||||
|
{
|
||||||
|
public IEnumerable<Artiste> Artistes { get; set; } = new List<Artiste>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.GroupeArtisteViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Artiste";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
<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>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover table-bordered">
|
||||||
|
<thead class="table-active">
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Nom de l'artiste</th>
|
||||||
|
<th scope="col" class="text-center">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)
|
||||||
|
{
|
||||||
|
<tr class="align-middle">
|
||||||
|
<td class="col-10">
|
||||||
|
@artiste.Nom
|
||||||
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
|
||||||
|
<a asp-action="Edit" asp-route-id="@artiste.IdArtiste"
|
||||||
|
class="btn btn-sm btn-outline-primary">
|
||||||
|
<i class="fa fa-pen"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a asp-action="Delete" asp-route-id="@artiste.IdArtiste"
|
||||||
|
class="btn btn-sm btn-outline-danger">
|
||||||
|
<i class="fa fa-trash"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
20
Webzine.WebApplication/ViewModels/Artiste/ArtisteModel.cs
Normal file
20
Webzine.WebApplication/ViewModels/Artiste/ArtisteModel.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using Webzine.Entity;
|
||||||
|
|
||||||
|
namespace Webzine.WebApplication.ViewModels.Artiste
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ViewModel pour afficher les détails d'un artiste, incluant les informations de l'artiste et la liste de ses titres.
|
||||||
|
/// </summary>
|
||||||
|
public class ArtisteModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Artiste dont on affiche les détails.
|
||||||
|
/// </summary>
|
||||||
|
public Artiste Artiste { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Liste des titres de l'artiste.
|
||||||
|
/// </summary>
|
||||||
|
public List<Entity.Titre> Titres { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user