Merge pull request 'patch_dev' (#200) from patch_dev into dev
Reviewed-on: https://10.4.0.131/gitea/DI1-P4-E1/Webzine/pulls/200
This commit is contained in:
@@ -217,8 +217,7 @@ namespace Webzine.Repository
|
|||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.OrderBy(a => a.Nom)
|
.OrderBy(a => a.Nom)
|
||||||
.Include(t => t.Titres)
|
.Include(t => t.Titres)
|
||||||
.Skip(offset)
|
.Paginate(offset, limit);
|
||||||
.Take(limit);
|
|
||||||
this.logger.LogDebug("Page {PageNumber} d'artistes récupérée avec {PageSize} artistes par page.", offset, limit);
|
this.logger.LogDebug("Page {PageNumber} d'artistes récupérée avec {PageSize} artistes par page.", offset, limit);
|
||||||
return artistes;
|
return artistes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,8 +103,7 @@ public class DbCommentaireRepository : ICommentaireRepository
|
|||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Include(c => c.Titre)
|
.Include(c => c.Titre)
|
||||||
.OrderByDescending(c => c.DateCreation)
|
.OrderByDescending(c => c.DateCreation)
|
||||||
.Skip(offset)
|
.Paginate(offset, limit);
|
||||||
.Take(limit);
|
|
||||||
|
|
||||||
return commentaires;
|
return commentaires;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,8 +191,7 @@ public class DbStyleRepository : IStyleRepository
|
|||||||
var styles = this.context.Styles
|
var styles = this.context.Styles
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.OrderBy(s => s.Libelle)
|
.OrderBy(s => s.Libelle)
|
||||||
.Skip(offset)
|
.Paginate(offset, limit);
|
||||||
.Take(limit);
|
|
||||||
|
|
||||||
this.logger.LogDebug("La liste paginée de styles a été récupérée.");
|
this.logger.LogDebug("La liste paginée de styles a été récupérée.");
|
||||||
return styles;
|
return styles;
|
||||||
|
|||||||
@@ -107,8 +107,7 @@ public class DbTitreRepository : ITitreRepository
|
|||||||
.ThenBy(t => t.Libelle)
|
.ThenBy(t => t.Libelle)
|
||||||
.Include(t => t.Artiste)
|
.Include(t => t.Artiste)
|
||||||
.Include(t => t.Styles)
|
.Include(t => t.Styles)
|
||||||
.Skip(offset)
|
.Paginate(offset, limit)
|
||||||
.Take(limit)
|
|
||||||
.AsNoTracking();
|
.AsNoTracking();
|
||||||
|
|
||||||
return titres;
|
return titres;
|
||||||
|
|||||||
@@ -112,8 +112,7 @@ namespace Webzine.Repository
|
|||||||
{
|
{
|
||||||
return this.dataStore.Artistes
|
return this.dataStore.Artistes
|
||||||
.OrderBy(a => a.Nom)
|
.OrderBy(a => a.Nom)
|
||||||
.Skip(offset)
|
.Paginate(offset, limit)
|
||||||
.Take(limit)
|
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,8 +63,7 @@ namespace Webzine.Repository
|
|||||||
{
|
{
|
||||||
return this.dataStore.Commentaires
|
return this.dataStore.Commentaires
|
||||||
.OrderByDescending(c => c.DateCreation)
|
.OrderByDescending(c => c.DateCreation)
|
||||||
.Skip(offset)
|
.Paginate(offset, limit);
|
||||||
.Take(limit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
@@ -77,8 +77,7 @@ public class LocalStyleRepository : IStyleRepository
|
|||||||
{
|
{
|
||||||
return this.dataStore.Styles
|
return this.dataStore.Styles
|
||||||
.OrderBy(s => s.Libelle)
|
.OrderBy(s => s.Libelle)
|
||||||
.Skip(offset)
|
.Paginate(offset, limit)
|
||||||
.Take(limit)
|
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,8 +50,7 @@ public class LocalTitreRepository : ITitreRepository
|
|||||||
return this.dataStore.Titres
|
return this.dataStore.Titres
|
||||||
.OrderByDescending(t => t.DateCreation)
|
.OrderByDescending(t => t.DateCreation)
|
||||||
.ThenBy(t => t.Libelle)
|
.ThenBy(t => t.Libelle)
|
||||||
.Skip(offset)
|
.Paginate(offset, limit);
|
||||||
.Take(limit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
56
Webzine.Repository/RepositoryPaginationExtensions.cs
Normal file
56
Webzine.Repository/RepositoryPaginationExtensions.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
namespace Webzine.Repository;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fournit des méthodes génériques pour paginer des collections dans la couche Repository.
|
||||||
|
/// </summary>
|
||||||
|
public static class RepositoryPaginationExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Retourne une portion paginée d'une requête.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Type des éléments paginés.</typeparam>
|
||||||
|
/// <param name="source">Source à paginer.</param>
|
||||||
|
/// <param name="offset">Nombre d'éléments à ignorer.</param>
|
||||||
|
/// <param name="limit">Nombre maximal d'éléments à retourner.</param>
|
||||||
|
/// <returns>La requête paginée.</returns>
|
||||||
|
public static IQueryable<T> Paginate<T>(this IQueryable<T> source, int offset, int limit)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(source);
|
||||||
|
ValidatePaginationArguments(offset, limit);
|
||||||
|
|
||||||
|
return source
|
||||||
|
.Skip(offset)
|
||||||
|
.Take(limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retourne une portion paginée d'une collection en mémoire.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Type des éléments paginés.</typeparam>
|
||||||
|
/// <param name="source">Source à paginer.</param>
|
||||||
|
/// <param name="offset">Nombre d'éléments à ignorer.</param>
|
||||||
|
/// <param name="limit">Nombre maximal d'éléments à retourner.</param>
|
||||||
|
/// <returns>La collection paginée.</returns>
|
||||||
|
public static IEnumerable<T> Paginate<T>(this IEnumerable<T> source, int offset, int limit)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(source);
|
||||||
|
ValidatePaginationArguments(offset, limit);
|
||||||
|
|
||||||
|
return source
|
||||||
|
.Skip(offset)
|
||||||
|
.Take(limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidatePaginationArguments(int offset, int limit)
|
||||||
|
{
|
||||||
|
if (offset < 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(offset), "L'offset doit être supérieur ou égal à 0.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (limit <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(limit), "La limite doit être strictement supérieure à 0.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,174 +1,175 @@
|
|||||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
using ViewModels.Styles;
|
|
||||||
|
|
||||||
using Webzine.Entity;
|
|
||||||
using Webzine.Repository.Contracts;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Controleur pour la gestion des styles dans l'administration du webzine.
|
|
||||||
/// </summary>
|
|
||||||
[Area("Administration")]
|
|
||||||
public class StyleController : Controller
|
|
||||||
{
|
{
|
||||||
private readonly ILogger<StyleController> logger;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
private readonly IStyleRepository styleRepository;
|
|
||||||
private readonly IConfiguration configuration;
|
using Webzine.Entity;
|
||||||
|
using Webzine.Repository.Contracts;
|
||||||
|
using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
|
||||||
|
using Webzine.WebApplication.Areas.Administration.ViewModels.Styles;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="StyleController"/> class.
|
/// Controleur pour la gestion des styles dans l'administration du webzine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">Service de journalisation injecte.</param>
|
[Area("Administration")]
|
||||||
/// <param name="styleRepository">Repository des styles injecte.</param>
|
public class StyleController : Controller
|
||||||
/// <param name="configuration">Service de configuration injecte pour acceder aux parametres de configuration.</param>
|
|
||||||
public StyleController(
|
|
||||||
ILogger<StyleController> logger,
|
|
||||||
IStyleRepository styleRepository,
|
|
||||||
IConfiguration configuration)
|
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
private readonly ILogger<StyleController> logger;
|
||||||
this.styleRepository = styleRepository;
|
private readonly IStyleRepository styleRepository;
|
||||||
this.configuration = configuration;
|
private readonly IConfiguration configuration;
|
||||||
|
|
||||||
this.logger.LogInformation("Initialisation du controleur StyleController.");
|
/// <summary>
|
||||||
}
|
/// Initializes a new instance of the <see cref="StyleController"/> class.
|
||||||
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="logger">Service de journalisation injecte.</param>
|
||||||
/// Affiche la liste des styles dans la vue Index.
|
/// <param name="styleRepository">Repository des styles injecte.</param>
|
||||||
/// </summary>
|
/// <param name="configuration">Service de configuration injecte pour acceder aux parametres de configuration.</param>
|
||||||
/// <param name="page">Le numero de page pour la pagination des styles (par defaut a 0).</param>
|
public StyleController(
|
||||||
/// <returns>La vue Index avec la liste des styles.</returns>
|
ILogger<StyleController> logger,
|
||||||
public IActionResult Index(int page = 0)
|
IStyleRepository styleRepository,
|
||||||
{
|
IConfiguration configuration)
|
||||||
int styles_par_page = this.configuration.GetValue<int>("Webzine:NombreDeLignesAdministration");
|
|
||||||
IEnumerable<Style> listeStyles = this.styleRepository.FindStyles(page * styles_par_page, styles_par_page);
|
|
||||||
|
|
||||||
int totalStyles = this.styleRepository.Count();
|
|
||||||
|
|
||||||
var model = new StyleIndexViewModel
|
|
||||||
{
|
{
|
||||||
Styles = listeStyles,
|
this.logger = logger;
|
||||||
Page = page,
|
this.styleRepository = styleRepository;
|
||||||
TotalPages = (int)Math.Ceiling((double)totalStyles / styles_par_page),
|
this.configuration = configuration;
|
||||||
};
|
|
||||||
return this.View(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
this.logger.LogInformation("Initialisation du controleur StyleController.");
|
||||||
/// Affiche la vue de creation d'un nouveau style.
|
}
|
||||||
/// </summary>
|
|
||||||
/// <returns>La vue Create pour ajouter un nouveau style.</returns>
|
/// <summary>
|
||||||
public IActionResult Create()
|
/// Affiche la liste des styles dans la vue Index.
|
||||||
{
|
/// </summary>
|
||||||
var model = new StyleCreateViewModel
|
/// <param name="page">Le numero de page pour la pagination des styles (par defaut a 0).</param>
|
||||||
|
/// <returns>La vue Index avec la liste des styles.</returns>
|
||||||
|
public IActionResult Index(int page = 0)
|
||||||
{
|
{
|
||||||
Libelle = string.Empty,
|
int styles_par_page = this.configuration.GetValue<int>("Webzine:NombreDeLignesAdministration");
|
||||||
};
|
IEnumerable<Style> listeStyles = this.styleRepository.FindStyles(page * styles_par_page, styles_par_page);
|
||||||
|
|
||||||
return this.View(model);
|
int totalStyles = this.styleRepository.Count();
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
var model = new StyleIndexViewModel
|
||||||
/// Cree un nouveau style.
|
{
|
||||||
/// </summary>
|
Styles = listeStyles,
|
||||||
/// <param name="model">Nouveau style.</param>
|
Page = page,
|
||||||
/// <returns>IActionResult.</returns>
|
TotalPages = (int)Math.Ceiling((double)totalStyles / styles_par_page),
|
||||||
[HttpPost]
|
};
|
||||||
public IActionResult Create(StyleCreateViewModel model)
|
return this.View(model);
|
||||||
{
|
}
|
||||||
var style = new Style
|
|
||||||
|
/// <summary>
|
||||||
|
/// Affiche la vue de creation d'un nouveau style.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>La vue Create pour ajouter un nouveau style.</returns>
|
||||||
|
public IActionResult Create()
|
||||||
{
|
{
|
||||||
Libelle = model.Libelle,
|
var model = new StyleCreateViewModel
|
||||||
};
|
{
|
||||||
|
Libelle = string.Empty,
|
||||||
|
};
|
||||||
|
|
||||||
this.styleRepository.Add(style);
|
return this.View(model);
|
||||||
|
}
|
||||||
|
|
||||||
return this.RedirectToAction("Index");
|
/// <summary>
|
||||||
}
|
/// Cree un nouveau style.
|
||||||
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="model">Nouveau style.</param>
|
||||||
/// Affiche la vue de confirmation de suppression d'un style.
|
/// <returns>IActionResult.</returns>
|
||||||
/// </summary>
|
[HttpPost]
|
||||||
/// <param name="id">L'identifiant du style a supprimer.</param>
|
public IActionResult Create(StyleCreateViewModel model)
|
||||||
/// <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)
|
|
||||||
{
|
{
|
||||||
|
var style = new Style
|
||||||
|
{
|
||||||
|
Libelle = model.Libelle,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.styleRepository.Add(style);
|
||||||
|
|
||||||
return this.RedirectToAction("Index");
|
return this.RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
var model = new StyleDeleteViewModel
|
/// <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)
|
||||||
{
|
{
|
||||||
IdStyle = style.IdStyle,
|
var style = this.styleRepository.Find(id);
|
||||||
Libelle = style.Libelle,
|
|
||||||
};
|
|
||||||
|
|
||||||
return this.View(model);
|
if (style == null || style.IdStyle == 0)
|
||||||
}
|
{
|
||||||
|
return this.RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
var model = new StyleDeleteViewModel
|
||||||
/// Methode POST pour supprimer un style.
|
{
|
||||||
/// </summary>
|
IdStyle = style.IdStyle,
|
||||||
/// <param name="model">Le style a supprimer.</param>
|
Libelle = style.Libelle,
|
||||||
/// <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)
|
return this.View(model);
|
||||||
{
|
|
||||||
this.styleRepository.Delete(style);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.RedirectToAction("Index");
|
/// <summary>
|
||||||
}
|
/// Methode POST pour supprimer un style.
|
||||||
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="model">Le style a supprimer.</param>
|
||||||
/// Affiche la vue d'edition d'un style existant.
|
/// <returns>Redirige vers la page d'index d'admin style.</returns>
|
||||||
/// </summary>
|
[HttpPost]
|
||||||
/// <param name="id">L'identifiant du style a editer.</param>
|
public IActionResult Delete(StyleDeleteViewModel model)
|
||||||
/// <returns>La vue d'edition ou une redirection vers l'index si le style n'existe pas.</returns>
|
|
||||||
public IActionResult Edit(int id)
|
|
||||||
{
|
|
||||||
var style = this.styleRepository.Find(id);
|
|
||||||
|
|
||||||
if (style == null || style.IdStyle == 0)
|
|
||||||
{
|
{
|
||||||
|
var style = this.styleRepository.Find(model.IdStyle);
|
||||||
|
|
||||||
|
if (style != null)
|
||||||
|
{
|
||||||
|
this.styleRepository.Delete(style);
|
||||||
|
}
|
||||||
|
|
||||||
return this.RedirectToAction("Index");
|
return this.RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
var model = new StyleEditViewModel
|
/// <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>
|
||||||
|
public IActionResult Edit(int id)
|
||||||
{
|
{
|
||||||
IdStyle = style.IdStyle,
|
var style = this.styleRepository.Find(id);
|
||||||
Libelle = style.Libelle,
|
|
||||||
};
|
|
||||||
|
|
||||||
return this.View(model);
|
if (style == null || style.IdStyle == 0)
|
||||||
}
|
{
|
||||||
|
return this.RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
var model = new StyleEditViewModel
|
||||||
/// Met a jour un style existant.
|
{
|
||||||
/// </summary>
|
IdStyle = style.IdStyle,
|
||||||
/// <param name="model">Donnees du style a modifier.</param>
|
Libelle = style.Libelle,
|
||||||
/// <returns>Redirige vers la page d'index d'admin style.</returns>
|
};
|
||||||
[HttpPost]
|
|
||||||
public IActionResult Edit(StyleEditViewModel model)
|
return this.View(model);
|
||||||
{
|
|
||||||
var style = this.styleRepository.Find(model.IdStyle);
|
|
||||||
if (style == null)
|
|
||||||
{
|
|
||||||
return this.RedirectToAction("Index");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
style.Libelle = model.Libelle;
|
/// <summary>
|
||||||
this.styleRepository.Update(style);
|
/// 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)
|
||||||
|
{
|
||||||
|
var style = this.styleRepository.Find(model.IdStyle);
|
||||||
|
if (style == null)
|
||||||
|
{
|
||||||
|
return this.RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
|
||||||
return this.RedirectToAction("Index");
|
style.Libelle = model.Libelle;
|
||||||
|
this.styleRepository.Update(style);
|
||||||
|
|
||||||
|
return this.RedirectToAction("Index");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user