private static void Finish(Task <List <Parking> > parkings, int index, Starship ship) // Final check before adding to database { var parkingCheck = new ParkingChecks(); if (parkingCheck.SizeTooBig(parkings, index, ship)) { Console.WriteLine("Too big."); Console.ReadKey(); } else { if (Occupation.ParkIsOccupied(parkings, index)) { Console.WriteLine("Occupied"); Console.ReadKey(); } else { Console.Clear(); using var context = new SpaceContext(); Console.WriteLine("Parking.."); var park = context.Parkings.First(p => p.Id == parkings.Result[index].Id); park.Occupied = true; park.ShipName = ship.Name; park.ParkedBy = ship.Driver; context.SaveChangesAsync(); Console.WriteLine("Parked"); Console.ReadKey(); } } }
public void LeavePark() // Read name and let user select the ship to leave with { var parkingCheck = new ParkingChecks(); var person = new PersonApi(); var payment = new PaymentActions(); string name = StandardMessages.NameReader(); var r = person.GetAllPersons(); StandardMessages.LoadingMessage(); if (r.Result.Any(p => p.Name == name)) { var parkings = parkingCheck.ParkingLots(); var array = ArrayBuilder.OnLeaveArray(parkings); Console.Clear(); var selectedOption = Menu.ShowMenu($"Welcome {name}. What ship will you be leaving with today?\n", array); if (Occupation.ParkIsOccupied(parkings, selectedOption) == false) // If user selects a empty parking lot, display message { StandardMessages.EmptyParkingLotMessage(); } else if (parkings.Result[selectedOption].ParkedBy != name) // If user selects a ship that is not theirs, display message { StandardMessages.NotYourShipMessage(); } else { payment.Pay(parkings, selectedOption, name); // Pay for the parking lot by getting the database row Leave(parkings, selectedOption); // Remove ship from database } } else { StandardMessages.NotAllowedMessage(); } }
public void Park(Starship ship) { var parkingCheck = new ParkingChecks(); StandardMessages.LoadingMessage(); var parkings = parkingCheck.ParkingLots(); var array = ArrayBuilder.ParkArray(parkings); // Create string array of all parkings to present to the user in the menu Console.Clear(); var selectedOption = Menu.ShowMenu($"You have selected to park {ship.Name}. Choose parking spot", array); Finish(parkings, selectedOption, ship); // Add ship to parking in database }