1
1
using System . ComponentModel . DataAnnotations ;
2
2
using System . Drawing ;
3
+ using System . Reflection ;
4
+ using System . Text . Json ;
5
+ using System . Text . Json . Serialization ;
3
6
using MicroPlumberd . Services ;
4
7
5
8
namespace MicroPlumberd . Examples . Cinema . Scheduler
@@ -8,14 +11,15 @@ namespace MicroPlumberd.Examples.Cinema.Scheduler
8
11
public partial class ScheduleCommandHandler ( IPlumber plumber )
9
12
{
10
13
[ ThrowsFaultException < ScreeningTimeCannotBeInPast > ]
11
- public async Task Handle ( Guid id , DefineScreening cmd )
14
+ public async Task Handle ( Guid id , PathScreening cmd )
12
15
{
13
16
if ( cmd . Date . IsDefined && cmd . Time . IsDefined )
14
- if ( cmd . Date . Value . ToDateTime ( cmd . Time . Value ) < DateTime . Now )
15
- throw new FaultException < ScreeningTimeCannotBeInPast > ( new ScreeningTimeCannotBeInPast ( ) ) ;
17
+ if ( cmd . Date . Value . ToDateTime ( cmd . Time . Value ) < DateTime . Now )
18
+ throw new FaultException < ScreeningTimeCannotBeInPast > ( new ScreeningTimeCannotBeInPast ( ) ) ;
16
19
17
-
18
- ScreeningStateDefined state = await plumber . GetState < ScreeningStateDefined > ( id ) ;
20
+
21
+ ScreeningStateDefined state = await plumber . GetState < ScreeningStateDefined > ( id ) ?? throw new Exception ( ) ;
22
+
19
23
if ( cmd . SeatConfiguration . IsDefined )
20
24
{
21
25
SeatRoomConfiguration conf = cmd . SeatConfiguration ;
@@ -36,7 +40,7 @@ public async Task Handle(Guid id, DefineScreening cmd)
36
40
if ( cmd . Date . IsDefined )
37
41
state . When = cmd . Date . Value . ToDateTime ( TimeOnly . MinValue ) . Add ( state . When . TimeOfDay ) ;
38
42
39
- // await plumber.AppendState(state);
43
+ await plumber . AppendState ( state ) ;
40
44
}
41
45
}
42
46
@@ -47,28 +51,29 @@ public class ScreeningTimeCannotBeInPast
47
51
}
48
52
49
53
public readonly record struct SeatLocation ( ushort Row , ushort Seat ) ;
50
-
51
- public readonly record struct Property < T >
52
- {
53
- public T Value { get ; init ; }
54
- public static implicit operator T ( Property < T > value ) => value . Value ;
55
- public static implicit operator Property < T > ( T value ) => new Property < T > ( ) { Value = value , IsDefined = true } ;
56
-
57
- public bool IsDefined { get ; init ; }
58
- }
54
+
59
55
public record SeatRoomConfiguration
60
56
{
61
57
public int SeatCount { get ; init ; }
62
58
public int RowCount { get ; init ; }
63
59
public SeatLocation [ ] EmptySpaces { get ; init ; }
64
60
}
65
- public record DefineScreening
61
+
62
+ public record PathScreening
63
+ {
64
+ public Option < SeatRoomConfiguration > SeatConfiguration { get ; set ; }
65
+ public Option < string > Movie { get ; set ; }
66
+ public Option < string > Room { get ; set ; }
67
+ public Option < TimeOnly > Time { get ; set ; }
68
+ public Option < DateOnly > Date { get ; set ; }
69
+ }
70
+ public record CreateScreening
66
71
{
67
- public Property < SeatRoomConfiguration > SeatConfiguration { get ; init ; }
68
- public Property < string > Movie { get ; init ; }
69
- public Property < string > Room { get ; init ; }
70
- public Property < TimeOnly > Time { get ; init ; }
71
- public Property < DateOnly > Date { get ; init ; }
72
+ public SeatRoomConfiguration SeatConfiguration { get ; set ; }
73
+ public string Movie { get ; set ; }
74
+ public string Room { get ; set ; }
75
+ public TimeOnly Time { get ; set ; }
76
+ public DateOnly Date { get ; set ; }
72
77
73
78
}
74
79
0 commit comments