Beispiel #1
0
        /// <summary>
        /// get specific booking detail info
        /// </summary>
        public void GetSpecificBookingDetailsInfo()
        {
            try
            {
                var bookingDetails = new GetAllBookingDetails();
                Console.WriteLine($"Here are all existing Booking Details:\n");
                bookingDetails.GetAllBookingDetailsInfo();

                Console.WriteLine($"\nChoose specific Booking Detail to view by entering Booking Id ");
                var userInput     = Convert.ToInt32(Console.ReadLine());
                var bookingDetail = _bicycleRentalDbContext.Booking_details.Find(userInput);

                if (bookingDetail == null)
                {
                    Console.WriteLine("No bookingDetail was found..");
                    Visuals.ReturnToMainMenu();
                }

                Console.Clear();

                Console.WriteLine($"Your specific Booking Detail: ");
                Console.WriteLine($"Booking_id: {bookingDetail.Booking_id}");
                Console.WriteLine($"Booking_date: {bookingDetail.Booking_date.ToShortDateString()}");
                Console.WriteLine($"Return_due_date: {bookingDetail.Return_due_date.ToShortDateString()}");
                Console.WriteLine($"Rental_price: {bookingDetail.Rental_price}");
                Console.WriteLine($"Customer_id: {bookingDetail.Customer_id}");
                Console.WriteLine($"Bicycle_id: {bookingDetail.Bicycle_id}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"You messed up! {ex}");
            }
        }
        public void DeleteExistingCustomer()
        {
            try
            {
                var bookingDetails = new GetAllBookingDetails();
                bookingDetails.GetAllBookingDetailsInfo();

                Console.WriteLine("Choose booking detail to delete by entering Booking Id: ");
                var userinput = Convert.ToInt32(Console.ReadLine());

                var getBookingDetail      = new ReturnBookingDetails();
                var bookingDetailToDelete = getBookingDetail.Return_BookingDetail(userinput);

                if (bookingDetailToDelete == null)
                {
                    Console.WriteLine("No Booking Detail was found..");
                    Visuals.ReturnToMainMenu();
                }

                _bicycleRentalDbContext
                .Booking_details
                .Remove(bookingDetailToDelete);

                _bicycleRentalDbContext
                .SaveChanges();

                Console.WriteLine($"Existing booking details with booking id: {bookingDetailToDelete.Booking_id} deleted successfully!");
            }

            catch (Exception ex)
            {
                Console.WriteLine($"You messed up! {ex}");
            }
        }
        public void UpdateExistingBookingDetails()
        {
            try
            {
                var bookingDetail = new GetAllBookingDetails();
                bookingDetail.GetAllBookingDetailsInfo();

                Console.WriteLine("Choose Booking detail to update by entering Booking Id: ");
                var userinput = Convert.ToInt32(Console.ReadLine());

                var getBookingDetail      = new ReturnBookingDetails();
                var bookingDetailToUpdate = getBookingDetail.Return_BookingDetail(userinput);

                if (bookingDetailToUpdate == null)
                {
                    Console.WriteLine("No Booking Detail was found..");
                    Visuals.ReturnToMainMenu();
                }

                Console.WriteLine("Change Booking detail information");
                Console.WriteLine("");
                Console.WriteLine("Update Booking_date");
                bookingDetailToUpdate.Booking_date = Convert.ToDateTime(Console.ReadLine());
                Console.WriteLine("Update Return_due_date");
                bookingDetailToUpdate.Return_due_date = Convert.ToDateTime(Console.ReadLine());
                Console.WriteLine("Update Rental_price");
                bookingDetailToUpdate.Rental_price = float.Parse(Console.ReadLine());
                Console.WriteLine("Customer_id");
                bookingDetailToUpdate.Customer_id = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Bicycle_id");
                bookingDetailToUpdate.Bicycle_id = Convert.ToInt32(Console.ReadLine());

                _bicycleRentalDbContext
                .Booking_details
                .Update(bookingDetailToUpdate);

                _bicycleRentalDbContext
                .SaveChanges();

                Console.WriteLine("Existing Booking detail updated successfully!");
                Console.WriteLine("");
                Console.WriteLine("---------------------------------------");
                Console.WriteLine($"Customer Booking_date: {bookingDetailToUpdate.Booking_date}");
                Console.WriteLine($"Customer Return_due_date: {bookingDetailToUpdate.Return_due_date}");
                Console.WriteLine($"Customer Rental_price: {bookingDetailToUpdate.Rental_price}");
                Console.WriteLine($"Customer Customer_id: {bookingDetailToUpdate.Customer_id}");
                Console.WriteLine($"Customer Bicycle_id: {bookingDetailToUpdate.Bicycle_id}");
                Console.WriteLine("---------------------------------------");
            }

            catch (Exception ex)
            {
                Console.WriteLine($"You messed up! {ex}");
            }
        }