|
|
|
@ -11,129 +11,6 @@ namespace WF_WebAdmin.Pages
|
|
|
|
|
{
|
|
|
|
|
public partial class ValidQuote
|
|
|
|
|
{
|
|
|
|
|
// Chaîne de connexion à adapter
|
|
|
|
|
private const string connectionString =
|
|
|
|
|
"Host=localhost;Port=5432;Database=wikifantasy3;Username=postgres;Password=postgres";
|
|
|
|
|
|
|
|
|
|
private List<Quote> quotes;
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
// On charge toutes les citations dont isValide = false
|
|
|
|
|
quotes = await LoadNotValidatedQuotesAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Charge toutes les citations non validées (isValide = false)
|
|
|
|
|
/// et mappe les colonnes vers ton modèle.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async Task<List<Quote>> LoadNotValidatedQuotesAsync()
|
|
|
|
|
{
|
|
|
|
|
var result = new List<Quote>();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using var con = new NpgsqlConnection(connectionString);
|
|
|
|
|
await con.OpenAsync();
|
|
|
|
|
|
|
|
|
|
// Sélection des colonnes réellement présentes en DB
|
|
|
|
|
// + placeholders pour les autres
|
|
|
|
|
var sql = @"
|
|
|
|
|
SELECT
|
|
|
|
|
id_quote AS Id,
|
|
|
|
|
content AS Content,
|
|
|
|
|
likes AS ""Like"",
|
|
|
|
|
langue AS Langue,
|
|
|
|
|
-- Champs pas vraiment en DB : placeholders
|
|
|
|
|
'' AS Charac,
|
|
|
|
|
'' AS ImgPath,
|
|
|
|
|
'' AS TitleSrc,
|
|
|
|
|
now() AS DateSrc,
|
|
|
|
|
'' AS UserProposition
|
|
|
|
|
FROM quote
|
|
|
|
|
WHERE isValide = false
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
using var cmd = new NpgsqlCommand(sql, con);
|
|
|
|
|
using var reader = await cmd.ExecuteReaderAsync();
|
|
|
|
|
|
|
|
|
|
while (await reader.ReadAsync())
|
|
|
|
|
{
|
|
|
|
|
var q = new Quote
|
|
|
|
|
{
|
|
|
|
|
Id = reader.GetInt32(reader.GetOrdinal("Id")),
|
|
|
|
|
Content = reader.GetString(reader.GetOrdinal("Content")),
|
|
|
|
|
Like = reader.GetInt32(reader.GetOrdinal("Like")),
|
|
|
|
|
Langue = reader.GetString(reader.GetOrdinal("Langue")),
|
|
|
|
|
// placeholders
|
|
|
|
|
Charac = reader.GetString(reader.GetOrdinal("Charac")),
|
|
|
|
|
ImgPath = reader.GetString(reader.GetOrdinal("ImgPath")),
|
|
|
|
|
TitleSrc = reader.GetString(reader.GetOrdinal("TitleSrc")),
|
|
|
|
|
DateSrc = reader.GetDateTime(reader.GetOrdinal("DateSrc")),
|
|
|
|
|
UserProposition = reader.GetString(reader.GetOrdinal("UserProposition"))
|
|
|
|
|
};
|
|
|
|
|
result.Add(q);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"[Erreur] LoadNotValidatedQuotesAsync : {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Met à jour isValide = true pour la citation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async Task ValiderQuote(int quoteId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using var con = new NpgsqlConnection(connectionString);
|
|
|
|
|
await con.OpenAsync();
|
|
|
|
|
|
|
|
|
|
var sql = "UPDATE quote SET isValide = true WHERE id_quote = @Id";
|
|
|
|
|
using var cmd = new NpgsqlCommand(sql, con);
|
|
|
|
|
cmd.Parameters.AddWithValue("Id", quoteId);
|
|
|
|
|
|
|
|
|
|
int rowsAffected = await cmd.ExecuteNonQueryAsync();
|
|
|
|
|
if (rowsAffected > 0)
|
|
|
|
|
{
|
|
|
|
|
// Supprime la quote de la liste pour l'enlever de l'affichage
|
|
|
|
|
quotes.RemoveAll(q => q.Id == quoteId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"[Erreur] ValiderQuote : {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supprime complètement la citation de la base.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async Task RejeterQuote(int quoteId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using var con = new NpgsqlConnection(connectionString);
|
|
|
|
|
await con.OpenAsync();
|
|
|
|
|
|
|
|
|
|
var sql = "DELETE FROM quote WHERE id_quote = @Id";
|
|
|
|
|
using var cmd = new NpgsqlCommand(sql, con);
|
|
|
|
|
cmd.Parameters.AddWithValue("Id", quoteId);
|
|
|
|
|
|
|
|
|
|
int rowsAffected = await cmd.ExecuteNonQueryAsync();
|
|
|
|
|
if (rowsAffected > 0)
|
|
|
|
|
{
|
|
|
|
|
quotes.RemoveAll(q => q.Id == quoteId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"[Erreur] RejeterQuote : {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|