This is the expected result: The accumulatedMaxPax
should be equal to the previous value
+ the current maxPax
. It should reset (=0) on every destinations
change.
[
{
"date": "2022-05-06",
"destinations": [
{
"id": 1,
"description": "PAXOS - ANTIPAXOS",
"abbreviation": "PA",
"ports": [
{
"id": 1,
"description": "CORFU PORT",
"maxPax": 200,
"accumulatedMaxPax": 200 // Initial (accumulatedMaxPax = maxPax )
},
{
"id": 4,
"description": "BENITSES PORT",
"maxPax": 200,
"accumulatedMaxPax": 400 // 200 (previous) + 200 (current) = 400
},
{
"id": 17,
"description": "BOUKARI PORT",
"maxPax": 100,
"accumulatedMaxPax": 500 // 400 (previous) + 100 (current) = 500
},
{
"id": 2,
"description": "LEFKIMMI PORT",
"maxPax": 400,
"accumulatedMaxPax": 900 // 500 (previous) + 400 (current) = 900
}
]
},
{
"id": 3,
"description": "BLUE LAGOON",
"abbreviation": "BL",
"ports": [
{
"id": 1,
"description": "CORFU PORT",
"maxPax": 215,
"accumulatedMaxPax": 215
},
{
"id": 4,
"description": "BENITSES PORT",
"maxPax": 215,
"accumulatedMaxPax": 430
}
]
},
{
"id": 7,
"description": "PARTY",
"abbreviation": "PRT",
"ports": [
{
"id": 1,
"description": "CORFU PORT",
"maxPax": 200,
"accumulatedMaxPax": 200
}
]
}
]
}
]
This is the code which works according to the specs, with the missing part of the puzzle as question marks!
public IEnumerable<AvailabilityCalendarGroupVM> GetForCalendar(string fromDate, string toDate) {
return context.Schedules
.Where(x => x.Date >= Convert.ToDateTime(fromDate) && x.Date <= Convert.ToDateTime(toDate))
.GroupBy(x => x.Date)
.Select(x => new AvailabilityCalendarGroupVM {
Date = DateHelpers.DateTimeToISOString(x.Key.Date),
Destinations = x.GroupBy(x => new { x.Date, x.Destination.Id, x.Destination.Description, x.Destination.Abbreviation }).Select(x => new DestinationCalendarVM {
Id = x.Key.Id,
Description = x.Key.Description,
Abbreviation = x.Key.Abbreviation,
Ports = x.GroupBy(x => new { x.PortId, x.Port.Description, x.Port.Abbreviation, x.MaxPax, x.Port.StopOrder }).OrderBy(x => x.Key.StopOrder).Select(x => new PortCalendarVM {
Id = x.Key.PortId,
Description = x.Key.Description,
MaxPax = x.Key.MaxPax,
AccumulatedMaxPax = NOW WHAT ???
})
})
}).ToList();
}