File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using Microsoft . AspNetCore . Authorization ;
22using Microsoft . AspNetCore . Mvc ;
33using Microsoft . EntityFrameworkCore ;
4+ using Microsoft . IdentityModel . Tokens ;
45using Todo . Data ;
6+ using Todo . Migrations ;
57using Todo . Models ;
8+ using Todo . Services ;
69
710namespace Todo . Controllers
811{
912 [ ApiController ]
1013 public class TaskManagerController : ControllerBase
1114 {
15+ private readonly TaskManagerServices taskManagerServices ;
16+
1217 [ HttpGet ( "/TasksToDo" ) ]
13- public IActionResult Get ( [ FromServices ] AppDbContext context )
18+ public IActionResult Get ( )
1419 {
15-
16- var tasksDone = context . Tasks
17- . Where ( x => x . Done == false )
18- . Select ( task => new
19- {
20- TaskId = task . Id ,
21- TaskTitle = task . Title ,
22- TaskDescription = task . Description ,
23- Done = task . Done ,
24- CreatedAt = task . CreatedAt ,
25- CategoryName = context . CategorieTasks
26- . Where ( category => category . Id == task . CategorieTaskId )
27- . Select ( category => category . Name )
28- . FirstOrDefault ( )
29- } )
30- . ToList ( ) ;
31- return Ok ( tasksDone ) ;
20+ try
21+ {
22+ var tasks = taskManagerServices . GetTasksToDo ( ) ;
23+ return Ok ( tasks ) ;
24+ }
25+ catch ( System . Exception )
26+ {
27+ return BadRequest ( ) ;
28+ }
3229 }
3330
3431 [ HttpGet ( "/ListTaskDone" ) ]
Original file line number Diff line number Diff line change 1+ using Microsoft . AspNetCore . Mvc ;
2+ using Todo . Data ;
3+
4+ namespace Todo . Services
5+ {
6+ public class TaskManagerServices
7+ {
8+ private readonly AppDbContext context ;
9+
10+ public TaskManagerServices ( AppDbContext dbContext )
11+ {
12+ context = dbContext ;
13+ }
14+
15+ public IActionResult GetTasksToDo ( )
16+ {
17+ var tasks = context . Tasks
18+ . Where ( x => x . Done == false )
19+ . Select ( task => new
20+ {
21+ TaskId = task . Id ,
22+ TaskTitle = task . Title ,
23+ TaskDescription = task . Description ,
24+ Done = task . Done ,
25+ CreatedAt = task . CreatedAt ,
26+ CategoryName = context . CategorieTasks
27+ . Where ( category => category . Id == task . CategorieTaskId )
28+ . Select ( category => category . Name )
29+ . FirstOrDefault ( )
30+ } )
31+ . ToList ( ) ;
32+ return new OkObjectResult ( tasks ) ;
33+ }
34+
35+
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments