|
11 | 11 |
|
12 | 12 | public static class RouteHandlers |
13 | 13 | { |
14 | | - private static Func<IEnumerable<Film>> listFilms; |
| 14 | + public static Func<IEnumerable<Film>> ListFilmsHandler; |
15 | 15 |
|
16 | | - private static Func<int, Film> listFilmById; |
| 16 | + public static Func<int, Film> ListFilmByIdHandler; |
17 | 17 |
|
18 | | - private static Action<int, Film> updateFilm; |
| 18 | + public static Action<int, Film> UpdateFilmHandler; |
19 | 19 |
|
20 | | - private static Action<Film> createFilm; |
| 20 | + public static Action<Film> CreateFilmHandler; |
21 | 21 |
|
22 | | - private static Action<int> deleteFilm; |
| 22 | + public static Action<int> DeleteFilmHandler; |
23 | 23 |
|
24 | 24 | //private static Func<int,Film> getFilmyById = i => new Film { Id = 1, Name = "Pulp Fiction", DirectorId = 1 }; |
25 | 25 |
|
26 | | - public static Func<IEnumerable<Film>> ListFilmsHandler |
| 26 | + static RouteHandlers() |
27 | 27 | { |
28 | | - get => listFilms ?? ListFilmsRoute.Handle; |
29 | | - set => listFilms = value; |
30 | | - } |
31 | | - |
32 | | - public static Func<int, Film> ListFilmBIdHandler |
33 | | - { |
34 | | - get => listFilmById ?? (filmId => ListFilmByIdRoute.Handle( |
35 | | - filmId, |
36 | | - //Write some SQL to get the film |
37 | | - fId => new Film { Id = 1, Name = "Pulp Fiction", DirectorId = 1 }, |
38 | | - //Write some SQL to get the director |
39 | | - dirId => new Director { Name = "Steven Spielberg" }, |
40 | | - //Write some SQL to get the cast |
41 | | - fId => new[] { new CastMember { Name = "John Travolta" }, new CastMember { Name = "Samuel L Jackson" } } |
42 | | - ) |
| 28 | + ListFilmsHandler = () => ListFilmsRoute.Handle(); |
| 29 | + |
| 30 | + ListFilmByIdHandler = filmId => ListFilmByIdRoute.Handle(filmId, |
| 31 | + //Write some SQL to get the film |
| 32 | + fId => new Film { Id = 1, Name = "Pulp Fiction", DirectorId = 1 }, |
| 33 | + //Write some SQL to get the director |
| 34 | + dirId => new Director { Name = "Steven Spielberg" }, |
| 35 | + //Write some SQL to get the cast |
| 36 | + fId => new[] { new CastMember { Name = "John Travolta" }, new CastMember { Name = "Samuel L Jackson" } } |
43 | 37 | ); |
44 | 38 |
|
45 | | - set => listFilmById = value; |
46 | | - } |
47 | | - |
48 | | - public static Action<int, Film> UpdateFilmHandler |
49 | | - { |
50 | | - get => updateFilm ?? ((filmId, film) => UpdateFilmRoute.Handle( |
51 | | - filmId, |
52 | | - film, |
53 | | - () => new Random().Next() % 2 == 0, |
54 | | - fId => new Film { Id = 1, Name = "Pulp Fiction", DirectorId = 1 } |
55 | | - ) |
| 39 | + UpdateFilmHandler = (filmId, film) => UpdateFilmRoute.Handle( |
| 40 | + filmId, |
| 41 | + film, |
| 42 | + () => new Random().Next() % 2 == 0, |
| 43 | + fId => new Film { Id = 1, Name = "Pulp Fiction", DirectorId = 1 } |
56 | 44 | ); |
| 45 | + |
| 46 | + CreateFilmHandler = film => CreateFilmRoute.Handle(film, () => new Random().Next() % 2 == 0); |
57 | 47 |
|
58 | | - set => updateFilm = value; |
59 | | - } |
60 | | - |
61 | | - public static Action<Film> CreateFilmHandler |
62 | | - { |
63 | | - get => createFilm ?? (film => CreateFilmRoute.Handle(film, () => new Random().Next() % 2 == 0)); |
64 | | - set => createFilm = value; |
65 | | - } |
66 | | - |
67 | | - public static Action<int> DeleteFilmHandler |
68 | | - { |
69 | | - get => deleteFilm ?? (id => DeleteFilmRoute.Handle(id, () => new Random().Next() % 2 == 0)); |
70 | | - set => deleteFilm = value; |
| 48 | + DeleteFilmHandler = id => DeleteFilmRoute.Handle(id, () => new Random().Next() % 2 == 0); |
71 | 49 | } |
72 | 50 | } |
73 | 51 | } |
0 commit comments