예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (Person person in _clientController.GetAllPersons())
                {
                    if (person.FirstName.Equals(firstName.Text.Trim()) && person.LastName.Equals(lastName.Text.Trim()))
                    {
                        int counter = Decimal.ToInt32(noPlaces.Value);
                        while (counter >= 1)
                        {
                            Random randomNumber = new Random();
                            bool   correct      = true;
                            int    rInt         = 0;
                            while (correct)
                            {
                                rInt = randomNumber.Next(1, 18);
                                foreach (Booking booking in _clientController.GetAllBookings())
                                {
                                    if (rInt == booking.SeatNo)
                                    {
                                        break;
                                    }
                                }
                                correct = false;
                            }
                            int id = _clientController.GetAllBookings().Count + 1;
                            _clientController.AddBooking(_ride, new Booking
                            {
                                BookingID = id,
                                RideID    = _ride.RideID,
                                PersonID  = person.PersonID,
                                SeatNo    = rInt
                            }, person);
                            counter--;
                        }
                    }
                }

                MessageBox.Show(@"Rezervare facuta cu succes !", @"Rezervare", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                Close();
            }
            catch (Exception repositoryException)
            {
                MessageBox.Show(repositoryException.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (Transport.Model.Client client in _clientController.GetAllClients())
                {
                    if (client.FirstName.Equals(firstName.Text.Trim()) && client.LastName.Equals(lastName.Text.Trim()))
                    {
                        Random randomNumber = new Random();
                        bool   correct      = true;
                        int    rInt         = 0;
                        while (correct)
                        {
                            rInt = randomNumber.Next(1, 18);
                            foreach (Booking booking in _clientController.GetAllBookings())
                            {
                                if (rInt == booking.SeatNo)
                                {
                                    break;
                                }
                            }
                            correct = false;
                        }
                        _clientController.AddBooking(_ride, new Booking
                        {
                            Id       = 1,
                            RideId   = _ride.Id,
                            ClientId = client.Id,
                            SeatNo   = rInt
                        }, client);
                    }
                }

                MessageBox.Show(@"Rezervare facuta cu succes !", @"Rezervare", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                Close();
            }
            catch (Exception repositoryException)
            {
                MessageBox.Show(repositoryException.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }