|
|
|
@ -1,198 +1,198 @@
|
|
|
|
|
using WF_WebAdmin.Converter;
|
|
|
|
|
using WF_WebAdmin.Model;
|
|
|
|
|
using Npgsql;
|
|
|
|
|
|
|
|
|
|
namespace WF_WebAdmin.Service
|
|
|
|
|
{
|
|
|
|
|
public class QuoteServiceLocal: IQuoteService
|
|
|
|
|
{
|
|
|
|
|
private readonly string? _connectionString = "Host=localhost;Port=5432;Username=loguichard3;Password=Reglisse15.;Database=dbloguichard3";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Asynchronously adds a new quote to the database and returns the corresponding <see cref="QuoteDTO"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">The <see cref="Quote"/> object to be added to the database.</param>
|
|
|
|
|
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result containing the added quote's data.</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method converts the provided <see cref="Quote"/> object into a <see cref="QuoteDTO"/> using <see cref="QuoteExtension"/>.
|
|
|
|
|
/// It then inserts the quote into the PostgreSQL database using a parameterized SQL query with the help of Npgsql.
|
|
|
|
|
/// After successfully inserting the quote, the corresponding <see cref="QuoteDTO"/> is returned to the caller.
|
|
|
|
|
/// Error handling is in place to catch any issues during the database insertion process, with the exception message logged in case of failure.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public async Task<QuoteDTO> AddQuoteAsync(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
|
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
|
|
|
|
|
|
|
|
|
|
// Utilisation de NpgsqlConnection pour PostgreSQL
|
|
|
|
|
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) " +
|
|
|
|
|
"VALUES (@content, @langue, @reason, @source, @character, @user, @img_path)";
|
|
|
|
|
|
|
|
|
|
// Créer une commande Npgsql
|
|
|
|
|
var command = new NpgsqlCommand(commandText, connection);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Ajouter des paramètres à la commande
|
|
|
|
|
command.Parameters.AddWithValue("@content", quote.Content);
|
|
|
|
|
command.Parameters.AddWithValue("@langue", quote.Langue);
|
|
|
|
|
command.Parameters.AddWithValue("@reason", "À vérifier"); // Vous pouvez changer ça si nécessaire
|
|
|
|
|
command.Parameters.AddWithValue("@source", quote.Source);
|
|
|
|
|
command.Parameters.AddWithValue("@character", quote.Character);
|
|
|
|
|
command.Parameters.AddWithValue("@user", quote.User); // Assurez-vous que `quote.User` est correctement défini
|
|
|
|
|
command.Parameters.AddWithValue("@img_path", quote.ImgPath);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Ouvrir la connexion à la base de données
|
|
|
|
|
await connection.OpenAsync();
|
|
|
|
|
|
|
|
|
|
// Exécuter la commande d'insertion
|
|
|
|
|
await command.ExecuteNonQueryAsync();
|
|
|
|
|
}
|
|
|
|
|
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}");
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
// Fermer la connexion (automatiquement géré avec `using`, mais ajouté pour explicitement montrer le processus)
|
|
|
|
|
await connection.CloseAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retourner l'objet DTO pour que vous puissiez l'utiliser ailleurs dans votre application
|
|
|
|
|
return quoteDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Asynchronously handles the removal of a quote and returns the corresponding <see cref="QuoteDTO"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">The <see cref="Quote"/> object to be removed.</param>
|
|
|
|
|
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result corresponding to the removed quote.</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDTO"/> using the
|
|
|
|
|
/// <see cref="QuoteExtension"/>, and then returns the DTO. Note that while this function is named `RemoveQuote`,
|
|
|
|
|
/// it currently only converts the quote to a DTO and does not actually perform any database removal operation.
|
|
|
|
|
/// You may need to implement additional logic to remove the quote from the database.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public Task RemoveQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
|
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
|
|
|
|
|
|
|
|
|
|
// Return the DTO as the result of this asynchronous operation (though no removal logic is currently implemented)
|
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Asynchronously validates a quote and returns the corresponding <see cref="QuoteDTO"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">The <see cref="Quote"/> object to be validated.</param>
|
|
|
|
|
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result corresponding to the validated quote.</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDTO"/> using the
|
|
|
|
|
/// <see cref="QuoteExtension"/>, and returns the DTO. The method is named `validQuote`, but currently, it only
|
|
|
|
|
/// converts the quote into a DTO and does not perform any actual validation logic.
|
|
|
|
|
/// If you intend to validate the quote (e.g., updating its status in a database), you will need to implement
|
|
|
|
|
/// the actual validation logic separately.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public Task validQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
|
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
|
|
|
|
|
|
|
|
|
|
// Return the DTO as the result of this asynchronous operation (though no validation logic is currently implemented)
|
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Asynchronously updates a quote and returns the corresponding <see cref="QuoteDTO"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">The <see cref="Quote"/> object to be updated.</param>
|
|
|
|
|
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result corresponding to the updated quote.</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDTO"/> using the
|
|
|
|
|
/// <see cref="QuoteExtension"/>, and returns the DTO. The method is named `updateQuote`, but currently, it only
|
|
|
|
|
/// converts the quote into a DTO and does not perform any actual update logic.
|
|
|
|
|
/// If you intend to update the quote (e.g., modifying the quote in a database or data source),
|
|
|
|
|
/// you will need to implement the actual update logic separately.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public Task updateQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
|
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
|
|
|
|
|
|
|
|
|
|
// Return the DTO as the result of this asynchronous operation (though no update logic is currently implemented)
|
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Task addQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task removeQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Quote>> getAllQuote()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Quote>> getSomeQuote(int nb, int page)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Quote>> reserchQuote(string reserch, List<string> argument)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Quote>> getAllQuoteInvalid()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Quote>> getSomeQuoteInvalid(int nb, int page)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<Quote> getOnequote(int id)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<int> getNbQuote()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Character>> getChar()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Source>> getSrc()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
using WF_WebAdmin.Converter;
|
|
|
|
|
using WF_WebAdmin.Model;
|
|
|
|
|
using Npgsql;
|
|
|
|
|
|
|
|
|
|
namespace WF_WebAdmin.Service
|
|
|
|
|
{
|
|
|
|
|
public class QuoteServiceLocal: IQuoteService
|
|
|
|
|
{
|
|
|
|
|
private readonly string? _connectionString = "Host=localhost;Port=5432;Username=;Password=;Database=";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Asynchronously adds a new quote to the database and returns the corresponding <see cref="QuoteDTO"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">The <see cref="Quote"/> object to be added to the database.</param>
|
|
|
|
|
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result containing the added quote's data.</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method converts the provided <see cref="Quote"/> object into a <see cref="QuoteDTO"/> using <see cref="QuoteExtension"/>.
|
|
|
|
|
/// It then inserts the quote into the PostgreSQL database using a parameterized SQL query with the help of Npgsql.
|
|
|
|
|
/// After successfully inserting the quote, the corresponding <see cref="QuoteDTO"/> is returned to the caller.
|
|
|
|
|
/// Error handling is in place to catch any issues during the database insertion process, with the exception message logged in case of failure.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public async Task<QuoteDTO> AddQuoteAsync(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
|
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
|
|
|
|
|
|
|
|
|
|
// Utilisation de NpgsqlConnection pour PostgreSQL
|
|
|
|
|
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) " +
|
|
|
|
|
"VALUES (@content, @langue, @reason, @source, @character, @user, @img_path)";
|
|
|
|
|
|
|
|
|
|
// Créer une commande Npgsql
|
|
|
|
|
var command = new NpgsqlCommand(commandText, connection);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Ajouter des paramètres à la commande
|
|
|
|
|
command.Parameters.AddWithValue("@content", quote.Content);
|
|
|
|
|
command.Parameters.AddWithValue("@langue", quote.Langue);
|
|
|
|
|
command.Parameters.AddWithValue("@reason", "À vérifier"); // Vous pouvez changer ça si nécessaire
|
|
|
|
|
command.Parameters.AddWithValue("@source", quote.Source);
|
|
|
|
|
command.Parameters.AddWithValue("@character", quote.Character);
|
|
|
|
|
command.Parameters.AddWithValue("@user", quote.User); // Assurez-vous que `quote.User` est correctement défini
|
|
|
|
|
command.Parameters.AddWithValue("@img_path", quote.ImgPath);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Ouvrir la connexion à la base de données
|
|
|
|
|
await connection.OpenAsync();
|
|
|
|
|
|
|
|
|
|
// Exécuter la commande d'insertion
|
|
|
|
|
await command.ExecuteNonQueryAsync();
|
|
|
|
|
}
|
|
|
|
|
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}");
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
// Fermer la connexion (automatiquement géré avec `using`, mais ajouté pour explicitement montrer le processus)
|
|
|
|
|
await connection.CloseAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retourner l'objet DTO pour que vous puissiez l'utiliser ailleurs dans votre application
|
|
|
|
|
return quoteDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Asynchronously handles the removal of a quote and returns the corresponding <see cref="QuoteDTO"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">The <see cref="Quote"/> object to be removed.</param>
|
|
|
|
|
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result corresponding to the removed quote.</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDTO"/> using the
|
|
|
|
|
/// <see cref="QuoteExtension"/>, and then returns the DTO. Note that while this function is named `RemoveQuote`,
|
|
|
|
|
/// it currently only converts the quote to a DTO and does not actually perform any database removal operation.
|
|
|
|
|
/// You may need to implement additional logic to remove the quote from the database.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public Task RemoveQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
|
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
|
|
|
|
|
|
|
|
|
|
// Return the DTO as the result of this asynchronous operation (though no removal logic is currently implemented)
|
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Asynchronously validates a quote and returns the corresponding <see cref="QuoteDTO"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">The <see cref="Quote"/> object to be validated.</param>
|
|
|
|
|
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result corresponding to the validated quote.</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDTO"/> using the
|
|
|
|
|
/// <see cref="QuoteExtension"/>, and returns the DTO. The method is named `validQuote`, but currently, it only
|
|
|
|
|
/// converts the quote into a DTO and does not perform any actual validation logic.
|
|
|
|
|
/// If you intend to validate the quote (e.g., updating its status in a database), you will need to implement
|
|
|
|
|
/// the actual validation logic separately.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public Task validQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
|
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
|
|
|
|
|
|
|
|
|
|
// Return the DTO as the result of this asynchronous operation (though no validation logic is currently implemented)
|
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Asynchronously updates a quote and returns the corresponding <see cref="QuoteDTO"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">The <see cref="Quote"/> object to be updated.</param>
|
|
|
|
|
/// <returns>A task representing the asynchronous operation, with a <see cref="QuoteDTO"/> result corresponding to the updated quote.</returns>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This method takes a <see cref="Quote"/> object, converts it into a <see cref="QuoteDTO"/> using the
|
|
|
|
|
/// <see cref="QuoteExtension"/>, and returns the DTO. The method is named `updateQuote`, but currently, it only
|
|
|
|
|
/// converts the quote into a DTO and does not perform any actual update logic.
|
|
|
|
|
/// If you intend to update the quote (e.g., modifying the quote in a database or data source),
|
|
|
|
|
/// you will need to implement the actual update logic separately.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public Task updateQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
QuoteExtension extension = new QuoteExtension();
|
|
|
|
|
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
|
|
|
|
|
|
|
|
|
|
// Return the DTO as the result of this asynchronous operation (though no update logic is currently implemented)
|
|
|
|
|
return Task.FromResult(quoteDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Task addQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task removeQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Quote>> getAllQuote()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Quote>> getSomeQuote(int nb, int page)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Quote>> reserchQuote(string reserch, List<string> argument)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Quote>> getAllQuoteInvalid()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Quote>> getSomeQuoteInvalid(int nb, int page)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<Quote> getOnequote(int id)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<int> getNbQuote()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Character>> getChar()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<List<Source>> getSrc()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|