Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Controllers/CategorieTaskController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

builder.Services.AddScoped<TaskManagerServices>();
builder.Services.AddScoped<LoginService>();
builder.Services.AddScoped<CategorieTaskService>();


var key = Encoding.ASCII.GetBytes(Settings.Secret);
Expand Down
11 changes: 7 additions & 4 deletions Services/CategorieTaskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions Services/TaskManagerServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down