Ejemplo n.º 1
0
        // Add to the waitlist
        private void btnAddToWaitlist(object sender, EventArgs e)
        {
            lblMessages.Text = ""; // clear lables of error before checking.


            // must check IF any seat is empty.
            try
            {
                // if flight is full, throw exception
                if (!AirplaneService.IsFull())
                {
                    throw new ConstraintException();
                }
                var attempt = WaitlistService.AddToWaitlist(txtName.Text);

                if (!attempt)
                {
                    lblMessages.Text += "Waitlist is full!\r\n";
                }
                lblMessages.Text += $"Added {txtName.Text} to the Waitlist\r\n";
                btnShowWaitingList(sender, e); // update dialog status
                ResetSelection();
            }
            catch (ConstraintException) // full flight
            {
                lblMessages.Text += "Waitlist is only available after all\n\r seats are assigned.\r\n";
            }
            catch (NullReferenceException) // empty name
            {
                lblMessages.Text += "Name must not be empty or white spaced\r\n";
            }
        }