-
Notifications
You must be signed in to change notification settings - Fork 8
/
ReservationChangeRequestConfig.cs
76 lines (65 loc) · 2.72 KB
/
ReservationChangeRequestConfig.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
72
73
74
75
76
using GroupFlights.Postsale.Domain.Changes.Outcome;
using GroupFlights.Postsale.Domain.Changes.Payments;
using GroupFlights.Postsale.Domain.Changes.Request;
using GroupFlights.Postsale.Domain.Shared;
using GroupFlights.Shared.Types;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace GroupFlights.Postsale.Infrastructure.Data.EF.Configs;
internal class ReservationChangeRequestConfig : IEntityTypeConfiguration<ReservationChangeRequest>
{
public void Configure(EntityTypeBuilder<ReservationChangeRequest> builder)
{
builder.HasKey(x => x.Id);
builder.HasOne<ReservationToChange>("_reservationToChange");
builder.Property<DateTime>("_newTravelDate");
builder.Property<UserId>("_requester")
.HasConversion<Guid?>(x => x == null ? null : x.Value,
x => x == null ? null : new (x.Value))
.IsRequired();
builder.Property<bool>("_isFeasible");
builder.OwnsOne<RequiredPayment>("_paymentRequiredToApplyChange", p =>
{
p.OwnsOne(x => x.Deadline);
});
builder.OwnsOne<ReservationCost>("_newCost",
c =>
{
c.OwnsOne(x => x.TotalCost, m =>
{
m.Property(x => x.Amount).IsRequired();
m.Property(x => x.Currency).IsRequired();
});
c.Navigation(x => x.TotalCost).IsRequired();
c.OwnsOne(x => x.RefundableCost, m =>
{
m.Property(x => x.Amount).IsRequired();
m.Property(x => x.Currency).IsRequired();
});
c.Navigation(x => x.RefundableCost).IsRequired();
}).Navigation("_newCost").IsRequired(false);
builder.OwnsMany<FlightSegment>("_newTravel", t =>
{
t.OwnsOne(x => x.FlightTime);
t.Property(x => x.Date).IsRequired();
t.OwnsOne(x => x.SourceAirport, a =>
{
a.Property(x => x.Code)
.HasConversion(x => x.Value,
x => new(x))
.IsRequired();
});
t.OwnsOne(x => x.TargetAirport, a =>
{
a.Property(x => x.Code)
.HasConversion(x => x.Value,
x => new(x))
.IsRequired();
});
t.OwnsOne(x => x.FlightTime);
});
builder.HasOne<ReservationChangeToApply>("_changeToApply");
builder.Property<bool>("_isActive");
builder.Property<ReservationChangeRequest.CompletionStatus?>("_completionStatus");
}
}