This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Webzine.Entity;
|
||||
using Webzine.Entity.Fixtures;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels;
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
[Area("Administration")]
|
||||
public class DashboardController : Controller
|
||||
{
|
||||
private readonly ILogger<DashboardController> _logger;
|
||||
private readonly List<Titre> _titres;
|
||||
private readonly List<Style> _styles;
|
||||
private readonly List<Artiste> _artistes;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise une nouvelle instance du <see cref="DashboardController"/>.
|
||||
/// Les données sont générées dynamiquement via <see cref="DataFactory"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecté.</param>
|
||||
public DashboardController(ILogger<DashboardController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
_logger.LogInformation("Initialisation du contrôleur TitreController.");
|
||||
|
||||
var factory = new DataFactory();
|
||||
|
||||
_artistes = factory.GenerateArtists(10);
|
||||
_styles = factory.GenerateStyles(10);
|
||||
_titres = factory.GenerateTitres(30, _artistes, _styles);
|
||||
|
||||
factory.GenerateCommentaires(50, _titres);
|
||||
|
||||
_logger.LogInformation("Données fictives générées avec succès.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche le tableau de bord de l'administration.
|
||||
/// </summary>
|
||||
/// <returns>La vue Index du tableau de bord.</returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
var mostChronicledArtist = _titres
|
||||
.GroupBy(t => t.Artiste)
|
||||
.OrderByDescending(g => g.Count())
|
||||
.FirstOrDefault();
|
||||
|
||||
var topArtistAlbums = _titres
|
||||
.GroupBy(t => t.Artiste)
|
||||
.OrderByDescending(g => g.Select(t => t.Album).Distinct().Count())
|
||||
.FirstOrDefault();
|
||||
|
||||
var mostPlayedTrack = _titres
|
||||
.OrderByDescending(t => t.NbLectures)
|
||||
.FirstOrDefault();
|
||||
|
||||
var model = new DashboardViewModel
|
||||
{
|
||||
ArtistCount = _artistes.Count,
|
||||
|
||||
MostChronicledArtistName = mostChronicledArtist?.Key.Nom,
|
||||
|
||||
TopArtistAlbumsName = topArtistAlbums?.Key.Nom,
|
||||
|
||||
BiographyCount = _artistes.Count(a => !string.IsNullOrEmpty(a.Biographie)),
|
||||
|
||||
MostPlayedTrackId = mostPlayedTrack?.IdTitre ?? 0,
|
||||
MostPlayedTrack = mostPlayedTrack?.Libelle,
|
||||
|
||||
TrackCount = _titres.Count,
|
||||
|
||||
GenreCount = _styles.Count,
|
||||
|
||||
TotalPlays = _titres.Sum(t => t.NbLectures),
|
||||
|
||||
TotalLikes = _titres.Sum(t => t.NbLikes)
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user