Merge branch 'dev' into j3/feat/business-logic/titre-admin
# Conflicts: # Webzine.Business/Webzine.Business.csproj # Webzine.WebApplication/Program.cs
This commit is contained in:
@@ -50,14 +50,37 @@ public class ArtisteController : Controller
|
||||
/// <returns>Redirection.</returns>
|
||||
public IActionResult Create()
|
||||
{
|
||||
var model = new AdminArtisteForm
|
||||
return this.View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formulaire de création d'un artiste.
|
||||
/// </summary>
|
||||
/// <param name="model">Paramètre nécessaire pour la création d'un artiste.</param>
|
||||
/// <returns>Redirection sur la page Index.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Create(ArtisteCreateViewModel model)
|
||||
{
|
||||
// vérifier si les données sont corrects.
|
||||
if (!this.ModelState.IsValid)
|
||||
{
|
||||
Id = 0,
|
||||
Nom = string.Empty,
|
||||
Biographie = string.Empty,
|
||||
// Passer model en paramètre afin que
|
||||
// l'utilisateur conserve sa saissie.
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
// Créer un objet Artiste avecc les paramètres.
|
||||
var artiste = new Artiste
|
||||
{
|
||||
Nom = model.Nom,
|
||||
Biographie = model.Biographie,
|
||||
};
|
||||
|
||||
return this.View(model);
|
||||
// Persister les données.
|
||||
this.artisteRepository.Add(artiste);
|
||||
|
||||
// Renvoyer sur la page Index.
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -69,14 +92,37 @@ public class ArtisteController : Controller
|
||||
{
|
||||
var artiste = this.artisteRepository.Find(id);
|
||||
|
||||
var model = new AdminArtisteForm
|
||||
if (artiste == null)
|
||||
{
|
||||
Id = artiste.IdArtiste,
|
||||
Nom = artiste.Nom,
|
||||
Biographie = artiste.Biographie,
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
return this.View(artiste);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Traitement du formulaire de modification d'un artiste.
|
||||
/// </summary>
|
||||
/// <param name="model">Paramètre d'un artiste.</param>
|
||||
/// <returns>Redirection sur Index.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Edit(ArtisteEditViewModel model)
|
||||
{
|
||||
var artiste = new Artiste
|
||||
{
|
||||
IdArtiste = model.Id,
|
||||
Nom = model.Nom,
|
||||
Biographie = model.Biographie,
|
||||
};
|
||||
|
||||
return this.View(model);
|
||||
if (!this.ModelState.IsValid)
|
||||
{
|
||||
return this.View(artiste);
|
||||
}
|
||||
|
||||
this.artisteRepository.Update(artiste);
|
||||
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,6 +133,12 @@ public class ArtisteController : Controller
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
var artiste = this.artisteRepository.Find(id);
|
||||
|
||||
if (artiste == null)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
var model = new AdminArtisteForm
|
||||
{
|
||||
Id = id,
|
||||
|
||||
@@ -53,6 +53,11 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
{
|
||||
var commentaire = this.commentaireRepository.Find(id);
|
||||
|
||||
if (commentaire == null)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
var model = new CommentaireDeleteViewModel
|
||||
{
|
||||
IdCommentaire = commentaire.IdCommentaire,
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
using Webzine.Business.Contracts;
|
||||
using Webzine.Business.Contracts.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels;
|
||||
|
||||
[Area("Administration")]
|
||||
public class DashboardController : Controller
|
||||
{
|
||||
private readonly ILogger<DashboardController> logger;
|
||||
private readonly IStyleRepository styleRepository;
|
||||
private readonly IArtisteRepository artisteRepository;
|
||||
private readonly ITitreRepository titreRepository;
|
||||
private readonly IDashboardService dashboardService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DashboardController"/> class.
|
||||
/// Initialise une nouvelle instance de la classe <see cref="DashboardController"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecté.</param>
|
||||
/// <param name="styleRepository">Repository des styles injecté.</param>
|
||||
public DashboardController(ILogger<DashboardController> logger, IStyleRepository styleRepository, IArtisteRepository artisteRepository, ITitreRepository titreRepository)
|
||||
/// <param name="dashboardService">Service de calcul des statistiques du tableau de bord.</param>
|
||||
public DashboardController(ILogger<DashboardController> logger, IDashboardService dashboardService)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.styleRepository = styleRepository;
|
||||
this.artisteRepository = artisteRepository;
|
||||
this.titreRepository = titreRepository;
|
||||
this.dashboardService = dashboardService;
|
||||
|
||||
this.logger.LogInformation("Initialisation du contrôleur TitreController.");
|
||||
}
|
||||
@@ -35,42 +31,8 @@ public class DashboardController : Controller
|
||||
/// <returns>La vue Index du tableau de bord.</returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
var artisteLePlusChronique = this.titreRepository.FindAll()
|
||||
.GroupBy(t => t.Artiste)
|
||||
.OrderByDescending(g => g.Count())
|
||||
.First();
|
||||
DashboardDTO data = dashboardService.GetDashboardData();
|
||||
|
||||
var albumLePlusChronique = this.titreRepository.FindAll()
|
||||
.GroupBy(t => t.Artiste)
|
||||
.OrderByDescending(g => g.Select(t => t.Album).Distinct().Count())
|
||||
.First();
|
||||
|
||||
var musiqueLaPlusJouee = this.titreRepository.FindAll()
|
||||
.OrderByDescending(t => t.NbLectures)
|
||||
.First();
|
||||
|
||||
var model = new DashboardViewModel
|
||||
{
|
||||
NombreArtistes = this.artisteRepository.FindAll().Count(),
|
||||
|
||||
ArtisteLePlusChronique = artisteLePlusChronique.Key.Nom,
|
||||
|
||||
AlbumLePlusChronique = albumLePlusChronique.Key.Nom,
|
||||
|
||||
NombreBiographies = this.artisteRepository.FindAll().Count(a => !string.IsNullOrEmpty(a.Biographie)),
|
||||
|
||||
IdMusiqueLaPlusJouee = musiqueLaPlusJouee.IdTitre,
|
||||
MusiqueLaPlusJouee = musiqueLaPlusJouee.Libelle,
|
||||
|
||||
NombreTitres = this.titreRepository.Count(),
|
||||
|
||||
NombreGenres = this.styleRepository.FindAll().Count(),
|
||||
|
||||
NombreLectures = this.titreRepository.FindAll().Sum(t => t.NbLectures),
|
||||
|
||||
NombreLikes = this.titreRepository.FindAll().Sum(t => t.NbLikes),
|
||||
};
|
||||
|
||||
return this.View(model);
|
||||
return this.View(data);
|
||||
}
|
||||
}
|
||||
@@ -1,109 +1,170 @@
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
{
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Entity;
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
|
||||
|
||||
/// <summary>
|
||||
/// Controleur pour la gestion des styles dans l'administration du webzine.
|
||||
/// </summary>
|
||||
[Area("Administration")]
|
||||
public class StyleController : Controller
|
||||
{
|
||||
private readonly ILogger<StyleController> logger;
|
||||
private readonly IStyleRepository styleRepository;
|
||||
|
||||
/// <summary>
|
||||
/// Contrôleur pour la gestion des styles dans l'administration du webzine.
|
||||
/// Initializes a new instance of the <see cref="StyleController"/> class.
|
||||
/// </summary>
|
||||
[Area("Administration")]
|
||||
public class StyleController : Controller
|
||||
/// <param name="logger">Service de journalisation injecte.</param>
|
||||
/// <param name="styleRepository">Repository des styles injecte.</param>
|
||||
public StyleController(
|
||||
ILogger<StyleController> logger,
|
||||
IStyleRepository styleRepository)
|
||||
{
|
||||
private readonly ILogger<StyleController> logger;
|
||||
private readonly IStyleRepository styleRepository;
|
||||
this.logger = logger;
|
||||
this.styleRepository = styleRepository;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StyleController"/> class.
|
||||
/// Initialise une nouvelle instance de la classe <see cref="StyleController"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecté.</param>
|
||||
/// <param name="styles">Repository des styles injecté.</param>
|
||||
public StyleController(
|
||||
ILogger<StyleController> logger,
|
||||
IStyleRepository styleRepository)
|
||||
this.logger.LogInformation("Initialisation du controleur StyleController.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la liste des styles dans la vue Index.
|
||||
/// </summary>
|
||||
/// <returns>La vue Index avec la liste des styles.</returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
IEnumerable<Style> listeStyles = this.styleRepository.FindAll().Take(10);
|
||||
|
||||
return this.View(listeStyles);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue de creation d'un nouveau style.
|
||||
/// </summary>
|
||||
/// <returns>La vue Create pour ajouter un nouveau style.</returns>
|
||||
public IActionResult Create()
|
||||
{
|
||||
var model = new StyleCreateViewModel
|
||||
{
|
||||
this.logger = logger;
|
||||
Libelle = string.Empty,
|
||||
};
|
||||
|
||||
this.logger.LogInformation("Initialisation du contrôleur StyleController.");
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
this.styleRepository = styleRepository;
|
||||
/// <summary>
|
||||
/// Cree un nouveau style.
|
||||
/// </summary>
|
||||
/// <param name="model">Nouveau style.</param>
|
||||
/// <returns>IActionResult.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Create(StyleCreateViewModel model)
|
||||
{
|
||||
if (!this.ModelState.IsValid)
|
||||
{
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la liste des styles dans la vue Index.
|
||||
/// </summary>
|
||||
/// <returns>La vue Index avec le ViewModel contenant la liste des styles.</returns>
|
||||
public IActionResult Index()
|
||||
var style = new Style
|
||||
{
|
||||
var listeStyles = this.styleRepository.FindAll().Take(10);
|
||||
Libelle = model.Libelle,
|
||||
};
|
||||
|
||||
return this.View(listeStyles);
|
||||
}
|
||||
this.styleRepository.Add(style);
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue de création d'un nouveau style.
|
||||
/// </summary>
|
||||
/// <returns>La vue Create pour ajouter un nouveau style.</returns>
|
||||
public IActionResult Create()
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue de confirmation de suppression d'un style.
|
||||
/// </summary>
|
||||
/// <param name="id">L'identifiant du style a supprimer.</param>
|
||||
/// <returns>La vue de confirmation ou une redirection vers l'index si le style n'existe pas.</returns>
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
var style = this.styleRepository.Find(id);
|
||||
|
||||
if (style == null || style.IdStyle == 0)
|
||||
{
|
||||
return this.View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue de confirmation de suppression d'un style, en récupérant les détails du style à supprimer à partir de l'identifiant fourni.
|
||||
/// </summary>
|
||||
/// <param name="id">L'identifiant du style à supprimer.</param>
|
||||
/// <returns>La vue de confirmation de suppression avec le ViewModel contenant les détails du style à supprimer, ou une redirection vers l'index si le style n'existe pas.</returns>
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
var style = this.styleRepository.Find(id);
|
||||
|
||||
var vm = new StyleDeleteViewModel
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
|
||||
return this.View(vm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Méthode POST pour supprimer un style.
|
||||
/// </summary>
|
||||
/// <param name="model">Le style à supprimer.</param>
|
||||
/// <returns>Redirige vers la page d'index d'admin style.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Delete(StyleEditViewModel model)
|
||||
{
|
||||
var style = this.styleRepository.Find(model.IdStyle);
|
||||
|
||||
if (style != null)
|
||||
{
|
||||
this.styleRepository.Delete(style);
|
||||
}
|
||||
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue d'édition d'un style existant, en récupérant les détails du style à éditer à partir de l'identifiant fourni.
|
||||
/// </summary>
|
||||
/// <param name="id">L'identifiant du style à éditer.</param>
|
||||
/// <returns>La vue d'édition avec le ViewModel contenant les détails du style à éditer, ou une redirection vers l'index si le style n'existe pas.</returns>
|
||||
[HttpGet]
|
||||
public IActionResult Edit(int id)
|
||||
var model = new StyleDeleteViewModel
|
||||
{
|
||||
var style = this.styleRepository.Find(id);
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
|
||||
var model = new StyleEditViewModel
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Methode POST pour supprimer un style.
|
||||
/// </summary>
|
||||
/// <param name="model">Le style a supprimer.</param>
|
||||
/// <returns>Redirige vers la page d'index d'admin style.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Delete(StyleDeleteViewModel model)
|
||||
{
|
||||
var style = this.styleRepository.Find(model.IdStyle);
|
||||
|
||||
if (style != null)
|
||||
{
|
||||
this.styleRepository.Delete(style);
|
||||
}
|
||||
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Affiche la vue d'edition d'un style existant.
|
||||
/// </summary>
|
||||
/// <param name="id">L'identifiant du style a editer.</param>
|
||||
/// <returns>La vue d'edition ou une redirection vers l'index si le style n'existe pas.</returns>
|
||||
[HttpGet]
|
||||
public IActionResult Edit(int id)
|
||||
{
|
||||
var style = this.styleRepository.Find(id);
|
||||
|
||||
if (style == null || style.IdStyle == 0)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
var model = new StyleEditViewModel
|
||||
{
|
||||
IdStyle = style.IdStyle,
|
||||
Libelle = style.Libelle,
|
||||
};
|
||||
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Met a jour un style existant.
|
||||
/// </summary>
|
||||
/// <param name="model">Donnees du style a modifier.</param>
|
||||
/// <returns>Redirige vers la page d'index d'admin style.</returns>
|
||||
[HttpPost]
|
||||
public IActionResult Edit(StyleEditViewModel model)
|
||||
{
|
||||
if (!this.ModelState.IsValid)
|
||||
{
|
||||
return this.View(model);
|
||||
}
|
||||
|
||||
var style = this.styleRepository.Find(model.IdStyle);
|
||||
if (style == null)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
style.Libelle = model.Libelle;
|
||||
this.styleRepository.Update(style);
|
||||
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
@@ -170,6 +170,11 @@ public class TitreController : Controller
|
||||
{
|
||||
var titre = this.titreRepository.Find(id);
|
||||
|
||||
if (titre == null)
|
||||
{
|
||||
return this.RedirectToAction("Index");
|
||||
}
|
||||
|
||||
var model = new AdminTitreDelete
|
||||
{
|
||||
Id = titre.IdTitre,
|
||||
|
||||
Reference in New Issue
Block a user