public async Task <IActionResult> Park(ParkParkedVehicleViewModel viewModel) { var parkSpots = ParkingSpotContainer.GetParkSpots(_configuration); if (ModelState.IsValid) { var vehicle = new ParkedVehicle(); vehicle.VehicleTypeId = int.Parse(Request.Form["Type"].ToString()); if (vehicle.VehicleTypeId == 0) { throw new ArgumentException("The value of the SelectItem selected was zero."); } var member = TempDataExtensions.Get <Member>(TempData, "member"); vehicle.MemberId = member.MemberId; PopulateVehicleFromViewModel(viewModel, vehicle); await ParkVehicleInBackend(parkSpots, vehicle); vehicle.IsParked = true; _context.Add(vehicle); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View()); }
public async Task <IActionResult> RePark(string registrationNumber) { var vehicle = await _context.ParkedVehicles.FirstOrDefaultAsync(v => v.RegistrationNumber.Equals(registrationNumber)); if (vehicle == null) { TempData.Keep(); return(RedirectToAction(nameof(Park))); } vehicle.ParkingDate = DateTime.Now; vehicle.IsParked = true; var parkSpots = ParkingSpotContainer.GetParkSpots(_configuration); await ParkVehicleInBackend(parkSpots, vehicle); try { _context.Update(vehicle); await _context.SaveChangesAsync(); return(RedirectToAction(actionName: "Index", controllerName: "Vehicles")); } catch (DbUpdateConcurrencyException) { if (await _context.ParkedVehicles.FirstOrDefaultAsync(v => v.RegistrationNumber == registrationNumber) == null) { TempData.Keep(); return(RedirectToAction(nameof(Park))); } else { throw; } } return(View()); }
public SpotStatusViewComponent(GarageContext context, IConfiguration configuration) { _context = context; _configuration = configuration; parkSpots = ParkingSpotContainer.GetParkSpots(configuration); }