Beispiel #1
0
        public void TestRentalManagerRemoveInvoice()
        {
            // Pre-setup
            RentalManager manager = new RentalManager(new UnitOfWork(new RentalContext("development")));

            manager.AddClient("Tim", "De Smet", "*****@*****.**", "0493100289", "Azaleastraat", "57", "", "9940", "Evergem", "Belgium", ClientType.AGENCY, "Jetstax", "BE0730.671.009");
            Assert.AreNotEqual(manager.GetAllClients().Count, 0);
            Client client = manager.GetAllClients().Last();

            manager.AddCar("Porsche", "Cayenne Limousine", "White", 310, 1500, 1200, 1600, true);
            Assert.AreNotEqual(manager.GetAllCars().Count, 0);
            Car car = manager.GetAllCars().Last();

            manager.AddReservation(client, ReservationArrangementType.AIRPORT, new DateTime(2020, 8, 20, 10, 0, 0), new DateTime(2020, 8, 20, 13, 0, 0), "Gent", "Gent", new List <Car>()
            {
                car
            }, DateTime.Now, 6.0);

            // Setup
            Assert.AreNotEqual(manager.GetAllReservations().Count, 0);
            Reservation reservation = manager.GetAllReservations().Last();
            int         count       = manager.GetAllReservations().Count;

            manager.RemoveReservation(reservation);

            // Check
            Assert.AreEqual(manager.GetAllReservations().Count, count - 1);
        }
        private void Submit_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            DateTime from;
            DateTime until;

            if (inClient.SelectedIndex < 0)
            {
                MainWindow.DisplayThrowbackDialog("Reservation Creation Error", "You must selected a client out of the list"); return;
            }
            if (!int.TryParse(inClient.SelectedItem.ToString().Split(" ")[0].Substring(1), out int clientID))
            {
                MainWindow.DisplayThrowbackDialog("Reservation Creation Error", "Something went wrong while retrieving the client from the list"); return;
            }
            RentalManager manager = new RentalManager(new UnitOfWork(new RentalContext()));
            Client        client  = manager.GetClient(clientID);

            if (inArrangement.SelectedIndex < 0 || !Enum.TryParse(inArrangement.SelectedItem.ToString().ToUpper(), out Type))
            {
                MainWindow.DisplayThrowbackDialog("Reservation Creation Error", "You must select a arrangement from the list"); return;
            }
            if ((from = GetFrom()) <= DateTime.MinValue)
            {
                MainWindow.DisplayThrowbackDialog("Reservation Creation Error", "You must select pickup date and time"); return;
            }
            if ((until = GetUntil()) <= DateTime.MinValue)
            {
                MainWindow.DisplayThrowbackDialog("Reservation Creation Error", "You must select return date and time"); return;
            }
            if (inStartLocation.SelectedIndex < 0)
            {
                MainWindow.DisplayThrowbackDialog("Reservation Creation Error", "You must select pickup location"); return;
            }
            if (inEndLocation.SelectedIndex < 0)
            {
                MainWindow.DisplayThrowbackDialog("Reservation Creation Error", "You must select return location"); return;
            }
            if (client.Type == ClientType.PRIVATE && AvailableCars.SelectedItems.Count > 1)
            {
                MainWindow.DisplayThrowbackDialog("Reservation Edit Error", "Private clients can select a maximum of 1 car"); return;
            }

            String startLocation = inStartLocation.SelectedItem.ToString();
            String endLocation   = inEndLocation.SelectedItem.ToString();

            List <int> carIDs       = new List <int>();
            List <int> selectedCars = AvailableCars.SelectedItems.Cast <DataRowView>().Select(x => AvailableCarsTable.Rows.IndexOf(x.Row)).ToList();

            foreach (int i in selectedCars)
            {
                if (AvailableCarsTable.Rows.Count > 1)
                {
                    DataRow row = AvailableCarsTable.Rows[i];
                    carIDs.Add((int)row[0]);
                }
            }

            List <Car> cars = new List <Car>();

            foreach (int carID in carIDs)
            {
                cars.Add(manager.GetCar(carID));
            }

            try
            {
                Reservation reservation = manager.AddReservation(client, Type, from, until, startLocation, endLocation, cars, DateTime.Now, 6);
                MainWindow.DisplayThrowbackDialog("Successfull", "The reservation has been added to the list");
                if (RegexUtilities.IsValidEmail(client.Email, true))
                {
                    MailService.Send_NewReservation(client.Email, reservation, cars);
                    MailService.Send_NewInvoice(client.Email, client.FirstName, client.LastName, client.CompanyName, manager.GetInvoice(reservation.InvoiceID), manager.GetInvoiceItems(reservation.InvoiceID));
                }
            }
            catch (Exception error)
            {
                MainWindow.DisplayThrowbackDialog("Reservation Creation Error", error.Message);
                return;
            }
        }