public IActionResult ParkVehicle(ParkVehicleViewModel viewModel) { var level = _levelRepository.GetById(viewModel.ParkingLevelId); if (level == null) { return(NotFound()); } var licensePlate = LicensePlate.Create(viewModel.Vehicle.LicensePlate); if (!licensePlate.IsSuccess) { return(BadRequest(licensePlate.ErrorMessage)); } var vehicle = Vehicle.Create(licensePlate.Value, viewModel.Vehicle.Weight); if (!vehicle.IsSuccess) { return(BadRequest(vehicle.ErrorMessage)); } var result = level.ParkVehicle(viewModel.ParkingSpaceNumber, vehicle.Value); if (!result.IsSuccess) { return(BadRequest(result.ErrorMessage)); } _context.SaveChanges(); return(RedirectToAction(nameof(ParkingController.Edit), "Parking", new { id = level.Parking.Id })); }
public IActionResult FindParkingSpace(string licensePlate) { var result = LicensePlate.Create(licensePlate); if (!result.IsSuccess) { return(BadRequest(result.ErrorMessage)); } foreach (var parking in _parkingRepository.GetAll()) { var parkingSpace = parking.FindParkingSpace(result.Value); if (parkingSpace != null) { return(View(parkingSpace)); } } return(NotFound()); }