Exemple #1
0
        private static List <DTO.ReservationsDTO> ConvertToDTO(List <Reservations> reservations)
        {
            var reservationsDTO = new List <DTO.ReservationsDTO>();

            foreach (var reservation in reservations)
            {
                var reservationDto = new DTO.ReservationsDTO();
                reservationDto.ReservationID = reservation.ReservationID;
                reservationDto.CarID         = reservation.CarID;
                reservationDto.CostumerID    = reservation.CostumerID;
                reservationDto.ReservStatsID = reservation.ReservStatsID;
                reservationDto.StartDate     = reservation.StartDate;
                reservationDto.EndDate       = reservation.EndDate;
                reservationDto.Location      = reservation.Location;
                reservationDto.CouponCode    = reservation.CouponCode;

                reservationsDTO.Add(reservationDto);
            }
            return(reservationsDTO);
        }
        private void submitButton_Click(object sender, EventArgs e)
        {
            var cars         = Domain.CarsManager.ListCars();
            var reservations = Domain.ReservationsManager.ListReservations();
            var customers    = Domain.CustomersManager.ListCustomers();


            if (carPlateTextBox.Text.Trim().Length == 0)
            {
                MessageBox.Show("Plate is a Mandatory Field");
                return;
            }

            else if (Domain.ReservationsManager.FindCarIdByPlate(carPlateTextBox.Text) == null)
            {
                MessageBox.Show("Car is Not Listed");
                return;
            }


            else if (clientIdTextBox.Text.Trim().Length == 0)
            {
                MessageBox.Show("Client Id is a Mandatory Field");
                return;
            }

            else if (IsInteger(clientIdTextBox.Text) == false)
            {
                MessageBox.Show("Please Enter an Integer");
                return;
            }

            else if (doesExist(customers, clientIdTextBox.Text) == false)
            {
                MessageBox.Show("Client does not exist");
                return;
            }

            else if (startDateDateTimePicker.Value.Date < DateTime.Now.Date)
            {
                MessageBox.Show("Please Select a Valid Start Date");
                return;
            }


            //else if (IsReserved(reservations, carPlateTextBox.Text) == true
            //          && CheckStartDate(reservations, carPlateTextBox.Text, startDateDateTimePicker.Value.Date) == false)
            //{
            //    MessageBox.Show("Please Select a Different Date");
            //    return;
            //}


            else if (endDateDateTimePicker.Value.Date <= startDateDateTimePicker.Value.Date)
            {
                MessageBox.Show("Please Select a Valid End Date");
                return;
            }

            else if (IsReserved(reservations, carPlateTextBox.Text) == true &&
                     DatesMatch(reservations, carPlateTextBox.Text, startDateDateTimePicker.Value.Date,
                                endDateDateTimePicker.Value.Date) == true)
            {
                MessageBox.Show("Car is not available.Please Try a Different Time Period");
                return;
            }



            else if (cityTextBox.Text.Trim().Length == 0)
            {
                MessageBox.Show("City is a Mandatory Field");
                return;
            }

            else
            {
                var carPlate = carPlateTextBox.Text;
                var car      = Domain.ReservationsManager.FindCarIdByPlate(carPlate);


                var status = new DTO.ReservationStatusesDTO();
                status.Name        = "OPEN";
                status.Description = "RESERVATION IS OPEN";
                Domain.ReservationStatusesManager.CreateStatus(status);

                var newStatus = Domain.ReservationStatusesManager.RetrieveStatus();

                var reservation = new DTO.ReservationsDTO();


                reservation.CarID         = car.CarID;
                reservation.ReservStatsID = newStatus.ReservStatsID;
                reservation.CostumerID    = Convert.ToInt32(clientIdTextBox.Text);
                reservation.StartDate     = startDateDateTimePicker.Value;
                reservation.EndDate       = endDateDateTimePicker.Value;
                reservation.Location      = cityTextBox.Text;
                Domain.ReservationsManager.RegisterNewCarRent(reservation);
                MessageBox.Show("Registered Successfully!");
            }
        }
Exemple #3
0
        private void updateRentbutton_Click(object sender, EventArgs e)
        {
            var reservations = Domain.ReservationsManager.ListReservations();

            if (updateCarPlateTextBox.Text.Trim().Length == 0)
            {
                MessageBox.Show("Plate is a mendatory field");
                return;
            }

            else if (Domain.ReservationsManager.FindCarIdByPlate(updateCarPlateTextBox.Text) == null)
            {
                MessageBox.Show("Car is Not Listed");
                return;
            }


            else if (DoesExist(reservations, updateCarPlateTextBox.Text) == false)
            {
                MessageBox.Show("Please Enter a Plate From Existing Reservation");
                return;
            }

            else if (updateClientIdTextBox.Text.Trim().Length == 0)
            {
                MessageBox.Show("Client Id is a Manndatory Field");
                return;
            }

            else if (clientIDMatchPlate(reservations, updateCarPlateTextBox.Text, updateClientIdTextBox.Text) == false)
            {
                MessageBox.Show("ID and Plate Should Match");
                return;
            }

            //else if (updateStartDateDateTimePicker.Value.Date < DateTime.Now.Date)
            //{
            //    MessageBox.Show("Please Select a Valid Start Date");
            //    return;
            //}

            else if (startDateMatch(reservations, updateCarPlateTextBox.Text, updateClientIdTextBox.Text,
                                    updateStartDateDateTimePicker.Value.Date) == false)
            {
                MessageBox.Show("StartDate Doesn't Match any Reservations");
                return;
            }


            //else if (updateStartDateDateTimePicker.Value.Date >= updateEndDateDateTimePicker.Value.Date)
            //{
            //    MessageBox.Show("Please Select a Valid End Date");
            //    return;
            //}

            else if (endDateMatch(reservations, updateCarPlateTextBox.Text, updateClientIdTextBox.Text,
                                  updateEndDateDateTimePicker.Value.Date) == false)
            {
                MessageBox.Show("EndtDate Doesn't Match any Reservations");
                return;
            }

            else if (updateCityTextBox.Text.Trim().Length == 0)
            {
                MessageBox.Show("City is a Manndatory Field");
                return;
            }


            else if (cityMatch(reservations, updateCarPlateTextBox.Text, updateClientIdTextBox.Text, updateEndDateDateTimePicker.Value.Date, updateCityTextBox.Text) == false)
            {
                MessageBox.Show("City Doesn't Match any Reservations");
                return;
            }

            //else if (AlreadyCanceled(reservations, updateCarPlateTextBox.Text, updateClientIdTextBox.Text, updateEndDateDateTimePicker.Value.Date, updateCityTextBox.Text) == true)
            //{
            //    MessageBox.Show("Can't Cancel. Already Canceled");
            //    return;
            //}


            else
            {
                var reservation = new DTO.ReservationsDTO();
                var carPlate    = updateCarPlateTextBox.Text;
                var car         = Domain.ReservationsManager.FindCarIdByPlate(carPlate);

                var reserv = reservations.Find(p => p.CarID == car.CarID && p.CostumerID == Convert.ToInt32(updateClientIdTextBox.Text) &&
                                               p.StartDate == updateStartDateDateTimePicker.Value.Date && p.EndDate == updateEndDateDateTimePicker.Value.Date).ReservStatsID;

                var reservStat = new ReservationStatusesDTO()
                {
                    ReservStatsID = reserv, Name = "CANCELED", Description = "CANCELED"
                };

                Domain.ReservationStatusesManager.UpdateStatus(reservStat);

                //var status = new DTO.ReservationStatusesDTO();
                //status.Name = "UPDATE";
                //status.Description = "RESERVATION IS OPEN";
                //Domain.ReservationStatusesManager.CreateStatus(status);

                //var newStatus = Domain.ReservationStatusesManager.RetrieveStatus();


                //reservation.CarID = car.CarID;
                //reservation.ReservStatsID = newStatus.ReservStatsID;
                //reservation.CostumerID = Convert.ToInt32(updateClientIdTextBox.Text);
                //reservation.StartDate = updateStartDateDateTimePicker.Value;
                //reservation.EndDate = updateEndDateDateTimePicker.Value;
                //reservation.Location = updateCityTextBox.Text;
                //Domain.ReservationsManager.UpdateCarRent(reservation);
                MessageBox.Show("Updated Successfully!");
            }
        }
Exemple #4
0
 public static void RegisterNewCarRent(DTO.ReservationsDTO reservationsDTO)
 {
     Persistence.ReservationsRepository.RegisterNewCarRent(reservationsDTO);
 }