diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.cs b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs similarity index 96% rename from WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.cs rename to WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs index e913791..27d0084 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs @@ -1,21 +1,21 @@ -using Microsoft.AspNetCore.Components; -using WF_WebAdmin.Model; - -namespace WF_WebAdmin.Pages -{ - public partial class DeleteUser - { - private User[] users; - - [Inject] - public HttpClient Http { get; set; } - - [Inject] - public NavigationManager NavigationManager { get; set; } - - protected override async Task OnInitializedAsync() - { - users = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataUser.json"); - } - } -} +using Microsoft.AspNetCore.Components; +using WF_WebAdmin.Model; + +namespace WF_WebAdmin.Pages +{ + public partial class DeleteUser + { + private User[] users; + + [Inject] + public HttpClient Http { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + protected override async Task OnInitializedAsync() + { + users = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataUser.json"); + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.cs deleted file mode 100644 index b8cd783..0000000 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.AspNetCore.Components; -using WF_WebAdmin.Model; - -namespace WF_WebAdmin.Pages -{ - public partial class ValidQuote - { - private Quote[] quotes; - - [Inject] - public HttpClient Http { get; set; } - - [Inject] - public NavigationManager NavigationManager { get; set; } - - protected override async Task OnInitializedAsync() - { - quotes = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataValidQuote.json"); - } - } -} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor index 595445f..da423b0 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor @@ -1,26 +1,36 @@ @page "/ValidQuote" +@using WF_WebAdmin.Model -@if(quotes != null){ -

Citations non validées

-

Citations en attente de validation:

+

Citations non validées

- @foreach(var quote in quotes) +@if (quotes is null) +{ +

Chargement des citations...

+} +else if (quotes.Count == 0) +{ +

Aucune citation en attente de validation.

+} +else +{ +

Citations en attente de validation :

+ + @foreach (var quote in quotes) {
- -

Identifiant de la citation :@quote.Id

-

Citation:@quote.Content

-

Personnage : @quote.Charac

-

Source : @quote.TitleSrc

-

Langue : @quote.Langue

-

@quote.UserProposition a proposé cette citation

- - +

ID : @quote.Id

+

Contenu : @quote.Content

+

Langue : @quote.Langue

+

Likes : @quote.Like

+ +

Personnage : @quote.Charac

+

Image : @quote.ImgPath

+

Source : @quote.TitleSrc

+

Date de source : @quote.DateSrc.ToShortDateString()

+

Utilisateur proposition : @quote.UserProposition

+ + +
} } - - - - - diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs new file mode 100644 index 0000000..a42112a --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs @@ -0,0 +1,139 @@ +using Microsoft.AspNetCore.Components; +using Npgsql; +using System.Data; +using WF_WebAdmin.Model; +using System.Collections.Generic; +using System; +using System.Threading.Tasks; +using System.Linq; + +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 quotes; + + protected override async Task OnInitializedAsync() + { + // On charge toutes les citations dont isValide = false + quotes = await LoadNotValidatedQuotesAsync(); + } + + /// + /// Charge toutes les citations non validées (isValide = false) + /// et mappe les colonnes vers ton modèle. + /// + private async Task> LoadNotValidatedQuotesAsync() + { + var result = new List(); + + 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; + } + + /// + /// Met à jour isValide = true pour la citation. + /// + 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}"); + } + } + + /// + /// Supprime complètement la citation de la base. + /// + 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}"); + } + } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj b/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj index 9c94761..1f97b88 100644 --- a/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj +++ b/WF-WebAdmin/WF-WebAdmin/WF-WebAdmin.csproj @@ -7,4 +7,8 @@ WF_WebAdmin + + + +