-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGamesController.cs
71 lines (62 loc) · 1.69 KB
/
GamesController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using Microsoft.AspNetCore.Mvc;
namespace testapi.Controllers;
[ApiController]
[Route("[controller]")]
public class GamesController : ControllerBase
{
private static List<Game> games;
// demo has this bellow methods I cant imagine why thoe order would matter though keep it in mind
public class Game{
public int id { get; set; }
public string? teamOneName { get; set; }
public string? teamTwoName { get; set; }
public int winner { get; set; }
}
List<Game> PopulateGames(){
return new List<Game>
{
new Game{
id = 1,
teamOneName="London",
teamTwoName="Cardif",
winner =1
},
new Game{
id = 2,
teamOneName="Leeds",
teamTwoName="London",
winner =2
},
new Game{
id = 3,
teamOneName="London",
teamTwoName="Manchester",
winner =1
},
};
}
private readonly ILogger<GamesController> _logger;
public GamesController(ILogger<GamesController> logger)
{
games = PopulateGames();
_logger = logger;
}
[HttpGet]
public IEnumerable<Game> Get()
{
return games;
}
[HttpDelete]
public IEnumerable<Game> Delete( int id)
{
var game = games.FirstOrDefault(x => x.id == id);
if (game != null) games.Remove(game);
return games;
}
[HttpPost]
public IEnumerable<Game> AddGame(Game game)
{
games.Add(game);
return games;
}
}