e) { + if (e.CancellationToken.IsCancellationRequested) + { + return; + } + + var response = await userService.getSomeUser(e.PageSize, e.Page); + + if (!e.CancellationToken.IsCancellationRequested) + { + totalItem = await userService.getNbUser(); + users = response.ToArray(); + } } // ------- Popup remove user ------- diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor new file mode 100644 index 0000000..5f59560 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor @@ -0,0 +1,5 @@ +@page "/edit/{Id:int}" + +Editer
+ +My parameter: @Id\ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs new file mode 100644 index 0000000..4d09214 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Edit.razor.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Components; +using WF_WebAdmin.Model; + +namespace WF_WebAdmin.Pages +{ + public partial class Edit + { + [Parameter] + public int Id { get; set; } + + private QuoteModel quoteModel = new(); + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor index cb8f955..ee6cebd 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor @@ -7,11 +7,12 @@Ajouter une recherche
-@if (quotes != null) -{- - @* @@ -20,19 +21,9 @@ - - @pagination -*@ - - if (pages == 1) - { - - - -...
- - - } -} \ No newline at end of file ++ + \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs index 3fecd73..155481b 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor.cs @@ -1,5 +1,5 @@ +using Blazorise.DataGrid; using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Mvc.RazorPages; using WF_WebAdmin.Model; using WF_WebAdmin.Service; @@ -11,46 +11,26 @@ namespace WF_WebAdmin.Pages private int MaxValue = 5; - private int pages = 1; - - private int maxPage; - - private RenderFragment pagination; + private int totalItem; [Inject] public IQuoteService QuoteService { get; set; } - protected override async Task OnInitializedAsync() + private async Task OnReadData(DataGridReadDataEventArgs+ Editer + +e) { - maxPage = await QuoteService.getNbQuote() / MaxValue; - if(maxPage * MaxValue != await QuoteService.getNbQuote()) - maxPage += 1; - ListquotesList = await QuoteService.getSomeQuote(MaxValue, pages); - quotes = quotesList.ToArray(); - } + if (e.CancellationToken.IsCancellationRequested) + { + return; + } - protected async Task pageSuivante() - { - pages += 1; - ListquotesList = await QuoteService.getSomeQuote(MaxValue, pages); - quotes = quotesList.ToArray(); - } - protected async Task pagePrecedente() - { - if (pages > 1) + var response = await QuoteService.getSomeQuote(e.PageSize, e.Page); + + if (!e.CancellationToken.IsCancellationRequested) { - pages -= 1; - ListquotesList = await QuoteService.getSomeQuote(MaxValue, pages); - quotes = quotesList.ToArray(); + totalItem = await QuoteService.getNbQuote(); + quotes = response.ToArray(); } } - - protected async Task pageNumero(int page) - { - this.pages = page; - ListquotesList = await QuoteService.getSomeQuote(MaxValue, this.pages); - quotes = quotesList.ToArray(); - } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Service/IUserService.cs b/WF-WebAdmin/WF-WebAdmin/Service/IUserService.cs index 3a505f4..7357e21 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/IUserService.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/IUserService.cs @@ -4,18 +4,22 @@ namespace WF_WebAdmin.Service { public interface IUserService { - public void removeUserJs(User user); + public Task removeUser(User user); - public void updateRole(User user); + public Task updateRole(User user); - public void downgradeRole(User user); + public Task downgradeRole(User user); - public ListgetAllUser(); + public Task updateUser(User user); - public List getSomeUser(int nb, int page); + public Task > getAllUser(); - public User getOneUser(int id); + public Task
> getSomeUser(int nb, int page); - public List
reserchUsers(string reserch, List args); + public Task getOneUser(int id); + + public Task > reserchUsers(string reserch, List
args); + + public Task getNbUser(); } } diff --git a/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs index bc34fbd..9dfd7fb 100644 --- a/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs +++ b/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs @@ -3,62 +3,95 @@ using WF_WebAdmin.Model; namespace WF_WebAdmin.Service; -public class UserServiceStub : IUserServiceJson +public class UserServiceStub : IUserService { - private readonly string _jsonFilePath; - - public UserServiceStub(string filePath) - { - _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", filePath); - } - - public async Task > GetUsersJson() - { - if (!File.Exists(_jsonFilePath)) - { - Console.Out.WriteLine($"{_jsonFilePath} not found"); - return new List
(); - } - - var json = await File.ReadAllTextAsync(_jsonFilePath); - return JsonSerializer.Deserialize >(json) ?? new List
(); - } - - public async Task SaveUsersJson(List users) + private readonly string _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataUsers.json"); + + + public async Task saveUsersJson(List users) { var json = JsonSerializer.Serialize(users, new JsonSerializerOptions { WriteIndented = true }); await File.WriteAllTextAsync(_jsonFilePath, json); - } - - public async Task AddUserJson(User user) - { - var data = await GetUsersJson(); - user.Id = data.Count > 0 ? data.Max(p => p.Id) + 1 : 1; - data.Add(user); - await SaveUsersJson(data); - } - - public async Task DeleteUserJson(int id) - { - var data = await GetUsersJson(); - var person = data.FirstOrDefault(p => p.Id == id); - if (person != null) - { - data.Remove(person); - await SaveUsersJson(data); - } - } - - public async Task UpdateUserJson(User user) - { - var data = await GetUsersJson(); - var person = data.FirstOrDefault(p => p.Id == user.Id); - if (person != null) - { - person.Name = user.Name; - person.Email = user.Email; - person.Image = user.Image; - await SaveUsersJson(data); - } - } + } + + public async Task removeUser(User user) + { + var data = await getAllUser(); + var u = data.FirstOrDefault(p => p.Id == user.Id); + if (u != null) + { + data.Remove(u); + await saveUsersJson(data); + } + } + + public Task updateRole(User user) + { + user.IsAdmin = true; + return updateUser(user); + } + + public Task downgradeRole(User user) + { + user.IsAdmin = false; + return updateUser(user); + } + + public async Task > getAllUser() + { + if (!File.Exists(_jsonFilePath)) + { + Console.Out.WriteLine($"{_jsonFilePath} not found"); + return new List
(); + } + + var json = await File.ReadAllTextAsync(_jsonFilePath); + return JsonSerializer.Deserialize >(json) ?? new List
(); + } + + public async Task > getSomeUser(int nb, int page) + { + var users = await getAllUser(); + if ((page - 1) * nb + nb > users.Count()) + { + return users.GetRange(users.Count() - nb, nb); + } + return users.GetRange((page - 1) * nb, nb); + } + + public async Task
getOneUser(int id) + { + var data = await getAllUser(); + var u = data.FirstOrDefault(p => p.Id == id); + if (u != null) + { + return u; + } + return null; + } + + public Task > reserchUsers(string reserch, List
args) + { + throw new NotImplementedException(); + } + + public async Task getNbUser() + { + var data = await getAllUser(); + return data.Count; + } + + public async Task updateUser(User user) + { + var data = await getAllUser(); + var person = data.FirstOrDefault(p => p.Id == user.Id); + if (person != null) + { + person.Name = user.Name; + person.Email = user.Email; + person.Image = user.Image; + person.IsAdmin = user.IsAdmin; + await saveUsersJson(data); + } + } } \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataQuote.json b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataQuote.json index 39d4bd4..c10c1ca 100644 --- a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataQuote.json +++ b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataQuote.json @@ -1,112 +1,242 @@ [ { - "id_quote": "1", - "content": "Dans le monde il n’y a pas d’un côté le bien et le mal, il y a une part de lumière et d’ombre en chacun de nous. Ce qui compte c’est celle que l’on choisit de montrer dans nos actes, ça c’est ce que l’on est vraiment.", - "likes": 0, - "langue": "fr", - "isValide": true, - "reason": "insertion de test", - "id_caracter": 50, - "id_source": 38, - "id_user_verif": 1 - }, - { - "id_quote": "22", - "content": "Nous avons parié, mon père et moi. Je ne crois pas que tu tiendras dix minutes dans ce tournoi. Lui, il n’est pas d’accord, il croit que tu n’en tiendras pas cinq.", - "likes": 0, - "langue": "fr", - "isValide": true, - "reason": "insertion de test", - "id_caracter": 7, - "id_source": 58, - "id_user_verif": 1 - }, - { - "id_quote": "45", - "content": "Je vous aurais suivi mon frère, mon capitaine, mon roi.", - "likes": 0, - "langue": "fr", - "isValide": true, - "reason": "insertion de test", - "id_caracter": 77, - "id_source": 76, - "id_user_verif": 1 - }, - { - "id_quote": "90", - "content": "Si vous le voulez bien, on se taillera des pipes plus tard, les enfants.", - "likes": 0, - "langue": "fr", - "isValide": true, - "reason": "insertion de test", - "id_caracter": 82, - "id_source": 9, - "id_user_verif": 1 - }, - { - "id_quote": "91", - "content": "Je fais le mort dans la 5e.", - "likes": 0, - "langue": "fr", - "isValide": true, - "reason": "insertion de test", - "id_caracter": 53, - "id_source": 9, - "id_user_verif": 1 - }, - { - "id_quote": "110", - "content": "Il les a tuées avec leur amour. C’est comme ça tous les jours dans le monde entier.", - "likes": 0, - "langue": "fr", - "isValide": true, - "reason": "insertion de test", - "id_caracter": 34, - "id_source": 74, - "id_user_verif": 1 - }, - { - "id_quote": "118", - "content": "La vengeance est un déesse dévorante. Eux aussi en sont victimes… Je ne dois pas céder à son appel. La justice finira par triompher.", - "likes": 0, - "langue": "fr", - "isValide": false, - "reason": "insertion de test", - "id_caracter": 44, - "id_source": 30, - "id_user_verif": 1 - }, - { - "id_quote": "185", - "content": "Tu viens de me montrer au complet ?!", - "likes": 0, - "langue": "fr", - "isValide": false, - "reason": "insertion de test", - "id_caracter": 38, - "id_source": 10, - "id_user_verif": 1 - }, - { - "id_quote": "182", - "content": "Nouille ou pas nouille, tu te préoccupes trop de ce qui a été ou de ce qui sera.", - "likes": 0, - "langue": "fr", - "isValide": false, - "reason": "insertion de test", - "id_caracter": 29, - "id_source": 71, - "id_user_verif": 1 - }, - { - "id_quote": "175", - "content": "Arrête de faire ton Jean-Jacques !", - "likes": 0, - "langue": "fr", - "isValide": false, - "reason": "insertion de test", - "id_caracter": 39, - "id_source": 68, - "id_user_verif": 1 + "Id": 1, + "Content": "Que la force soit avec toi.", + "Like": 150, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://starwars.com", + "TitleSrc": "Star Wars", + "DateSrc": "2025-01-21", + "UserProposition": "user1", + "isValide": true + }, + { + "Id": 2, + "Content": "Il n’y a pas de place comme chez soi.", + "Like": 120, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://wizardofoz.com", + "TitleSrc": "Le Magicien d'Oz", + "DateSrc": "2025-01-21", + "UserProposition": "user2", + "isValide": true + }, + { + "Id": 3, + "Content": "C'est le choix qui fait l'homme, non le destin.", + "Like": 90, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://harrypotter.com", + "TitleSrc": "Harry Potter et la Chambre des Secrets", + "DateSrc": "2025-01-21", + "UserProposition": "user3", + "isValide": true + }, + { + "Id": 4, + "Content": "La magie, c’est de croire en soi, c’est ça la magie.", + "Like": 75, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://disney.com", + "TitleSrc": "La Belle et la Bête", + "DateSrc": "2025-01-21", + "UserProposition": "user4", + "isValide": true + }, + { + "Id": 5, + "Content": "La vérité est plus étrange que la fiction.", + "Like": 65, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://theimaginarium.com", + "TitleSrc": "L'Imaginarium du Docteur Parnassus", + "DateSrc": "2025-01-21", + "UserProposition": "user5", + "isValide": true + }, + { + "Id": 6, + "Content": "Un homme qui ne croit pas aux miracles n’est pas un homme.", + "Like": 85, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://theprinceofpersia.com", + "TitleSrc": "Prince of Persia : Les Sables du Temps", + "DateSrc": "2025-01-21", + "UserProposition": "user6", + "isValide": true + }, + { + "Id": 7, + "Content": "La seule limite à notre réalisation de demain sera nos doutes et hésitations d’aujourd’hui.", + "Like": 100, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://backtothefuture.com", + "TitleSrc": "Retour vers le futur", + "DateSrc": "2025-01-21", + "UserProposition": "user7", + "isValide": true + }, + { + "Id": 8, + "Content": "L’imagination est plus importante que la connaissance.", + "Like": 200, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://inceptionmovie.com", + "TitleSrc": "Inception", + "DateSrc": "2025-01-21", + "UserProposition": "user8", + "isValide": true + }, + { + "Id": 9, + "Content": "Ce n’est pas de la magie, c’est de la science, mais on ne comprend pas encore tout.", + "Like": 110, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://doctorstrange.com", + "TitleSrc": "Doctor Strange", + "DateSrc": "2025-01-21", + "UserProposition": "user9", + "isValide": true + }, + { + "Id": 10, + "Content": "L’important ce n’est pas d’être parfait, c’est d’être vrai.", + "Like": 130, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://narnia.com", + "TitleSrc": "Le Monde de Narnia", + "DateSrc": "2025-01-21", + "UserProposition": "user10", + "isValide": true + }, + { + "Id": 11, + "Content": "Vous ne pouvez pas vivre sans causer de dommages à quelqu'un d'autre.", + "Like": 110, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://thematrix.com", + "TitleSrc": "The Matrix", + "DateSrc": "2025-01-21", + "UserProposition": "user11", + "isValide": true + }, + { + "Id": 12, + "Content": "Les rêves, ils ne peuvent pas vous mentir.", + "Like": 80, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://peterpanmovie.com", + "TitleSrc": "Peter Pan", + "DateSrc": "2025-01-21", + "UserProposition": "user12", + "isValide": true + }, + { + "Id": 13, + "Content": "Tous les hommes meurent, mais pas tous vivent.", + "Like": 95, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://braveheart.com", + "TitleSrc": "Braveheart", + "DateSrc": "2025-01-21", + "UserProposition": "user13", + "isValide": true + }, + { + "Id": 14, + "Content": "La vie, c’est ce qui nous arrive quand on est occupé à faire d’autres projets.", + "Like": 140, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://forrestgump.com", + "TitleSrc": "Forrest Gump", + "DateSrc": "2025-01-21", + "UserProposition": "user14", + "isValide": true + }, + { + "Id": 15, + "Content": "Il faut toujours croire en l’impossible, sinon la magie disparaît.", + "Like": 60, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://harrypotter.com", + "TitleSrc": "Harry Potter à l'école des sorciers", + "DateSrc": "2025-01-21", + "UserProposition": "user15", + "isValide": true + }, + { + "Id": 16, + "Content": "Le pouvoir de l’imaginaire est plus fort que tout.", + "Like": 120, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://theincrediblesmovie.com", + "TitleSrc": "Les Indestructibles", + "DateSrc": "2025-01-21", + "UserProposition": "user16", + "isValide": true + }, + { + "Id": 17, + "Content": "On peut conquérir l’univers en une journée si on travaille ensemble.", + "Like": 130, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://guardiansofthegalaxy.com", + "TitleSrc": "Les Gardiens de la Galaxie", + "DateSrc": "2025-01-21", + "UserProposition": "user17", + "isValide": true + }, + { + "Id": 18, + "Content": "La véritable magie vient de l’intérieur.", + "Like": 75, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://maleficentmovie.com", + "TitleSrc": "Maléfique", + "DateSrc": "2025-01-21", + "UserProposition": "user18", + "isValide": true + }, + { + "Id": 19, + "Content": "On ne voit bien qu’avec le cœur.", + "Like": 200, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://lepetitprince.com", + "TitleSrc": "Le Petit Prince", + "DateSrc": "2025-01-21", + "UserProposition": "user19", + "isValide": true + }, + { + "Id": 20, + "Content": "Les étoiles sont des rêves en attente d’être vécus.", + "Like": 85, + "Langue": "fr", + "Charac": "test", + "ImgPath": "http://interstellar.com", + "TitleSrc": "Interstellar", + "DateSrc": "2025-01-21", + "UserProposition": "user20", + "isValide": true } -] \ No newline at end of file +]