Refacto StyleCop
This commit is contained in:
@@ -1,15 +0,0 @@
|
|||||||
// <copyright file="ArtisteRepository.cs" company="PlaceholderCompany">
|
|
||||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
||||||
// </copyright>
|
|
||||||
|
|
||||||
namespace Webzine.Repository
|
|
||||||
{
|
|
||||||
using Webzine.Repository.Contracts;
|
|
||||||
/// <summary>
|
|
||||||
/// Implémentation de l'interface IArtisteRepository.
|
|
||||||
/// </summary>
|
|
||||||
public class ArtisteRepository : IArtisteRepository
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
namespace Webzine.Repository
|
// <copyright file="DbArtisteRepository.cs" company="PlaceholderCompany">
|
||||||
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||||
|
// </copyright>
|
||||||
|
|
||||||
|
namespace Webzine.Repository
|
||||||
{
|
{
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -13,18 +17,18 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class DbArtisteRepository : IArtisteRepository
|
public class DbArtisteRepository : IArtisteRepository
|
||||||
{
|
{
|
||||||
private WebzineDbContext _context;
|
private WebzineDbContext context;
|
||||||
private readonly ILogger<LocalArtisteRepository> _logger;
|
private readonly ILogger<LocalArtisteRepository> logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="DbArtisteRepository"/> class.
|
/// Initializes a new instance of the <see cref="DbArtisteRepository"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context">Le contexte de base de données à utiliser pour accéder aux entités et effectuer des opérations de
|
/// <param name="context">Le contexte de base de données à utiliser pour accéder aux entités et effectuer des opérations de
|
||||||
/// persistance. Ne peut pas être null.</param>
|
/// persistance. Ne peut pas être null.</param>
|
||||||
public DbArtisteRepository(WebzineDbContext context, ILogger<LocalArtisteRepository> logger)
|
public DbArtisteRepository(WebzineDbContext context, ILogger<LocalArtisteRepository> logger)
|
||||||
{
|
{
|
||||||
this._logger = logger;
|
this.logger = logger;
|
||||||
this._context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -32,17 +36,17 @@
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this._context.Artistes.Add(artiste);
|
this.context.Artistes.Add(artiste);
|
||||||
this._context.SaveChanges();
|
this.context.SaveChanges();
|
||||||
}
|
}
|
||||||
catch (DbUpdateException dbex)
|
catch (DbUpdateException dbex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(dbex, "Erreur de base de données lors de l'ajout de l'artiste: {id}", artiste.IdArtiste);
|
this.logger.LogError(dbex, "Erreur de base de données lors de l'ajout de l'artiste: {id}", artiste.IdArtiste);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Une erreur est survenue lors de l'ajout de l'artiste {Nom}.", artiste?.Nom);
|
this.logger.LogError(ex, "Une erreur est survenue lors de l'ajout de l'artiste {Nom}.", artiste?.Nom);
|
||||||
throw new Exception("Une erreur est survenue lors de l'ajout de l'artiste.", ex);
|
throw new Exception("Une erreur est survenue lors de l'ajout de l'artiste.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,17 +61,17 @@
|
|||||||
throw new ArgumentNullException(nameof(artiste), "L'artiste à supprimer ne peut pas être null.");
|
throw new ArgumentNullException(nameof(artiste), "L'artiste à supprimer ne peut pas être null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this._context.Artistes.Remove(artiste);
|
this.context.Artistes.Remove(artiste);
|
||||||
this._context.SaveChanges();
|
this.context.SaveChanges();
|
||||||
}
|
}
|
||||||
catch (DbUpdateException dbex)
|
catch (DbUpdateException dbex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(dbex, "Erreur de base de données lors de la suppression de l'artiste: {Id}", artiste.IdArtiste);
|
this.logger.LogError(dbex, "Erreur de base de données lors de la suppression de l'artiste: {Id}", artiste.IdArtiste);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Une erreur est survenue lors de la suppression de l'artiste {Nom}.", artiste?.Nom);
|
this.logger.LogError(ex, "Une erreur est survenue lors de la suppression de l'artiste {Nom}.", artiste?.Nom);
|
||||||
throw new Exception("Une erreur est survenue lors de la suppression de l'artiste.", ex);
|
throw new Exception("Une erreur est survenue lors de la suppression de l'artiste.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,14 +81,14 @@
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Artiste artiste = this._context.Artistes
|
Artiste artiste = this.context.Artistes
|
||||||
.Include(a => a.Titres)
|
.Include(a => a.Titres)
|
||||||
.First(a => a.IdArtiste == id);
|
.First(a => a.IdArtiste == id);
|
||||||
return artiste;
|
return artiste;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Erreur lors de la recherche de l'artiste: {Id}", id);
|
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste: {Id}", id);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,20 +98,21 @@
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var artiste = this._context.Artistes
|
var artiste = this.context.Artistes
|
||||||
.Include(a => a.Titres)
|
.Include(a => a.Titres)
|
||||||
.FirstOrDefault(a => a.Nom == nom);
|
.FirstOrDefault(a => a.Nom == nom);
|
||||||
|
|
||||||
if (artiste == null)
|
if (artiste == null)
|
||||||
{
|
{
|
||||||
this._logger.LogWarning("Pas d'artiste au nom {Nom}", nom);
|
this.logger.LogWarning("Pas d'artiste au nom {Nom}", nom);
|
||||||
artiste = new Artiste();
|
artiste = new Artiste();
|
||||||
}
|
}
|
||||||
return artiste;
|
|
||||||
|
return artiste;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le nom: {Nom}", nom);
|
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le nom: {Nom}", nom);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,13 +123,13 @@
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// .AsNoTracking() rend la requête beaucoup plus rapide pour de la lecture
|
// .AsNoTracking() rend la requête beaucoup plus rapide pour de la lecture
|
||||||
var artistes = this._context.Artistes.AsNoTracking().ToList();
|
var artistes = this.context.Artistes.AsNoTracking().ToList();
|
||||||
this._logger.LogInformation("{Count} artistes récupérés de la base.", artistes.Count);
|
this.logger.LogInformation("{Count} artistes récupérés de la base.", artistes.Count);
|
||||||
return artistes;
|
return artistes;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Erreur lors de la récupération de tous les artistes.");
|
this.logger.LogError(ex, "Erreur lors de la récupération de tous les artistes.");
|
||||||
return Enumerable.Empty<Artiste>(); // Retourne une liste vide au lieu de faire crash l'UI
|
return Enumerable.Empty<Artiste>(); // Retourne une liste vide au lieu de faire crash l'UI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,18 +144,18 @@
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this._context.Artistes.Update(artiste);
|
this.context.Artistes.Update(artiste);
|
||||||
this._context.SaveChanges();
|
this.context.SaveChanges();
|
||||||
this._logger.LogInformation("Artiste {Id} ({Nom}) mis à jour avec succès.", artiste.IdArtiste, artiste.Nom);
|
this.logger.LogInformation("Artiste {Id} ({Nom}) mis à jour avec succès.", artiste.IdArtiste, artiste.Nom);
|
||||||
}
|
}
|
||||||
catch (DbUpdateException ex)
|
catch (DbUpdateException ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Erreur de base de données lors de la mise à jour de l'artiste ID: {IdArtiste}", artiste.IdArtiste);
|
this.logger.LogError(ex, "Erreur de base de données lors de la mise à jour de l'artiste ID: {IdArtiste}", artiste.IdArtiste);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Erreur lors de la mise à jour de l'artiste {Id}.", artiste.IdArtiste);
|
this.logger.LogError(ex, "Erreur lors de la mise à jour de l'artiste {Id}.", artiste.IdArtiste);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
namespace Webzine.Repository
|
// <copyright file="LocalArtisteRepository.cs" company="PlaceholderCompany">
|
||||||
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||||
|
// </copyright>
|
||||||
|
|
||||||
|
namespace Webzine.Repository
|
||||||
{
|
{
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Webzine.Entity;
|
using Webzine.Entity;
|
||||||
@@ -10,8 +14,8 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class LocalArtisteRepository : IArtisteRepository
|
public class LocalArtisteRepository : IArtisteRepository
|
||||||
{
|
{
|
||||||
private readonly ILogger<LocalArtisteRepository> _logger;
|
private readonly ILogger<LocalArtisteRepository> logger;
|
||||||
private readonly List<Artiste> _artistes;
|
private readonly List<Artiste> artistes;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="LocalArtisteRepository"/> class.
|
/// Initializes a new instance of the <see cref="LocalArtisteRepository"/> class.
|
||||||
@@ -21,8 +25,8 @@
|
|||||||
/// <param name="logger">Le logger à utiliser pour enregistrer les messages de journalisation. Ne peut pas être null.</param>
|
/// <param name="logger">Le logger à utiliser pour enregistrer les messages de journalisation. Ne peut pas être null.</param>
|
||||||
public LocalArtisteRepository(List<Artiste> artistes, ILogger<LocalArtisteRepository> logger)
|
public LocalArtisteRepository(List<Artiste> artistes, ILogger<LocalArtisteRepository> logger)
|
||||||
{
|
{
|
||||||
this._logger = logger;
|
this.logger = logger;
|
||||||
this._artistes = artistes;
|
this.artistes = artistes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -30,18 +34,18 @@
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (this._artistes.Any(a => a.IdArtiste == artiste.IdArtiste))
|
if (this.artistes.Any(a => a.IdArtiste == artiste.IdArtiste))
|
||||||
{
|
{
|
||||||
this._logger.LogWarning("Un artiste avec l'ID {Id} existe déjà. L'ajout est ignoré.", artiste.IdArtiste);
|
this.logger.LogWarning("Un artiste avec l'ID {Id} existe déjà. L'ajout est ignoré.", artiste.IdArtiste);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._artistes.Add(artiste);
|
this.artistes.Add(artiste);
|
||||||
this._logger.LogInformation("Artiste ajouté : {Nom}", artiste.Nom);
|
this.logger.LogInformation("Artiste ajouté : {Nom}", artiste.Nom);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Erreur lors de l'ajout de l'artiste : {Nom}", artiste?.Nom);
|
this.logger.LogError(ex, "Erreur lors de l'ajout de l'artiste : {Nom}", artiste?.Nom);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,12 +55,12 @@
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this._artistes.Remove(artiste);
|
this.artistes.Remove(artiste);
|
||||||
this._logger.LogInformation("Artiste supprimé : {Nom}", artiste.Nom);
|
this.logger.LogInformation("Artiste supprimé : {Nom}", artiste.Nom);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Erreur lors de la suppression de l'artiste : {Nom}", artiste.Nom);
|
this.logger.LogError(ex, "Erreur lors de la suppression de l'artiste : {Nom}", artiste.Nom);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,12 +70,12 @@
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Artiste artiste = this._artistes.First(a => a.IdArtiste == id);
|
Artiste artiste = this.artistes.First(a => a.IdArtiste == id);
|
||||||
return artiste;
|
return artiste;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec ID: {Id}", id);
|
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec ID: {Id}", id);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,22 +85,21 @@
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Artiste artiste = this._artistes.First(a => a.Nom == nom);
|
Artiste artiste = this.artistes.First(a => a.Nom == nom);
|
||||||
return artiste;
|
return artiste;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le nom: {Nom}", nom);
|
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le nom: {Nom}", nom);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
/// La liste retournée est une copie de la liste interne, donc elle ne peut être nulle.
|
/// La liste retournée est une copie de la liste interne, donc elle ne peut être nulle.
|
||||||
public IEnumerable<Artiste> FindAll()
|
public IEnumerable<Artiste> FindAll()
|
||||||
{
|
{
|
||||||
return this._artistes;
|
return this.artistes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -104,7 +107,7 @@
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var artisteToUpdate = this._artistes.FirstOrDefault(a => a.IdArtiste == artiste.IdArtiste);
|
var artisteToUpdate = this.artistes.FirstOrDefault(a => a.IdArtiste == artiste.IdArtiste);
|
||||||
|
|
||||||
if (artisteToUpdate != null)
|
if (artisteToUpdate != null)
|
||||||
{
|
{
|
||||||
@@ -112,17 +115,17 @@
|
|||||||
artisteToUpdate.Biographie = artiste.Biographie;
|
artisteToUpdate.Biographie = artiste.Biographie;
|
||||||
artisteToUpdate.Titres = artiste.Titres;
|
artisteToUpdate.Titres = artiste.Titres;
|
||||||
|
|
||||||
this._logger.LogInformation("Artiste {Id} mis à jour avec succès.", artiste.IdArtiste);
|
this.logger.LogInformation("Artiste {Id} mis à jour avec succès.", artiste.IdArtiste);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this._logger.LogWarning("Mise à jour impossible : l'artiste avec l'ID {Id} n'existe pas.", artiste.IdArtiste);
|
this.logger.LogWarning("Mise à jour impossible : l'artiste avec l'ID {Id} n'existe pas.", artiste.IdArtiste);
|
||||||
throw new KeyNotFoundException($"L'artiste {artiste.IdArtiste} est introuvable.");
|
throw new KeyNotFoundException($"L'artiste {artiste.IdArtiste} est introuvable.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
this._logger.LogError(ex, "Une erreur est survenue lors de la mise à jour de l'artiste {Id}.", artiste.IdArtiste);
|
this.logger.LogError(ex, "Une erreur est survenue lors de la mise à jour de l'artiste {Id}.", artiste.IdArtiste);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Webzine.Repository
|
|
||||||
{
|
|
||||||
internal class StyleRepository
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
// <copyright file="TitreRepository.cs" company="PlaceholderCompany">
|
|
||||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
||||||
// </copyright>
|
|
||||||
|
|
||||||
namespace Webzine.Repository
|
|
||||||
{
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Webzine.EntitiesContext;
|
|
||||||
using Webzine.Entity;
|
|
||||||
using Webzine.Repository.Contracts;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Implémentation de l'interface ITitreRepository.
|
|
||||||
/// </summary>
|
|
||||||
public class TitreRepository : ITitreRepository
|
|
||||||
{
|
|
||||||
private readonly WebzineDbContext context;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="TitreRepository"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public TitreRepository(WebzineDbContext context)
|
|
||||||
{
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Rechercher un titre à l'aide de son nom.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mot">Nom de la musique.</param>
|
|
||||||
/// <returns>IEnumerable Titre.</returns>
|
|
||||||
public IEnumerable<Titre> Search(string mot)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(mot))
|
|
||||||
{
|
|
||||||
return Enumerable.Empty<Titre>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.context.Titres
|
|
||||||
.Where(t => !string.IsNullOrWhiteSpace(t.Libelle)
|
|
||||||
&& t.Libelle.ToLower().Contains(mot.ToLower()))
|
|
||||||
.OrderBy(t => t.Libelle)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retourne le titre demandé à partir de son identifiant.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idTitre">Id du titre cherché.</param>
|
|
||||||
/// <returns>Un titre.</returns>
|
|
||||||
public Titre? Find(int idTitre)
|
|
||||||
{
|
|
||||||
var find = this.context.Titres
|
|
||||||
.Where(t => t.IdTitre == idTitre)
|
|
||||||
.First();
|
|
||||||
|
|
||||||
return find;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retourne les titres demandés (pour la pagination) triés
|
|
||||||
/// selon la date de création(du plus récent à ancien).
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>IEnumerable de Titre.</returns>
|
|
||||||
public IEnumerable<Titre> FindTitres(
|
|
||||||
int offset,
|
|
||||||
int limit)
|
|
||||||
{
|
|
||||||
return this.context.Titres
|
|
||||||
.OrderByDescending(t => t.DateCreation)
|
|
||||||
.Include(t => t.Artiste)
|
|
||||||
.Skip((offset - 1) * limit)
|
|
||||||
.Take(limit)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retourne tous les titres.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Liste de Titre.</returns>
|
|
||||||
public IEnumerable<Titre> FindAll()
|
|
||||||
{
|
|
||||||
return this.context.Titres
|
|
||||||
.AsNoTracking()
|
|
||||||
.Include(t => t.Artiste)
|
|
||||||
.OrderByDescending(t => t.DateCreation)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Trouver les titres correspondant à un style.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="libelle">Style de musique recherché.</param>
|
|
||||||
/// <returns>IEnumerable Titre.</returns>
|
|
||||||
public IEnumerable<Titre> SearchByStyle(string libelle)
|
|
||||||
{
|
|
||||||
return this.context.Titres
|
|
||||||
.Where(t => t.Styles.Any(s => !string.IsNullOrWhiteSpace(s.Libelle)
|
|
||||||
&& s.Libelle.ToLower().Contains(libelle.ToLower())))
|
|
||||||
.OrderBy(t => t.Libelle)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
|||||||
public class ArtisteController : Controller
|
public class ArtisteController : Controller
|
||||||
{
|
{
|
||||||
// Injection du logger via le constructeur
|
// Injection du logger via le constructeur
|
||||||
private readonly ILogger<ArtisteController> _logger;
|
private readonly ILogger<ArtisteController> logger;
|
||||||
private readonly IArtisteRepository _artisteRepository;
|
private readonly IArtisteRepository _artisteRepository;
|
||||||
private readonly List<Artiste> _artistes = new List<Artiste>();
|
private readonly List<Artiste> _artistes = new List<Artiste>();
|
||||||
|
|
||||||
@@ -18,8 +18,8 @@ public class ArtisteController : Controller
|
|||||||
public ArtisteController(ILogger<ArtisteController> logger,
|
public ArtisteController(ILogger<ArtisteController> logger,
|
||||||
IArtisteRepository artisteRepository)
|
IArtisteRepository artisteRepository)
|
||||||
{
|
{
|
||||||
this._logger = logger;
|
this.logger = logger;
|
||||||
this._logger.LogDebug(1, "initialisation du ArtisteController d'administration");
|
this.logger.LogDebug(1, "initialisation du ArtisteController d'administration");
|
||||||
this._artisteRepository = artisteRepository;
|
this._artisteRepository = artisteRepository;
|
||||||
this._artistes.AddRange(this._artisteRepository.FindAll());
|
this._artistes.AddRange(this._artisteRepository.FindAll());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
|||||||
[Area("Administration")]
|
[Area("Administration")]
|
||||||
public class CommentaireController : Controller
|
public class CommentaireController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<CommentaireController> _logger;
|
private readonly ILogger<CommentaireController> logger;
|
||||||
private readonly List<Commentaire> _commentaires;
|
private readonly List<Commentaire> _commentaires;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -19,9 +19,9 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
|||||||
/// <param name="logger">Service de journalisation injecté.</param>
|
/// <param name="logger">Service de journalisation injecté.</param>
|
||||||
public CommentaireController(ILogger<CommentaireController> logger)
|
public CommentaireController(ILogger<CommentaireController> logger)
|
||||||
{
|
{
|
||||||
this._logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
this._logger.LogInformation("Initialisation du contrôleur CommentaireController.");
|
this.logger.LogInformation("Initialisation du contrôleur CommentaireController.");
|
||||||
|
|
||||||
var factory = new DataFactory(); // TODO injecter le factory via DI pour éviter de le recréer à chaque fois
|
var factory = new DataFactory(); // TODO injecter le factory via DI pour éviter de le recréer à chaque fois
|
||||||
// faire une classe statique
|
// faire une classe statique
|
||||||
@@ -32,7 +32,7 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
|||||||
|
|
||||||
_commentaires = factory.GenerateCommentaires(50, _titres);
|
_commentaires = factory.GenerateCommentaires(50, _titres);
|
||||||
|
|
||||||
this._logger.LogInformation("Données fictives générées avec succès.");
|
this.logger.LogInformation("Données fictives générées avec succès.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -65,7 +65,7 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
|||||||
|
|
||||||
if (commentaire == null)
|
if (commentaire == null)
|
||||||
{
|
{
|
||||||
this._logger.LogWarning("Commentaire avec ID {Id} introuvable pour suppression.", id);
|
this.logger.LogWarning("Commentaire avec ID {Id} introuvable pour suppression.", id);
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
// Copyright (c) Equipe 1 - . All rights reserved.
|
// Copyright (c) Equipe 1 - . All rights reserved.
|
||||||
// </copyright>
|
// </copyright>
|
||||||
|
|
||||||
using Webzine.Repository.Contracts;
|
|
||||||
|
|
||||||
namespace Webzine.WebApplication.Controllers
|
namespace Webzine.WebApplication.Controllers
|
||||||
{
|
{
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
public class ArtisteController : Controller
|
public class ArtisteController : Controller
|
||||||
{
|
{
|
||||||
// Injection du logger via le constructeur
|
// Injection du logger via le constructeur
|
||||||
private readonly ILogger<ArtisteController> _logger;
|
private readonly ILogger<ArtisteController> logger;
|
||||||
private readonly IArtisteRepository _artisteRepository;
|
private readonly IArtisteRepository _artisteRepository;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -18,8 +18,8 @@
|
|||||||
public ArtisteController(ILogger<ArtisteController> logger,
|
public ArtisteController(ILogger<ArtisteController> logger,
|
||||||
IArtisteRepository artisteRepository)
|
IArtisteRepository artisteRepository)
|
||||||
{
|
{
|
||||||
this._logger = logger;
|
this.logger = logger;
|
||||||
this._logger.LogDebug("Initialisation du ArtisteController");
|
this.logger.LogDebug("Initialisation du ArtisteController");
|
||||||
this._artisteRepository = artisteRepository;
|
this._artisteRepository = artisteRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,11 +31,11 @@
|
|||||||
[HttpGet("/artiste/{nom}")]
|
[HttpGet("/artiste/{nom}")]
|
||||||
public IActionResult Index(string nom)
|
public IActionResult Index(string nom)
|
||||||
{
|
{
|
||||||
this._logger.LogInformation("Tentative d'accès à l'artiste avec le nom : {NomArtiste}", nom);
|
this.logger.LogInformation("Tentative d'accès à l'artiste avec le nom : {NomArtiste}", nom);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(nom))
|
if (string.IsNullOrEmpty(nom))
|
||||||
{
|
{
|
||||||
this._logger.LogWarning("Nom de l'artiste manquant dans la requête.");
|
this.logger.LogWarning("Nom de l'artiste manquant dans la requête.");
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
|
|
||||||
if (artiste == null)
|
if (artiste == null)
|
||||||
{
|
{
|
||||||
this._logger.LogWarning("Artiste non trouvé pour le nom : {NomArtiste}", nomPropre);
|
this.logger.LogWarning("Artiste non trouvé pour le nom : {NomArtiste}", nomPropre);
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
var viewModel = new ArtisteDetailsViewModel
|
var viewModel = new ArtisteDetailsViewModel
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
.OrderBy(g => g.Key),
|
.OrderBy(g => g.Key),
|
||||||
};
|
};
|
||||||
|
|
||||||
this._logger.LogInformation("Artiste trouvé : {NomArtiste}", nom);
|
this.logger.LogInformation("Artiste trouvé : {NomArtiste}", nom);
|
||||||
|
|
||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,182 +1,171 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
// <copyright file="TitreController.cs" company=" Equipe 1 - ">
|
||||||
using Webzine.Entity;
|
// Copyright (c) Equipe 1 - . All rights reserved.
|
||||||
using Webzine.Repository.Contracts;
|
// </copyright>
|
||||||
using Webzine.WebApplication.ViewModels.Titre;
|
|
||||||
|
|
||||||
namespace Webzine.WebApplication.Controllers;
|
namespace Webzine.WebApplication.Controllers
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Controleur responsable de la gestion des titres musicaux :
|
|
||||||
/// affichage des details, filtrage par style,
|
|
||||||
/// ajout de likes, commentaires et recherche.
|
|
||||||
/// </summary>
|
|
||||||
[Route("titre")]
|
|
||||||
public class TitreController : Controller
|
|
||||||
{
|
{
|
||||||
private readonly ILogger<TitreController> logger;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
private readonly ITitreRepository titreRepository;
|
using Webzine.Entity;
|
||||||
|
using Webzine.Repository.Contracts;
|
||||||
|
using Webzine.WebApplication.ViewModels.Titre;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialise une nouvelle instance de la classe <see cref="TitreController"/>.
|
/// Controleur responsable de la gestion des titres musicaux :
|
||||||
|
/// affichage des details, filtrage par style,
|
||||||
|
/// ajout de likes, commentaires et recherche.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">Service de journalisation injecte.</param>
|
[Route("titre")]
|
||||||
/// <param name="titreRepository">Repository des titres injecte.</param>
|
public class TitreController : Controller
|
||||||
public TitreController(ILogger<TitreController> logger, ITitreRepository titreRepository)
|
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
private readonly ILogger<TitreController> logger;
|
||||||
this.titreRepository = titreRepository;
|
private readonly ITitreRepository titreRepository;
|
||||||
|
|
||||||
this.logger.LogInformation("Initialisation du controleur TitreController.");
|
/// <summary>
|
||||||
}
|
/// Initialise une nouvelle instance de la classe <see cref="TitreController"/>.
|
||||||
|
/// </summary>
|
||||||
/// <summary>
|
/// <param name="logger">Service de journalisation injecte.</param>
|
||||||
/// Affiche le detail d'un titre specifique.
|
/// <param name="titreRepository">Repository des titres injecte.</param>
|
||||||
/// </summary>
|
public TitreController(ILogger<TitreController> logger, ITitreRepository titreRepository)
|
||||||
/// <param name="id">Identifiant du titre.</param>
|
|
||||||
/// <returns>Vue des details ou 404 si introuvable.</returns>
|
|
||||||
[HttpGet("{id}")]
|
|
||||||
public IActionResult Details(int id)
|
|
||||||
{
|
|
||||||
this.logger.LogInformation("Demande d'affichage du detail pour le titre ID {Id}.", id);
|
|
||||||
|
|
||||||
var titre = this.titreRepository.Find(id);
|
|
||||||
|
|
||||||
if (titre == null)
|
|
||||||
{
|
{
|
||||||
this.logger.LogWarning("Titre avec ID {Id} introuvable.", id);
|
this.logger = logger;
|
||||||
return this.RedirectToAction("Index");
|
this.titreRepository = titreRepository;
|
||||||
|
|
||||||
|
this.logger.LogInformation("Initialisation du controleur TitreController.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var vm = new TitreDetail
|
/// <summary>
|
||||||
|
/// Affiche le detail d'un titre specifique.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Identifiant du titre.</param>
|
||||||
|
/// <returns>Vue des details ou 404 si introuvable.</returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public IActionResult Details(int id)
|
||||||
{
|
{
|
||||||
Details = new TitreContent
|
this.logger.LogInformation("Demande d'affichage du detail pour le titre ID {Id}.", id);
|
||||||
|
|
||||||
|
var titre = this.titreRepository.Find(id);
|
||||||
|
|
||||||
|
if (titre == null)
|
||||||
{
|
{
|
||||||
IdTitre = titre.IdTitre,
|
this.logger.LogWarning("Titre avec ID {Id} introuvable.", id);
|
||||||
Libelle = titre.Libelle,
|
return this.RedirectToAction("Index");
|
||||||
Chronique = titre.Chronique,
|
}
|
||||||
DateSortie = titre.DateSortie,
|
|
||||||
NbLikes = titre.NbLikes,
|
var vm = new TitreDetail
|
||||||
UrlJaquette = titre.UrlJaquette,
|
|
||||||
UrlEcoute = titre.UrlEcoute,
|
|
||||||
ArtisteNom = titre.Artiste.Nom,
|
|
||||||
Styles = titre.Styles,
|
|
||||||
Commentaires = titre.Commentaires,
|
|
||||||
},
|
|
||||||
CommentForm = new TitreComment
|
|
||||||
{
|
{
|
||||||
IdTitre = titre.IdTitre,
|
Details = new TitreContent
|
||||||
},
|
{
|
||||||
};
|
IdTitre = titre.IdTitre,
|
||||||
|
Libelle = titre.Libelle,
|
||||||
|
Chronique = titre.Chronique,
|
||||||
|
DateSortie = titre.DateSortie,
|
||||||
|
NbLikes = titre.NbLikes,
|
||||||
|
UrlJaquette = titre.UrlJaquette,
|
||||||
|
UrlEcoute = titre.UrlEcoute,
|
||||||
|
ArtisteNom = titre.Artiste.Nom,
|
||||||
|
Styles = titre.Styles,
|
||||||
|
Commentaires = titre.Commentaires,
|
||||||
|
},
|
||||||
|
CommentForm = new TitreComment
|
||||||
|
{
|
||||||
|
IdTitre = titre.IdTitre,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
return this.View(vm);
|
return this.View(vm);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Affiche les titres correspondant a un style musical donne.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="style">Nom du style musical.</param>
|
|
||||||
/// <returns>Vue contenant la liste filtree.</returns>
|
|
||||||
[HttpGet("style/{style}")]
|
|
||||||
public IActionResult Style(string style)
|
|
||||||
{
|
|
||||||
this.logger.LogInformation("Recherche des titres pour le style : {Style}.", style);
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
var titresFiltres = this.titreRepository.SearchByStyle(style).ToList();
|
|
||||||
=======
|
|
||||||
var titresFiltres = this._titreRepository.SearchByStyle(style).ToList();
|
|
||||||
>>>>>>> origin/j2/refactor/controler-style-titre
|
|
||||||
|
|
||||||
var vm = new TitreStyle
|
|
||||||
{
|
|
||||||
StyleName = style,
|
|
||||||
Titres = titresFiltres.Select(MapTitreItem).ToList(),
|
|
||||||
};
|
|
||||||
|
|
||||||
return this.View(vm);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ajoute un like a un titre.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="model">Modele contenant l'identifiant du titre.</param>
|
|
||||||
/// <returns>Redirection vers la page detail.</returns>
|
|
||||||
[HttpPost("like")]
|
|
||||||
public IActionResult Like(TitreLike model)
|
|
||||||
{
|
|
||||||
this.logger.LogInformation("Ajout d'un like pour le titre ID {Id}.", model.IdTitre);
|
|
||||||
|
|
||||||
var titre = this.titreRepository.Find(model.IdTitre);
|
|
||||||
|
|
||||||
if (titre == null)
|
|
||||||
{
|
|
||||||
<<<<<<< HEAD
|
|
||||||
this.logger.LogWarning("Impossible d'ajouter un like. Titre ID {Id} introuvable.", model.IdTitre);
|
|
||||||
=======
|
|
||||||
this._logger.LogWarning("Impossible d'ajouter un like. Titre ID {Id} introuvable.", model.IdTitre);
|
|
||||||
>>>>>>> origin/j2/refactor/controler-style-titre
|
|
||||||
return this.RedirectToAction("Index");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
titre.NbLikes++;
|
/// <summary>
|
||||||
|
/// Affiche les titres correspondant a un style musical donne.
|
||||||
return this.RedirectToAction("Details", new { id = model.IdTitre });
|
/// </summary>
|
||||||
}
|
/// <param name="style">Nom du style musical.</param>
|
||||||
|
/// <returns>Vue contenant la liste filtree.</returns>
|
||||||
/// <summary>
|
[HttpGet("style/{style}")]
|
||||||
/// Ajoute un commentaire a un titre.
|
public IActionResult Style(string style)
|
||||||
/// </summary>
|
|
||||||
/// <param name="model">Donnees du commentaire.</param>
|
|
||||||
/// <returns>Redirection vers la page detail.</returns>
|
|
||||||
[HttpPost("comment")]
|
|
||||||
public IActionResult Comment(TitreComment model)
|
|
||||||
{
|
|
||||||
if (!this.ModelState.IsValid)
|
|
||||||
{
|
{
|
||||||
<<<<<<< HEAD
|
this.logger.LogInformation("Recherche des titres pour le style : {Style}.", style);
|
||||||
this.logger.LogWarning("Echec de validation du modele de commentaire pour le titre ID {Id}.", model.IdTitre);
|
|
||||||
=======
|
var titresFiltres = this.titreRepository.SearchByStyle(style).ToList();
|
||||||
this._logger.LogWarning("Echec de validation du modele de commentaire pour le titre ID {Id}.", model.IdTitre);
|
|
||||||
>>>>>>> origin/j2/refactor/controler-style-titre
|
var vm = new TitreStyle
|
||||||
|
{
|
||||||
|
StyleName = style,
|
||||||
|
Titres = titresFiltres.Select(MapTitreItem).ToList(),
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.View(vm);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ajoute un like a un titre.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">Modele contenant l'identifiant du titre.</param>
|
||||||
|
/// <returns>Redirection vers la page detail.</returns>
|
||||||
|
[HttpPost("like")]
|
||||||
|
public IActionResult Like(TitreLike model)
|
||||||
|
{
|
||||||
|
this.logger.LogInformation("Ajout d'un like pour le titre ID {Id}.", model.IdTitre);
|
||||||
|
|
||||||
|
var titre = this.titreRepository.Find(model.IdTitre);
|
||||||
|
|
||||||
|
if (titre == null)
|
||||||
|
{
|
||||||
|
this.logger.LogWarning("Impossible d'ajouter un like. Titre ID {Id} introuvable.", model.IdTitre);
|
||||||
|
return this.RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
titre.NbLikes++;
|
||||||
|
|
||||||
return this.RedirectToAction("Details", new { id = model.IdTitre });
|
return this.RedirectToAction("Details", new { id = model.IdTitre });
|
||||||
}
|
}
|
||||||
|
|
||||||
var titre = this.titreRepository.Find(model.IdTitre);
|
/// <summary>
|
||||||
|
/// Ajoute un commentaire a un titre.
|
||||||
if (titre == null)
|
/// </summary>
|
||||||
|
/// <param name="model">Donnees du commentaire.</param>
|
||||||
|
/// <returns>Redirection vers la page detail.</returns>
|
||||||
|
[HttpPost("comment")]
|
||||||
|
public IActionResult Comment(TitreComment model)
|
||||||
{
|
{
|
||||||
<<<<<<< HEAD
|
if (!this.ModelState.IsValid)
|
||||||
this.logger.LogWarning("Impossible d'ajouter le commentaire. Titre ID {Id} introuvable.", model.IdTitre);
|
{
|
||||||
=======
|
this.logger.LogWarning("Echec de validation du modele de commentaire pour le titre ID {Id}.", model.IdTitre);
|
||||||
this._logger.LogWarning("Impossible d'ajouter le commentaire. Titre ID {Id} introuvable.", model.IdTitre);
|
return this.RedirectToAction("Details", new { id = model.IdTitre });
|
||||||
>>>>>>> origin/j2/refactor/controler-style-titre
|
}
|
||||||
return this.RedirectToAction("Index");
|
|
||||||
|
var titre = this.titreRepository.Find(model.IdTitre);
|
||||||
|
|
||||||
|
if (titre == null)
|
||||||
|
{
|
||||||
|
this.logger.LogWarning("Impossible d'ajouter le commentaire. Titre ID {Id} introuvable.", model.IdTitre);
|
||||||
|
return this.RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
var commentaire = new Commentaire
|
||||||
|
{
|
||||||
|
Auteur = model.Auteur,
|
||||||
|
Contenu = model.Contenu,
|
||||||
|
DateCreation = DateTime.Now,
|
||||||
|
IdTitre = model.IdTitre,
|
||||||
|
};
|
||||||
|
|
||||||
|
titre.Commentaires.Add(commentaire);
|
||||||
|
|
||||||
|
this.logger.LogInformation("Commentaire ajoute avec succes au titre ID {Id}.", model.IdTitre);
|
||||||
|
|
||||||
|
return this.RedirectToAction("Details", new { id = model.IdTitre });
|
||||||
}
|
}
|
||||||
|
|
||||||
var commentaire = new Commentaire
|
private static TitreStyleItem MapTitreItem(Titre titre)
|
||||||
{
|
{
|
||||||
Auteur = model.Auteur,
|
return new TitreStyleItem
|
||||||
Contenu = model.Contenu,
|
{
|
||||||
DateCreation = DateTime.Now,
|
IdTitre = titre.IdTitre,
|
||||||
IdTitre = model.IdTitre,
|
Libelle = titre.Libelle,
|
||||||
};
|
ArtisteNom = titre.Artiste?.Nom,
|
||||||
|
UrlJaquette = titre.UrlJaquette,
|
||||||
titre.Commentaires.Add(commentaire);
|
Duree = titre.Duree,
|
||||||
|
};
|
||||||
this.logger.LogInformation("Commentaire ajoute avec succes au titre ID {Id}.", model.IdTitre);
|
}
|
||||||
|
|
||||||
return this.RedirectToAction("Details", new { id = model.IdTitre });
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TitreStyleItem MapTitreItem(Titre titre)
|
|
||||||
{
|
|
||||||
return new TitreStyleItem
|
|
||||||
{
|
|
||||||
IdTitre = titre.IdTitre,
|
|
||||||
Libelle = titre.Libelle,
|
|
||||||
ArtisteNom = titre.Artiste?.Nom,
|
|
||||||
UrlJaquette = titre.UrlJaquette,
|
|
||||||
Duree = titre.Duree,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Web;
|
using NLog.Web;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Webzine.EntitiesContext;
|
using Webzine.EntitiesContext;
|
||||||
using Webzine.Repository;
|
using Webzine.Repository;
|
||||||
using Webzine.Repository.Contracts;
|
using Webzine.Repository.Contracts;
|
||||||
@@ -21,19 +21,9 @@ try
|
|||||||
// Necessite le package Nuget Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.
|
// Necessite le package Nuget Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.
|
||||||
.AddRazorRuntimeCompilation();
|
.AddRazorRuntimeCompilation();
|
||||||
|
|
||||||
// A utiliser en mode repo
|
|
||||||
|
|
||||||
// builder.Services.AddSingleton<ITitreRepository, LocalEntityRepository>();
|
|
||||||
|
|
||||||
// A utiliser en mode DB
|
|
||||||
builder.Services.AddScoped<ITitreRepository, TitreRepository>();
|
|
||||||
|
|
||||||
builder.Services.AddDbContext<WebzineDbContext>(options =>
|
builder.Services.AddDbContext<WebzineDbContext>(options =>
|
||||||
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
|
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||||
|
|
||||||
// Ajout d'un seeder pour la base de donn<6E>es
|
|
||||||
builder.Services.AddScoped<DbEntityRepository>();
|
|
||||||
|
|
||||||
// NLog: Setup NLog for Dependency injection
|
// NLog: Setup NLog for Dependency injection
|
||||||
builder.Logging.ClearProviders();
|
builder.Logging.ClearProviders();
|
||||||
builder.Host.UseNLog();
|
builder.Host.UseNLog();
|
||||||
@@ -45,17 +35,16 @@ try
|
|||||||
builder.Services.AddScoped<ITitreRepository, DbTitreRepository>();
|
builder.Services.AddScoped<ITitreRepository, DbTitreRepository>();
|
||||||
builder.Services.AddScoped<IStyleRepository, DbStyleRepository>();
|
builder.Services.AddScoped<IStyleRepository, DbStyleRepository>();
|
||||||
builder.Services.AddScoped<IArtisteRepository, DbArtisteRepository>();
|
builder.Services.AddScoped<IArtisteRepository, DbArtisteRepository>();
|
||||||
//builder.Services.AddScoped<ICommentaireRepository, DbCommentaireRepository>();
|
// builder.Services.AddScoped<ICommentaireRepository, DbCommentaireRepository>();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
builder.Services.AddScoped<ITitreRepository, LocalTitreRepository>();
|
builder.Services.AddScoped<ITitreRepository, LocalTitreRepository>();
|
||||||
builder.Services.AddScoped<IStyleRepository, LocalStyleRepository>();
|
builder.Services.AddScoped<IStyleRepository, LocalStyleRepository>();
|
||||||
builder.Services.AddScoped<IArtisteRepository, LocalArtisteRepository>();
|
builder.Services.AddScoped<IArtisteRepository, LocalArtisteRepository>();
|
||||||
//builder.Services.AddScoped<ICommentaireRepository, LocalCommentaireRepository>();
|
// builder.Services.AddScoped<ICommentaireRepository, LocalCommentaireRepository>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// https://learn.microsoft.com/fr-fr/aspnet/core/performance/response-compression?view=aspnetcore-10.0#configuration
|
// https://learn.microsoft.com/fr-fr/aspnet/core/performance/response-compression?view=aspnetcore-10.0#configuration
|
||||||
// Ajoute le service de compression des réponses HTTP pour réduire la taille des données envoyées au client et améliorer les performances de l'application.
|
// Ajoute le service de compression des réponses HTTP pour réduire la taille des données envoyées au client et améliorer les performances de l'application.
|
||||||
builder.Services.AddResponseCompression();
|
builder.Services.AddResponseCompression();
|
||||||
@@ -80,8 +69,6 @@ try
|
|||||||
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
|
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
|
||||||
db.Database.EnsureDeleted();
|
db.Database.EnsureDeleted();
|
||||||
db.Database.EnsureCreated();
|
db.Database.EnsureCreated();
|
||||||
var repo = scope.ServiceProvider.GetRequiredService<DbEntityRepository>();
|
|
||||||
repo.SeedBaseDeDonnees();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Active le middleware permettant le routage des requetes entrantes.
|
// Active le middleware permettant le routage des requetes entrantes.
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
</main>
|
</main>
|
||||||
@if(ViewContext.RouteData.Values["area"]?.ToString() != "Administration")
|
@if(ViewContext.RouteData.Values["area"]?.ToString() != "Administration")
|
||||||
{
|
{
|
||||||
@await Component.InvokeAsync("Sidebar")
|
@await Component.InvokeAsync("Components.Sidebar.Default")
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user