Complete setAdmin method

pull/26/head
tomivt 3 months ago
parent 944c620e80
commit 85aeeb061c

@ -97,7 +97,7 @@ else
<div class="divPopup"> <div class="divPopup">
<div class="contentPopup"> <div class="contentPopup">
<p>Êtes-vous sûr de vouloir changer le rôle de cet utilisateur ?</p> <p>Êtes-vous sûr de vouloir changer le rôle de cet utilisateur ?</p>
<button @onclick="() => Admin()">Confirmer</button> <button @onclick="() => setAdmin()">Confirmer</button>
<button @onclick="ClosePopup">Annuler</button> <button @onclick="ClosePopup">Annuler</button>
</div> </div>
</div> </div>

@ -32,8 +32,8 @@ namespace WF_WebAdmin.Pages
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
userService = new UserServiceStub($"fake-dataUsers.json"); userService = new UserServiceStub();
users = await userService.GetUsersJson(); users = await userService.getAllUser();
} }
private async Task OnReadData(DataGridReadDataEventArgs<Quote> e) private async Task OnReadData(DataGridReadDataEventArgs<Quote> e)
@ -49,7 +49,7 @@ namespace WF_WebAdmin.Pages
if (!e.CancellationToken.IsCancellationRequested) if (!e.CancellationToken.IsCancellationRequested)
{ {
totalItem = await userService.getNbUser(); totalItem = await userService.getNbUser();
users = response.ToArray(); users = new List<User>(response.ToArray());
} }
} }
@ -71,16 +71,16 @@ namespace WF_WebAdmin.Pages
{ {
if (userToDelete != null) if (userToDelete != null)
{ {
userService = new UserServiceStub($"fake-dataUsers.json"); userService = new UserServiceStub();
await userService.DeleteUserJson(userToDelete.Id); await userService.removeUser(userToDelete);
ClosePopup(); ClosePopup();
} }
} }
private async Task ModifyUser() private async Task ModifyUser()
{ {
userService = new UserServiceStub($"fake-dataUsers.json"); userService = new UserServiceStub();
await userService.UpdateUserJson(selectedUser); await userService.updateUser(selectedUser);
ClosePopup(); ClosePopup();
} }
@ -102,16 +102,18 @@ namespace WF_WebAdmin.Pages
private async Task Admin() private async Task setAdmin()
{ {
if (!userToAdmin.IsAdmin) if (!userToAdmin.IsAdmin)
{ {
userToAdmin.IsAdmin = true; userToAdmin.IsAdmin = true;
await userService.updateUser(userToAdmin);
ClosePopup(); ClosePopup();
} }
else else
{ {
userToAdmin.IsAdmin = false; userToAdmin.IsAdmin = false;
await userService.updateUser(userToAdmin);
ClosePopup(); ClosePopup();
} }
} }

@ -5,7 +5,7 @@ namespace WF_WebAdmin.Service;
public class UserServiceStub : IUserService public class UserServiceStub : IUserService
{ {
private readonly string _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataUsers.json"); private readonly string _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake_data_users.json");
public async Task saveUsersJson(List<User> users) public async Task saveUsersJson(List<User> users)

@ -3,7 +3,7 @@
"Id": 1, "Id": 1,
"Image": "https://tse4.mm.bing.net/th/id/OIP.fc5TQflh0cbxB1GUeOdk6gHaK8?w=123\u0026h=180\u0026c=7\u0026r=0\u0026o=5\u0026pid=1.7", "Image": "https://tse4.mm.bing.net/th/id/OIP.fc5TQflh0cbxB1GUeOdk6gHaK8?w=123\u0026h=180\u0026c=7\u0026r=0\u0026o=5\u0026pid=1.7",
"Name": "admin", "Name": "admin",
"Email": "admin@gmail.com", "Email": "adminop@gmail.com",
"DateCreation": "2024-12-12T00:00:00", "DateCreation": "2024-12-12T00:00:00",
"IsAdmin": true, "IsAdmin": true,
"Comments": [ "Comments": [
@ -17,15 +17,6 @@
} }
] ]
}, },
{
"Id": 2,
"Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137\u0026h=195\u0026c=7\u0026r=0\u0026o=5\u0026pid=1.7",
"Name": "exploit2",
"Email": "exploit@gmail.com",
"DateCreation": "2024-11-12T00:00:00",
"IsAdmin": true,
"Comments": null
},
{ {
"Id": 3, "Id": 3,
"Image": "https://tse4.mm.bing.net/th/id/OIP.XNQPKwc1OUfvnSO9MsxDYgHaE7?w=202\u0026h=180\u0026c=7\u0026r=0\u0026o=5\u0026pid=1.7", "Image": "https://tse4.mm.bing.net/th/id/OIP.XNQPKwc1OUfvnSO9MsxDYgHaE7?w=202\u0026h=180\u0026c=7\u0026r=0\u0026o=5\u0026pid=1.7",
Loading…
Cancel
Save