@@ -11,38 +11,39 @@ public CarMappings()
11
11
CreateMap < Car , CarDto > ( )
12
12
. ForCtorParam ( nameof ( CarDto . Id ) , cfg => cfg . MapFrom ( c => c . Id ) )
13
13
. ForCtorParam ( nameof ( CarDto . OilMarkId ) , cfg => cfg . MapFrom ( c => c . OilMarkId ) )
14
+ . ForCtorParam ( nameof ( CarDto . OilMarkName ) , cfg => cfg . MapFrom ( c => c . OilMark ! . Name ) )
14
15
. ForCtorParam ( nameof ( CarDto . Model ) , cfg => cfg . MapFrom ( c => c . Model ) )
15
16
. ForCtorParam ( nameof ( CarDto . Number ) , cfg => cfg . MapFrom ( c => c . Number ) )
16
17
. ForCtorParam ( nameof ( CarDto . ManufacturedYear ) , cfg => cfg . MapFrom ( c => c . ManufacturedYear ) )
17
18
. ForCtorParam ( nameof ( CarDto . Mileage ) , cfg => cfg . MapFrom ( c => c . Mileage ) )
18
- . ForCtorParam ( nameof ( CarDto . CurrentMonthFuelConsumption ) , cfg => cfg . MapFrom ( c => c . UsageSummary . CurrentMonthFuelConsumption ) )
19
- . ForCtorParam ( nameof ( CarDto . CurrentYearFuelConsumption ) , cfg => cfg . MapFrom ( c => c . UsageSummary . CurrentYearFuelConsumption ) )
19
+ . ForCtorParam ( nameof ( CarDto . CurrentMonthFuelConsumption ) , cfg => cfg . MapFrom ( c => c . UsageSummary != null ? c . UsageSummary . CurrentMonthFuelConsumption : default ) )
20
+ . ForCtorParam ( nameof ( CarDto . CurrentYearFuelConsumption ) , cfg => cfg . MapFrom ( c => c . UsageSummary != null ? c . UsageSummary . CurrentYearFuelConsumption : default ) )
20
21
. ForCtorParam ( nameof ( CarDto . MonthlyFuelConsumptionLimit ) , cfg => cfg . MapFrom ( c => c . Limits . MonthlyFuelConsumptionLimit ) )
21
22
. ForCtorParam ( nameof ( CarDto . YearlyFuelConsumptionLimit ) , cfg => cfg . MapFrom ( c => c . Limits . YearlyFuelConsumptionLimit ) )
22
- . ForCtorParam ( nameof ( CarDto . CurrentMonthMileage ) , cfg => cfg . MapFrom ( c => c . UsageSummary . CurrentMonthDistance ) )
23
- . ForCtorParam ( nameof ( CarDto . CurrentYearMileage ) , cfg => cfg . MapFrom ( c => c . UsageSummary . CurrentYearDistance ) )
23
+ . ForCtorParam ( nameof ( CarDto . CurrentMonthMileage ) , cfg => cfg . MapFrom ( c => c . UsageSummary != null ? c . UsageSummary . CurrentMonthDistance : default ) )
24
+ . ForCtorParam ( nameof ( CarDto . CurrentYearMileage ) , cfg => cfg . MapFrom ( c => c . UsageSummary != null ? c . UsageSummary . CurrentYearDistance : default ) )
24
25
. ForCtorParam ( nameof ( CarDto . MonthlyDistanceLimit ) , cfg => cfg . MapFrom ( c => c . Limits . MonthlyDistanceLimit ) )
25
26
. ForCtorParam ( nameof ( CarDto . YearlyDistanceLimit ) , cfg => cfg . MapFrom ( c => c . Limits . YearlyDistanceLimit ) ) ;
26
27
27
28
CreateMap < CreateCarDto , Car > ( )
28
29
. ForPath ( dest => dest . OilMarkId , opt => opt . MapFrom ( src => src . OilMarkId ) )
29
- . ForPath ( dest => dest . UsageSummary . CurrentMonthDistance , opt => opt . MapFrom ( src => src . CurrentYearMileage ) )
30
- . ForPath ( dest => dest . UsageSummary . CurrentYearDistance , opt => opt . MapFrom ( src => src . CurrentYearMileage ) )
31
30
. ForPath ( dest => dest . Limits . MonthlyDistanceLimit , opt => opt . MapFrom ( src => src . MonthlyDistanceLimit ) )
32
31
. ForPath ( dest => dest . Limits . YearlyDistanceLimit , opt => opt . MapFrom ( src => src . YearlyDistanceLimit ) )
33
- . ForPath ( dest => dest . UsageSummary . CurrentMonthFuelConsumption , opt => opt . MapFrom ( src => src . CurrentMonthFuelConsumption ) )
34
- . ForPath ( dest => dest . UsageSummary . CurrentYearFuelConsumption , opt => opt . MapFrom ( src => src . CurrentYearFuelConsumption ) )
35
32
. ForPath ( dest => dest . Limits . MonthlyFuelConsumptionLimit , opt => opt . MapFrom ( src => src . MonthlyFuelConsumptionLimit ) )
36
33
. ForPath ( dest => dest . Limits . YearlyFuelConsumptionLimit , opt => opt . MapFrom ( src => src . YearlyFuelConsumptionLimit ) ) ;
37
34
38
35
CreateMap < UpdateCarDto , Car > ( )
39
36
. ForPath ( dest => dest . OilMarkId , opt => opt . MapFrom ( src => src . OilMarkId ) )
40
- . ForPath ( dest => dest . UsageSummary . CurrentMonthDistance , opt => opt . MapFrom ( src => src . CurrentYearMileage ) )
41
- . ForPath ( dest => dest . UsageSummary . CurrentYearDistance , opt => opt . MapFrom ( src => src . CurrentYearMileage ) )
37
+ . ForPath ( dest => dest . UsageSummary , opt => opt . MapFrom ( src =>
38
+ new CarUsageSummary
39
+ {
40
+ CurrentMonthDistance = src . CurrentMonthMileage ,
41
+ CurrentYearDistance = src . CurrentYearMileage ,
42
+ CurrentMonthFuelConsumption = src . CurrentMonthFuelConsumption ,
43
+ CurrentYearFuelConsumption = src . CurrentYearFuelConsumption
44
+ } ) )
42
45
. ForPath ( dest => dest . Limits . MonthlyDistanceLimit , opt => opt . MapFrom ( src => src . MonthlyDistanceLimit ) )
43
46
. ForPath ( dest => dest . Limits . YearlyDistanceLimit , opt => opt . MapFrom ( src => src . YearlyDistanceLimit ) )
44
- . ForPath ( dest => dest . UsageSummary . CurrentMonthFuelConsumption , opt => opt . MapFrom ( src => src . CurrentMonthFuelConsumption ) )
45
- . ForPath ( dest => dest . UsageSummary . CurrentYearFuelConsumption , opt => opt . MapFrom ( src => src . CurrentYearFuelConsumption ) )
46
47
. ForPath ( dest => dest . Limits . MonthlyFuelConsumptionLimit , opt => opt . MapFrom ( src => src . MonthlyFuelConsumptionLimit ) )
47
48
. ForPath ( dest => dest . Limits . YearlyFuelConsumptionLimit , opt => opt . MapFrom ( src => src . YearlyFuelConsumptionLimit ) ) ;
48
49
}
0 commit comments