Skip to content

Commit efa6e37

Browse files
Merge pull request #4 from Task-Manager-Pro/codex/encontrar-e-corrigir-bug-no-código
Fix CategorieTask service injection and update logic
2 parents ebaf561 + 0f55b15 commit efa6e37

4 files changed

Lines changed: 18 additions & 13 deletions

File tree

Controllers/CategorieTaskController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ public class CategorieTaskManagerController : ControllerBase
1414
private readonly AppDbContext _context;
1515
private readonly CategorieTaskService _categorieTaskService;
1616

17-
public CategorieTaskManagerController(AppDbContext context)
17+
public CategorieTaskManagerController(AppDbContext context, CategorieTaskService categorieTaskService)
1818
{
1919
_context = context;
20+
_categorieTaskService = categorieTaskService;
2021
}
2122

2223
[Authorize]

Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
builder.Services.AddScoped<TaskManagerServices>();
3939
builder.Services.AddScoped<LoginService>();
40+
builder.Services.AddScoped<CategorieTaskService>();
4041

4142

4243
var key = Encoding.ASCII.GetBytes(Settings.Secret);

Services/CategorieTaskService.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ public IActionResult UpdateCategorieTask([FromBody] CategorieTaskModel model)
5151
{
5252
try
5353
{
54-
CategorieTaskEntity categorieToUpdate = new()
54+
var categorieToUpdate = _context.CategorieTasks.FirstOrDefault(c => c.Id == model.Id);
55+
if (categorieToUpdate == null)
5556
{
56-
Name = model.Name,
57-
Description = model.Description
58-
};
57+
return NotFound();
58+
}
59+
60+
categorieToUpdate.Name = model.Name;
61+
categorieToUpdate.Description = model.Description;
5962

6063
_context.CategorieTasks.Update(categorieToUpdate);
6164
_context.SaveChanges();

Services/TaskManagerServices.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,21 @@ public IActionResult InsertTask (TaskModel model, int userId)
148148

149149
public IActionResult EditTask (TaskModel model, int id)
150150
{
151-
TaskEntity taskToEdit = context.Tasks.FirstOrDefault(x => x.Id == id);
151+
var taskToEdit = context.Tasks.FirstOrDefault(x => x.Id == id);
152152

153-
if (taskToEdit == null) return new NotFoundResult();
154-
155-
taskToEdit = new TaskEntity()
153+
if (taskToEdit == null)
156154
{
157-
Title = model.Title,
158-
Description = model.Description
159-
};
155+
return new NotFoundResult();
156+
}
157+
158+
taskToEdit.Title = model.Title;
159+
taskToEdit.Description = model.Description;
160160

161161
context.Tasks.Update(taskToEdit);
162162
context.SaveChanges();
163163

164164
return Ok(taskToEdit);
165-
}
165+
}
166166
public IActionResult DeleteTask (int id)
167167
{
168168
TaskEntity taskToDelete = context.Tasks.FirstOrDefault(x => x.Id == id);

0 commit comments

Comments
 (0)