public async Task <IActionResult> Create(ReservationCreateViewModel model) { var userId = _userManager.GetUserId(User); if (ModelState.IsValid) { var parking = _context.Parkings.FirstOrDefault(f => f.Id == model.ParkingId); var totalAmount = model.ParkingDuration * parking.PricePerHour; if (_walletService.Pay(totalAmount, User)) { var parkingReservation = new ParkingReservation { UserId = userId, CarCategory = model.CarCategory, CarNumber = model.CarNumber, ParkingDate = model.ParkingDate, ParkingTime = model.ParkingDuration, VerificationCode = Guid.NewGuid(), AmountPaid = model.ParkingDuration * parking.PricePerHour, SlotNumber = model.SlotNumber, ParkingId = model.ParkingId }; _context.Add(parkingReservation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), "Reservations", new { id = parkingReservation.Id })); } else { ModelState.AddModelError(string.Empty, "Resurse insuficiente în cont."); } } model.AvailableParkings = _context.Parkings.ToList(); return(View(model)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,ParkingDate,ParkingTime,AmountPaid,VerificationCode")] ParkingReservation parkingReservation) { if (id != parkingReservation.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(parkingReservation); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ParkingReservationExists(parkingReservation.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", parkingReservation.UserId); return(View(parkingReservation)); }
// constructor public ModifyReservationForm(Form prevMenu, ParkingDatabase database, ParkingReservation reservationToModify, IClock clock, IMailer mailer) { rand = new Random(); Mailer = mailer; ModificationClock = clock; this.PreviousMenu = prevMenu; this.Database = database; OldReservation = reservationToModify; VehicleList = Database.GetVehicles(OldReservation.Customer.CustomerID); CardList = Database.GetCreditCards(OldReservation.Customer.CustomerID); InitializeComponent(); // bind the vehicle combo box to the vehicle list vehicleComboBox.DataSource = VehicleList; vehicleComboBox.DisplayMember = "AsString"; // set initial values based on current reservation details desiredMonthCalendar.MaxSelectionCount = 1; desiredMonthCalendar.SelectionStart = OldReservation.Date; desiredTimeDateTimePicker.Value = OldReservation.Date; durationComboBox.SelectedIndex = MinutesToDurationIndex(OldReservation.DurationMinutes); vehicleComboBox.SelectedItem = OldReservation.ReservationVehicle; }
// check if a reservation cancellation is allowed public bool CancelAllowed(ParkingReservation resToCancel) { // determine if the cancellation request is being requested within 24 hours of // the reservation start date TimeSpan timeDiff = resToCancel.Date.Subtract(CustomerClock.Now); if (timeDiff.TotalHours < 24) { return false; // cannot be < 24 hours away } else { return true; } }
// fill the reservation details labels public void FillReservationDetails(ParkingReservation res) { if (res == null) { idLabel.Text = "n/a"; startLabel.Text = "n/a"; endLabel.Text = "n/a"; modelLabel.Text = "n/a"; licenseLabel.Text = "n/a"; } else { idLabel.Text = res.ReservationID.ToString(); startLabel.Text = res.Date.ToString("g"); endLabel.Text = res.ReservationEndTime.ToString("g"); modelLabel.Text = res.ReservationVehicle.CarModel; licenseLabel.Text = res.ReservationVehicle.LicensePlateID; } }
private void button1_Click(object sender, EventArgs e) { var parking = db.ParkingPlaces.Where(x => x.ParkingName == parkName).FirstOrDefault(); var user = db.Users.Where(x => x.Email == Homepage.usr).FirstOrDefault(); Vehicle v = new Vehicle(); v.VehicleType = vtype.Text; v.ModelName = vname.Text; v.RegistrationNumber = vnumber.Text; v.User = user; db.Vehicles.Add(v); ParkingReservation parkingReservation = new ParkingReservation(); if (vtype.Text == "2-Wheeler") { parkingReservation.Payment = parking.TwoRate; parkingReservation.Plot = parking.TwoCapacity; parking.TwoCapacity = parking.TwoCapacity - 1; } else { parkingReservation.Payment = parking.FourRate; parkingReservation.Plot = parking.FourCapacity; parking.FourCapacity = parking.FourCapacity - 1; } parkingReservation.TimeArrival = atime.Value; parkingReservation.TimeDeparture = dtime.Value; parkingReservation.Vehicle = v; parkingReservation.ParkingPlace = parking; parkingReservation.User = user; db.ParkingReservations.Add(parkingReservation); db.SaveChanges(); MessageBox.Show("Your parking reservation is successfull!!\nParking Plot:" + parkingReservation.Plot + "\nAmount Payable:" + parkingReservation.Payment); this.Hide(); Homepage home = new Homepage(Homepage.usr); home.Show(); }
// check in the parking garage using a reservation public void CheckIn(ParkingReservation reservation) { if (reservation.Date > TerminalClock.Now) { // reservation period is not yet in effect; notify MessageBox.Show(string.Format("Reservation period has not started yet.\nPlease wait until {0}.", reservation.Date.ToShortTimeString())); } else if (reservation.ReservationEndTime <= TerminalClock.Now) { // reservation period has passed; notify MessageBox.Show(string.Format("Reservation period has passed.\nReservation ended at {0}.", reservation.ReservationEndTime.ToShortTimeString())); } else { // reservation period is in effect; check ticket key if (reservation.TicketKey != Convert.ToInt32(ticketKeyTextBox.Text)) { MessageBox.Show("Ticket key is invalid."); } else { // check if currently occupied bool isOccupied = Database.IsOccupied(reservation.ParkingSpotID); if (isOccupied) // parking spot is still occupied by previous customer { // check if other available spots for same time and duration bool cannotOrWillNot = false; // cannot or will not change spots if (!Database.IsOtherParkingSpots(reservation)) { cannotOrWillNot = true; // cannot offer another spot MessageBox.Show("Your parking spot has not been vacated. Since the garage is operating at maximum capacity, we are " + "currently unable to offer you a different spot."); } else // offer reservation with new parking spot ID to user { // pick a random other available spot List<Garage.ParkingSpot> otherSpots = Database.GetAvailableParkingSpots(reservation); int newSpotID = otherSpots[rand.Next(0, otherSpots.Count)].ParkingSpotID; // check if user agrees to switch spot DialogResult agreeResult = MessageBox.Show("Your parking spot has not been vacated. Would you like to change your reservation parking spot to " + newSpotID + "?", "Parking spot has not been vacated.", MessageBoxButtons.YesNo); // if agree: if (agreeResult == DialogResult.Yes) { // modifiy original reservation to have new parking spot and set as checked in Database.ModifyReservation(reservation, newSpotID, reservation.Date, reservation.DurationMinutes, true, reservation.ReservationVehicle.CarID); reservation.ParkingSpotID = newSpotID; // change status of parking spot Database.SetParkingSpotStatus(reservation.ParkingSpotID, 1); // print ticket Printer.PrintReservation(reservation); DisplayDetails(reservation); // lift barrier Barrier.AllowVehicleThrough(); } // if disagree: else if (agreeResult == DialogResult.No) { cannotOrWillNot = true; } } // if customer reservation spot has not been vacated, and the customer cannot or will change spots, // then offer the customer the chance to cancel the reservation and drop any charges if (cannotOrWillNot) { // apologize and ask if want to cancel transaction: DialogResult cancelResult = MessageBox.Show("Would you like to cancel your reservation? This will cancel also cancel " + "any charges for the reservation.", "Cancel reservation?", MessageBoxButtons.YesNo); // if agree: if (cancelResult == DialogResult.Yes) { // delete the reservation (and transaction) from the database Database.CancelReservation(reservation); MessageBox.Show("Reservation cancelled."); } else { // if disagree to make change, then inform that they may attempt to check in later MessageBox.Show("You may check back at a later time to check if parking spot has been vacated."); } } } else // parking spot is NOT occupied by previous customer { // display reservation details DisplayDetails(reservation); try { // change status of reservation Database.ModifyReservation(reservation, reservation.ParkingSpotID, reservation.Date, reservation.DurationMinutes, true, reservation.ReservationVehicle.CarID); // change status of parking lot Database.SetParkingSpotStatus(reservation.ParkingSpotID, 1); // lift barrier Barrier.AllowVehicleThrough(); } catch (Exception e) { MessageBox.Show(e.Message); } } } } // clear input and wait for next customer reservationNumTexBox.Clear(); ticketKeyTextBox.Clear(); }
// display details of a parking reservation (after successful check-in) public void DisplayDetails(ParkingReservation reservation) { MessageBox.Show(String.Format("Check-in successful.\n\nReservation ID: {0}\nReservation Ends: {1}\nParking Spot: {2}", reservation.ReservationID, reservation.ReservationEndTime, reservation.ParkingSpotID)); }
// check a user out from the garage public void CheckOut(ParkingReservation reservation) { // check if have any fine, due to customer oversaying his or her reservation period if (TerminalClock.Now > reservation.ReservationEndTime) { // if so, create new fine TimeSpan diff = TerminalClock.Now.Subtract(reservation.ReservationEndTime); decimal fine = decimal.Round((((decimal)diff.TotalMinutes) * (Database.HourlyRate / 60)), 2); // insert fine as transaction Database.RecordFine(fine, reservation.Customer.CustomerID, reservation.ReservationID, Database.GetDefaultCreditCardID(reservation.Customer.CustomerID)); // display fine to user MessageBox.Show(string.Format("Your checkout is {0:N0} minute(s) overdue. You will be charged a fine of {1:C}.", diff.TotalMinutes, fine)); } // change status of reservation to checked out Database.ModifyReservation(reservation, reservation.ParkingSpotID, reservation.Date, reservation.DurationMinutes, false, reservation.ReservationVehicle.CarID); // change status of parking lot to checked out Database.SetParkingSpotStatus(reservation.ParkingSpotID, 0); // thank user and allow through barrier MessageBox.Show("Thank you for your business."); AllowThroughBarrier(); // clear input reservationNumTexBox.Clear(); ticketKeyTextBox.Clear(); }
public void RemoveReservation(ParkingReservation reservation) { monitor.Check(); reservations.Remove(reservation); monitor.Release(); }
public void ExtendReservation(ParkingReservation reservation) { monitor.Check(); GlobalParameters globalParameters = GlobalParameters.GetInstance(); int currentTime = globalParameters.Timer; ViewerCache viewerCache = ViewerCache.GetInstance(); if (reservation.Car.Extensions < reservation.Zone.MaxExtensions) { int parkingBill = (zones.Length + 1 - reservation.Zone.ID) * globalParameters.ArgumentHolder.UnitPrice; reservation.Car.AddParkingBill(parkingBill); reservation.Zone.Profit = parkingBill; reservation.Car.Extensions++; viewerCache.Add(currentTime.ToString() + ": Vlasnik automobila " + reservation.Car.ID.ToString() + " je produljio parkiranje u zoni " + reservation.Zone.ID.ToString() + " i platio " + parkingBill.ToString() + " HRK"); monitor.Release(); } else { viewerCache.Add(currentTime.ToString() + ": Vlasniku automobila " + reservation.Car.ID.ToString() + ", parkiranog u zoni " + reservation.Zone.ID.ToString() + " odbijeno je produljenje"); monitor.Release(); Leave(reservation); } }
public void Leave(ParkingReservation reservation) { monitor.Check(); GlobalParameters globalParameters = GlobalParameters.GetInstance(); int currentTime = globalParameters.Timer; reservation.Car.Leave(); reservation.Zone.Remove(reservation.Car); reservations.Remove(reservation); ViewerCache viewerCache = ViewerCache.GetInstance(); viewerCache.Add(currentTime.ToString() + ": Automobil " + reservation.Car.ID.ToString() + " napušta zonu " + reservation.Zone.ID.ToString()); monitor.Release(); }
public bool ReservePlaceInZone(Automobile car, Zone zone) { monitor.Check(); bool returnValue; if (!open) { returnValue = false; } else if (zone.IsFull()) { GlobalParameters globalParameters = GlobalParameters.GetInstance(); ViewerCache viewerCache = ViewerCache.GetInstance(); zone.LostClients++; viewerCache.Add(globalParameters.Timer.ToString() + ": Automobilu " + car.ID + " odbijeno parkiranje u zoni " + zone.ID.ToString() + " jer nije bilo prostora"); returnValue = false; } else { GlobalParameters globalParameters = GlobalParameters.GetInstance(); int currentTime = globalParameters.Timer; ParkingReservation newReservation = new ParkingReservation(car, zone, currentTime); reservations.Add(newReservation); zone.Add(car); int parkingBill = (zones.Length + 1 - zone.ID) * globalParameters.ArgumentHolder.UnitPrice; car.AddParkingBill(parkingBill); zone.Profit = parkingBill; ViewerCache viewerCache = ViewerCache.GetInstance(); viewerCache.Add(currentTime.ToString() + ": Naplaćeno parkiranje u zoni " + zone.ID.ToString() + " automobilu " + car.ID.ToString() + " u iznosu od " + parkingBill.ToString() + " HRK"); returnValue = true; } monitor.Release(); return returnValue; }
// attempt to modify the reservation private void modifyButton_Click(object sender, EventArgs e) { // retrieve the desired reservation date from the input DateTime desiredDate = new DateTime(desiredMonthCalendar.SelectionStart.Year, desiredMonthCalendar.SelectionStart.Month, desiredMonthCalendar.SelectionStart.Day, desiredTimeDateTimePicker.Value.Hour, desiredTimeDateTimePicker.Value.Minute, 0); // retrieve the desired vehicle from the input Accounts.Vehicle desiredVehicle = vehicleComboBox.SelectedItem as Accounts.Vehicle; ParkingReservation newReservation = null; try { // create the new version of the reservation newReservation = new ParkingReservation(OldReservation.ReservationID, OldReservation.Customer, desiredVehicle, desiredDate, DurationIndexToMinutes(durationComboBox.SelectedIndex), OldReservation.ParkingSpotID, OldReservation.TicketKey, false); // check if modification is valid (does not conflict with another reservation) if (Database.ReservationModificationValid(OldReservation, newReservation)) { bool isAllowed = true; // by default, allowed // check if modifications are being attempted by a customer if (PreviousMenu is SelectReservationToModifyForm) // is customer { isAllowed = false; // check if modification is only an extension (date, vehicle, and time must be the same) // (modification only allowed before reservation start; customer extensions allowed whenever) if (OldReservation.Date == desiredDate && OldReservation.ReservationVehicle.CarID == desiredVehicle.CarID && OldReservation.DurationMinutes < newReservation.DurationMinutes) { // just extending isAllowed = true; } else { // attempting to make non-extension modifcation (don't allow if already started) // if desired is now or in the past, then do not continue if (desiredDate <= DateTime.Now) { MessageBox.Show("Please select a reservation date and time that is in the future."); } else if (OldReservation.Date <= ModificationClock.Now) { MessageBox.Show("Modifications to reservation date or vehicle not allowed after " + "start of reservation period."); } else { isAllowed = true; } } } // if the modiciation is allowed, process it if (isAllowed) { // modify the reservation in the database Database.ModifyReservation(OldReservation, newReservation.ParkingSpotID, newReservation.Date, newReservation.DurationMinutes, newReservation.IsCheckedIn, newReservation.ReservationVehicle.CarID); // display result MessageBox.Show(String.Format("Successfully modified reservation:\nReservation ID: {0}\nDate and Time: {1}\nDuration: {2} minutes\nParking Spot: {3}\nTicket Key: {4}", newReservation.ReservationID, newReservation.Date, newReservation.DurationMinutes, newReservation.ParkingSpotID, newReservation.TicketKey)); // mail receipt of the modification Mailer.MailReservationReceipt(newReservation); } } else { // if reservation already started, then can't modify spot if (OldReservation.Date < ModificationClock.Now) { MessageBox.Show("Cannot extend reservation period for your parking spot."); } else { // check if other available spots for same time and duration if (!Database.IsOtherParkingSpots(newReservation)) { MessageBox.Show("Modified reservation period is not available."); } else // another spot is available { // offer new reservation to user List<Garage.ParkingSpot> otherSpots = Database.GetAvailableParkingSpots(newReservation); // pick a random spot from the available spots int newSpotID = otherSpots[rand.Next(0, otherSpots.Count)].ParkingSpotID; // check if user wishes to make spot change DialogResult agreeResult = MessageBox.Show("Your parking spot is not available for that reservation period. " + "Would you like to change your reservation parking spot to " + newSpotID + "?", "Parking spot not available at that time.", MessageBoxButtons.YesNo); // if agree: if (agreeResult == DialogResult.Yes) { // modifiy original reservation to have new parking spot Database.ModifyReservation(newReservation, newSpotID, newReservation.Date, newReservation.DurationMinutes, false, newReservation.ReservationVehicle.CarID); newReservation.ParkingSpotID = newSpotID; // print ticket Mailer.MailReservationReceipt(newReservation); this.Close(); } } } } } catch (ReservationException ex) { MessageBox.Show(ex.Message); } }