Exemple #1
0
        public async Task <(bool IsSuccess, string RentalContract)> PostReservationAsync(ReservationRequest request)
        {
            var notAvailableResults = await reservationsService.GetNotAvailableVehiclesAsync(new Models.RequestModels.SearchVehicleAvailability()
            {
                StartDate = request.StartDate, EndDate = request.EndDate
            });

            if (!notAvailableResults.IsSuccess)
            {
                return(false, null);
            }

            var reservationVehicle = await vehiclesService.PostReservationVehicleAsync(new VehicleReservationRequest()
            {
                CarModelID = request.CarModelID, notAvailableVehicles = notAvailableResults.VehiclesNotAvailable.LstNotAvailableVehicles
            });

            if (!reservationVehicle.IsSuccess)
            {
                return(false, null);
            }

            var reservation = await reservationsService.PostReservationAsync(new ReservationPersistRequest()
            {
                CPF = request.CPF, StartDate = request.StartDate, EndDate = request.EndDate, VehicleID = reservationVehicle.Vehicle.ID, RentalPricePerHour = reservationVehicle.Vehicle.CarModel.RentalPricePerHour
            });

            if (reservation.IsSuccess)
            {
                string contrato = $"Número da reserva {reservation.Reservation.ID}.\n\nEu, {request.CPF}, estou locando o veiculo {reservationVehicle.Vehicle.CarModel.Name}, placa {reservationVehicle.Vehicle.LicensePlate}, durante o período de {request.StartDate} até {request.EndDate}, pelo valor total de R${reservationVehicle.Vehicle.CarModel.RentalPricePerHour * (decimal)(request.EndDate - request.StartDate).TotalHours}.";
                return(true, contrato);
            }
            return(false, null);
        }
Exemple #2
0
        public async Task <(bool IsSuccess, dynamic SearchResults)> SearchVehiclesAvailableAsync(SearchVehicleAvailability search)
        {
            var notAvailableResults = await reservationsService.GetNotAvailableVehiclesAsync(search);

            if (!notAvailableResults.IsSuccess)
            {
                notAvailableResults.VehiclesNotAvailable = new NotAvailableVehicles();
                notAvailableResults.VehiclesNotAvailable.LstNotAvailableVehicles = new List <int> {
                    -1
                };
            }

            var availableModels = await vehiclesService.GetAvailableCarModelsAsync(notAvailableResults.VehiclesNotAvailable.LstNotAvailableVehicles);

            if (availableModels.IsSuccess)
            {
                var result = new
                {
                    TotalRentalHours = (search.EndDate - search.StartDate).TotalHours,
                    AvailableModels  = availableModels.AvailableCarModels
                };
                return(true, result);
            }
            return(false, null);
        }