|
|
@ -4,29 +4,30 @@ using Npgsql;
|
|
|
|
|
|
|
|
|
|
|
|
namespace WF_WebAdmin.Service
|
|
|
|
namespace WF_WebAdmin.Service
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Service de gestion des citations utilisant une base de données PostgreSQL.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public class QuoteServiceLocal : IQuoteService
|
|
|
|
public class QuoteServiceLocal : IQuoteService
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly string? _connectionString = "Host=localhost;Port=5432;Username=loguichard3;Password=Reglisse15.;Database=dbloguichard3";
|
|
|
|
private readonly string? _connectionString = "Host=localhost;Port=5432;Username=loguichard3;Password=Reglisse15.;Database=dbloguichard3";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Ajoute une nouvelle citation à la base de données PostgreSQL.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="quote">Citation à ajouter.</param>
|
|
|
|
|
|
|
|
/// <returns>Un objet <see cref="QuoteDTO"/> représentant la citation ajoutée.</returns>
|
|
|
|
public async Task<QuoteDTO> AddQuoteAsync(Quote quote)
|
|
|
|
public async Task<QuoteDTO> AddQuoteAsync(Quote quote)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
|
|
|
|
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
|
|
|
|
|
|
|
|
|
|
|
|
// Utilisation de NpgsqlConnection pour PostgreSQL
|
|
|
|
|
|
|
|
using (var connection = new NpgsqlConnection(_connectionString))
|
|
|
|
using (var connection = new NpgsqlConnection(_connectionString))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Définir la requête SQL d'insertion
|
|
|
|
|
|
|
|
var commandText = "INSERT INTO Quote (content, langue, reason, id_source, id_caracter, id_user_verif, img_path) " +
|
|
|
|
var commandText = "INSERT INTO Quote (content, langue, reason, id_source, id_caracter, id_user_verif, img_path) " +
|
|
|
|
"VALUES (@content, @langue, @reason, @source, @character, @user, @img_path)";
|
|
|
|
"VALUES (@content, @langue, @reason, @source, @character, @user, @img_path)";
|
|
|
|
|
|
|
|
|
|
|
|
// Créer une commande Npgsql
|
|
|
|
|
|
|
|
var command = new NpgsqlCommand(commandText, connection);
|
|
|
|
var command = new NpgsqlCommand(commandText, connection);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
// Ajouter des paramètres à la commande
|
|
|
|
// Ajouter des paramètres à la commande
|
|
|
|
command.Parameters.AddWithValue("@content", quote.Content);
|
|
|
|
command.Parameters.AddWithValue("@content", quote.Content);
|
|
|
@ -38,32 +39,28 @@ namespace WF_WebAdmin.Service
|
|
|
|
command.Parameters.AddWithValue("@img_path", quote.ImgPath);
|
|
|
|
command.Parameters.AddWithValue("@img_path", quote.ImgPath);
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Ouvrir la connexion à la base de données
|
|
|
|
|
|
|
|
await connection.OpenAsync();
|
|
|
|
await connection.OpenAsync();
|
|
|
|
|
|
|
|
|
|
|
|
// Exécuter la commande d'insertion
|
|
|
|
|
|
|
|
await command.ExecuteNonQueryAsync();
|
|
|
|
await command.ExecuteNonQueryAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Gérer les erreurs ici (par exemple, afficher ou enregistrer les erreurs)
|
|
|
|
|
|
|
|
Console.WriteLine($"Une erreur est survenue lors de l'ajout de la citation : {ex.Message}");
|
|
|
|
Console.WriteLine($"Une erreur est survenue lors de l'ajout de la citation : {ex.Message}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Fermer la connexion (automatiquement géré avec `using`, mais ajouté pour explicitement montrer le processus)
|
|
|
|
|
|
|
|
await connection.CloseAsync();
|
|
|
|
await connection.CloseAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Retourner l'objet DTO pour que vous puissiez l'utiliser ailleurs dans votre application
|
|
|
|
|
|
|
|
return quoteDTO;
|
|
|
|
return quoteDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Supprime une citation de la base de données.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="quote">Citation à supprimer.</param>
|
|
|
|
public Task RemoveQuote(Quote quote)
|
|
|
|
public Task RemoveQuote(Quote quote)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
@ -72,6 +69,10 @@ namespace WF_WebAdmin.Service
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Valide une citation.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="quote">Citation à valider.</param>
|
|
|
|
public Task validQuote(Quote quote)
|
|
|
|
public Task validQuote(Quote quote)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
@ -80,6 +81,10 @@ namespace WF_WebAdmin.Service
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Met à jour une citation existante.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="quote">Citation mise à jour.</param>
|
|
|
|
public Task updateQuote(Quote quote)
|
|
|
|
public Task updateQuote(Quote quote)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
@ -88,61 +93,89 @@ namespace WF_WebAdmin.Service
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Ajoute une citation (non implémenté).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Task addQuote(Quote quote)
|
|
|
|
public Task addQuote(Quote quote)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Supprime une citation (non implémenté).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public Task removeQuote(Quote quote)
|
|
|
|
public Task removeQuote(Quote quote)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Récupère toutes les citations (non implémenté).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public Task<List<Quote>> getAllQuote()
|
|
|
|
public Task<List<Quote>> getAllQuote()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Récupère un ensemble de citations paginées (non implémenté).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public Task<List<Quote>> getSomeQuote(int nb, int page)
|
|
|
|
public Task<List<Quote>> getSomeQuote(int nb, int page)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Recherche des citations selon des critères spécifiques (non implémenté).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public Task<List<Quote>> reserchQuote(string reserch, List<string> argument)
|
|
|
|
public Task<List<Quote>> reserchQuote(string reserch, List<string> argument)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Récupère toutes les citations invalides (non implémenté).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public Task<List<Quote>> getAllQuoteInvalid()
|
|
|
|
public Task<List<Quote>> getAllQuoteInvalid()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Récupère une liste paginée de citations invalides (non implémenté).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public Task<List<Quote>> getSomeQuoteInvalid(int nb, int page)
|
|
|
|
public Task<List<Quote>> getSomeQuoteInvalid(int nb, int page)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Récupère une citation spécifique en fonction de son ID (non implémenté).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public Task<Quote> getOnequote(int id)
|
|
|
|
public Task<Quote> getOnequote(int id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Récupère le nombre total de citations enregistrées (non implémenté).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public Task<int> getNbQuote()
|
|
|
|
public Task<int> getNbQuote()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Récupère la liste des personnages (non implémenté).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public Task<List<Character>> getChar()
|
|
|
|
public Task<List<Character>> getChar()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Récupère la liste des sources (non implémenté).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public Task<List<Source>> getSrc()
|
|
|
|
public Task<List<Source>> getSrc()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
throw new NotImplementedException();
|
|
|
|