diff --git a/Controllers/CategorieTaskController.cs b/Controllers/CategorieTaskController.cs index 8f8166b..5efe6c2 100644 --- a/Controllers/CategorieTaskController.cs +++ b/Controllers/CategorieTaskController.cs @@ -14,9 +14,10 @@ public class CategorieTaskManagerController : ControllerBase private readonly AppDbContext _context; private readonly CategorieTaskService _categorieTaskService; - public CategorieTaskManagerController(AppDbContext context) + public CategorieTaskManagerController(AppDbContext context, CategorieTaskService categorieTaskService) { _context = context; + _categorieTaskService = categorieTaskService; } [Authorize] diff --git a/Program.cs b/Program.cs index da61ef5..f12a1e0 100644 --- a/Program.cs +++ b/Program.cs @@ -37,6 +37,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); var key = Encoding.ASCII.GetBytes(Settings.Secret); diff --git a/Services/CategorieTaskService.cs b/Services/CategorieTaskService.cs index e5becfd..b1c2f4f 100644 --- a/Services/CategorieTaskService.cs +++ b/Services/CategorieTaskService.cs @@ -51,11 +51,14 @@ public IActionResult UpdateCategorieTask([FromBody] CategorieTaskModel model) { try { - CategorieTaskEntity categorieToUpdate = new() + var categorieToUpdate = _context.CategorieTasks.FirstOrDefault(c => c.Id == model.Id); + if (categorieToUpdate == null) { - Name = model.Name, - Description = model.Description - }; + return NotFound(); + } + + categorieToUpdate.Name = model.Name; + categorieToUpdate.Description = model.Description; _context.CategorieTasks.Update(categorieToUpdate); _context.SaveChanges(); diff --git a/Services/TaskManagerServices.cs b/Services/TaskManagerServices.cs index 9e5f4f4..5453ac3 100644 --- a/Services/TaskManagerServices.cs +++ b/Services/TaskManagerServices.cs @@ -148,21 +148,21 @@ public IActionResult InsertTask (TaskModel model, int userId) public IActionResult EditTask (TaskModel model, int id) { - TaskEntity taskToEdit = context.Tasks.FirstOrDefault(x => x.Id == id); + var taskToEdit = context.Tasks.FirstOrDefault(x => x.Id == id); - if (taskToEdit == null) return new NotFoundResult(); - - taskToEdit = new TaskEntity() + if (taskToEdit == null) { - Title = model.Title, - Description = model.Description - }; + return new NotFoundResult(); + } + + taskToEdit.Title = model.Title; + taskToEdit.Description = model.Description; context.Tasks.Update(taskToEdit); context.SaveChanges(); return Ok(taskToEdit); - } + } public IActionResult DeleteTask (int id) { TaskEntity taskToDelete = context.Tasks.FirstOrDefault(x => x.Id == id);