Example #1
0
        private void BtnSaveReservation_Click(object sender, EventArgs e)
        {
            try
            {
                string errMsg = ValidateForm();
                if (errMsg != string.Empty)
                {
                    toolStripStatusLabel1.Text      = "Create Reservation failed";
                    toolStripStatusLabel1.ForeColor = Color.Red;
                    MessageBox.Show(errMsg, "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                ReservationService reservationService = new ReservationService();
                Reservation        reservation        = new Reservation();


                reservation = PopulateReservationObject();
                if (reservationService.AddNewReservation(reservation))
                {
                    DisabledForm();
                    toolStripStatusLabel1.Text      = "Create Reservation successfully";
                    toolStripStatusLabel1.ForeColor = Color.LightGreen;

                    string reservationNumberToShow = reservationService.ShowReservationNumber(reservation.CheckInDate, reservation.CheckOutDate, reservation.RoomId);
                    MessageBox.Show($"The Reservation Number is: {reservationNumberToShow}", "INFORMATION!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    string msg = "";
                    foreach (ValidationError error in reservation.Guest.Errors)
                    {
                        msg += error.Description + Environment.NewLine;
                    }
                    foreach (ValidationError error in reservation.Errors)
                    {
                        msg += error.Description + Environment.NewLine;
                    }
                    toolStripStatusLabel1.Text      = "Create Reservation failed";
                    toolStripStatusLabel1.ForeColor = Color.Red;

                    MessageBox.Show(msg, "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                toolStripStatusLabel1.Text      = "Create Reservation failed";
                toolStripStatusLabel1.ForeColor = Color.Red;


                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }