From 9073f29527f09e5f93f37f2be8785bc8e86fac65 Mon Sep 17 00:00:00 2001 From: "victor.gaborit" Date: Sun, 25 Feb 2024 14:38:46 +0100 Subject: [PATCH] =?UTF-8?q?utilisation=20DeleteItem=20dans=20UserControlle?= =?UTF-8?q?r=20et=20correction=20de=20bug=20car=20DeletItem=20renvoyait=20?= =?UTF-8?q?un=20objet=20non=20serializable=20qui=20provoquait=20une=20erre?= =?UTF-8?q?ur=20500=20cot=C3=A9=20API=20:bug:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_SQLuedo/API/Controllers/UsersController.cs | 2 +- API_SQLuedo/ModelToEntity/DbDataManager.cs | 2 +- API_SQLuedo/ModelToEntity/Extension.cs | 12 ++++++------ API_SQLuedo/Shared/IUserDataService.cs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/API_SQLuedo/API/Controllers/UsersController.cs b/API_SQLuedo/API/Controllers/UsersController.cs index 6a4b462..623360e 100644 --- a/API_SQLuedo/API/Controllers/UsersController.cs +++ b/API_SQLuedo/API/Controllers/UsersController.cs @@ -74,7 +74,7 @@ namespace API.Controllers if(success) { _logger.LogInformation("[INFORMATION] L'utilisateur avec l'id {id} a été supprimé.", id); - return Ok(_dataService.UserService.DeleteUser(id)); + return Ok(_dataService.UserService.DeleteItem(id)); } else { _logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); diff --git a/API_SQLuedo/ModelToEntity/DbDataManager.cs b/API_SQLuedo/ModelToEntity/DbDataManager.cs index c56dcf4..c4640e0 100644 --- a/API_SQLuedo/ModelToEntity/DbDataManager.cs +++ b/API_SQLuedo/ModelToEntity/DbDataManager.cs @@ -12,7 +12,7 @@ using System.Runtime.InteropServices.ObjectiveC; namespace ModelToEntity { - public class DbDataManager : IUserDataService + public class DbDataManager : IUserDataService { public async Task GetUserById(int id) { diff --git a/API_SQLuedo/ModelToEntity/Extension.cs b/API_SQLuedo/ModelToEntity/Extension.cs index 508e872..02c8edd 100644 --- a/API_SQLuedo/ModelToEntity/Extension.cs +++ b/API_SQLuedo/ModelToEntity/Extension.cs @@ -29,23 +29,23 @@ namespace ModelToEntity return Task.FromResult(item); } - internal static async Task DeleteItemAsync(this DbContext context, int? id) where T : class + internal static Task DeleteItemAsync(this DbContext context, int? id) where T : class { if (id == null) { - return false; + return Task.FromResult(false); } - var entity = await context.Set().FindAsync(id); + var entity = context.Set().Find(id); if (entity == null) { - return false; + return Task.FromResult(false); } context.Set().Remove(entity); - await context.SaveChangesAsync(); + context.SaveChanges(); - return true; + return Task.FromResult(true); } internal static Task UpdateItemAsync(this DbContext context, int? id, TDto dto) where T : class diff --git a/API_SQLuedo/Shared/IUserDataService.cs b/API_SQLuedo/Shared/IUserDataService.cs index bf2f2e2..c6c646f 100644 --- a/API_SQLuedo/Shared/IUserDataService.cs +++ b/API_SQLuedo/Shared/IUserDataService.cs @@ -10,7 +10,7 @@ using Model.Business; namespace Services { - public interface IUserDataService : IGenericService where T : class + public interface IUserDataService : IGenericService where T : class { public Task> GetUsers(int page, int number); public Task GetUserById(int id);