#118 Suppression des styles et des titres fonctionne.
This commit is contained in:
@@ -294,6 +294,7 @@ public class DbTitreRepository : ITitreRepository
|
|||||||
var titres = this.context.Titres
|
var titres = this.context.Titres
|
||||||
.Include(t => t.Artiste)
|
.Include(t => t.Artiste)
|
||||||
.Include(t => t.Styles)
|
.Include(t => t.Styles)
|
||||||
|
.Include(t => t.Commentaires)
|
||||||
.OrderBy(t => t.Libelle)
|
.OrderBy(t => t.Libelle)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Webzine.Entity;
|
|
||||||
using Webzine.Entity.Fixtures;
|
|
||||||
using Webzine.Repository.Contracts;
|
using Webzine.Repository.Contracts;
|
||||||
using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
|
using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
|
||||||
|
|
||||||
@@ -13,20 +11,22 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
|||||||
public class StyleController : Controller
|
public class StyleController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<StyleController> logger;
|
private readonly ILogger<StyleController> logger;
|
||||||
private readonly IStyleRepository styles;
|
private readonly IStyleRepository styleRepository;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialise une nouvelle instance de la classe <see cref="StyleController"/>.
|
/// Initialise une nouvelle instance de la classe <see cref="StyleController"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">Service de journalisation injecté.</param>
|
/// <param name="logger">Service de journalisation injecté.</param>
|
||||||
/// <param name="styles">Repository des styles injecté.</param>
|
/// <param name="styles">Repository des styles injecté.</param>
|
||||||
public StyleController(ILogger<StyleController> logger, IStyleRepository styles)
|
public StyleController(
|
||||||
|
ILogger<StyleController> logger,
|
||||||
|
IStyleRepository styleRepository)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
this.logger.LogInformation("Initialisation du contrôleur StyleController.");
|
this.logger.LogInformation("Initialisation du contrôleur StyleController.");
|
||||||
|
|
||||||
this.styles = styles;
|
this.styleRepository = styleRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -35,7 +35,7 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
|||||||
/// <returns>La vue Index avec le ViewModel contenant la liste des styles.</returns>
|
/// <returns>La vue Index avec le ViewModel contenant la liste des styles.</returns>
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
var listeStyles = this.styles.FindAll().Take(10);
|
var listeStyles = this.styleRepository.FindAll().Take(10);
|
||||||
|
|
||||||
return this.View(listeStyles);
|
return this.View(listeStyles);
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
|||||||
/// <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>
|
/// <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)
|
public IActionResult Delete(int id)
|
||||||
{
|
{
|
||||||
var style = this.styles.Find(id);
|
var style = this.styleRepository.Find(id);
|
||||||
|
|
||||||
var vm = new StyleDeleteViewModel
|
var vm = new StyleDeleteViewModel
|
||||||
{
|
{
|
||||||
@@ -67,6 +67,24 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
|||||||
return this.View(vm);
|
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>
|
/// <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.
|
/// 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>
|
/// </summary>
|
||||||
@@ -75,7 +93,7 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Edit(int id)
|
public IActionResult Edit(int id)
|
||||||
{
|
{
|
||||||
var style = styles.Find(id);
|
var style = styleRepository.Find(id);
|
||||||
|
|
||||||
var model = new StyleEditViewModel
|
var model = new StyleEditViewModel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,9 +29,6 @@ public class TitreController : Controller
|
|||||||
public TitreController(ILogger<TitreController> logger, ITitreRepository titreRepository, IArtisteRepository artisteRepository, IStyleRepository styleRepository)
|
public TitreController(ILogger<TitreController> logger, ITitreRepository titreRepository, IArtisteRepository artisteRepository, IStyleRepository styleRepository)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
this.logger.LogInformation("Initialisation du contrôleur TitreController pour l'Administration.");
|
|
||||||
|
|
||||||
this.titreRepository = titreRepository;
|
this.titreRepository = titreRepository;
|
||||||
this.artisteRepository = artisteRepository;
|
this.artisteRepository = artisteRepository;
|
||||||
this.styleRepository = styleRepository;
|
this.styleRepository = styleRepository;
|
||||||
@@ -140,4 +137,21 @@ public class TitreController : Controller
|
|||||||
|
|
||||||
return this.View(model);
|
return this.View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Méthode POST pour supprimer un titre.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Le titre à supprimer.</param>
|
||||||
|
/// <returns>Redirige vers la page d'index d'admin titre.</returns>
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult Delete(AdminTitreDelete model)
|
||||||
|
{
|
||||||
|
var titre = this.titreRepository.Find(model.Id);
|
||||||
|
if (titre != null)
|
||||||
|
{
|
||||||
|
this.titreRepository.Delete(titre);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.RedirectToAction("Index");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user