refactor: remplace l’invocation du composant Sidebar par un composant de vue
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Webzine.Repository.Contracts;
|
||||
|
||||
namespace Webzine.WebApplication.ViewComponents
|
||||
{
|
||||
/// <summary>
|
||||
/// View component pour la sidebar, récupère les styles depuis le repository.
|
||||
/// </summary>
|
||||
public class SidebarViewComponent : ViewComponent
|
||||
{
|
||||
private readonly IStyleRepository styleRepository;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SidebarViewComponent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="styleRepository">Repository des styles injecté.</param>
|
||||
public SidebarViewComponent(IStyleRepository styleRepository)
|
||||
{
|
||||
this.styleRepository = styleRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Récupère tous les styles triés par libellé et les passe à la vue.
|
||||
/// </summary>
|
||||
/// <returns>Une vue contenant la liste des styles.</returns>
|
||||
public IViewComponentResult Invoke()
|
||||
{
|
||||
var styles = this.styleRepository.FindAll()
|
||||
.OrderBy(s => s.Libelle)
|
||||
.ToList();
|
||||
|
||||
return this.View(styles);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user