public ICollection <AvailabilityDTO> GetAvailability(IReservation reservation) { var availableSpacesByDate = new List <AvailabilityDTO>(); var carPark = carParkRepository.FindCarParkById(reservation.CarParkId); for (int i = 0; i <= (reservation.ToDate - reservation.FromDate).Days; i++) { var reservationDay = reservation.FromDate.AddDays(i); var takenReservations = carPark.Reservations.Where(x => x.FromDate <= reservationDay && x.ToDate >= reservationDay); availableSpacesByDate.Add(new AvailabilityDTO() { ReservationDate = reservationDay, SpacesAvailability = FormatAvailabilityString(carPark.AvailableSpaces, takenReservations.Count()), FreeSpaces = carPark.AvailableSpaces - takenReservations.Count(), Price = parkingPricesService.GetParkingPrice(reservationDay.Month) }); } return(availableSpacesByDate); }
public ICarPark FindCarParkById(int id) { var carParkEntity = carParkRepository.FindCarParkById(id); return(new CarPark(carParkEntity.Id, carParkEntity.AvailableSpaces)); }