//Prompts user for id and rents movie. Updates inventory and adds to transactions public static void RentMovie() { Console.Clear(); Console.WriteLine("\nRENT MOVIE\n"); String input; int id; int index = -1; TransactionFile tf = new TransactionFile(); MovieFile mf = new MovieFile(); Movie[] movieInventory = mf.ReadFile(); ViewAvailableMovies(); Console.WriteLine("\nEnter email address: "); String email = Console.ReadLine(); while (index == -1) { Console.WriteLine("\nEnter movie ID to rent:\t(Enter 0 to input movie title instead)"); input = Console.ReadLine(); if (input.All(char.IsNumber)) { id = int.Parse(input); if (id == 0) { Console.WriteLine("\nEnter movie title to rent: "); input = Console.ReadLine(); index = Program.GetMovieIndex(movieInventory, input); } else { index = Program.GetMovieIndex(movieInventory, id); } if (index == -1) { Console.WriteLine("\tError: Movie not found."); } } else { Console.WriteLine("\tError: Enter only numeric values."); } if (index != -1) { if (movieInventory[index].GetStock() == false) { Console.WriteLine("\tError: Selected movie is unavailable. Please select a different movie."); index = -1; } } } movieInventory[index].SetStock(); mf.WriteFile(movieInventory); String[] dateDelin = DateTime.Now.ToString().Split(' '); String rentDate = dateDelin[0]; Transaction[] transactions = tf.ReadFile(); tf.IncrementCount(); Transaction newTransaction = new Transaction(tf.GetID(), email, movieInventory[index].GetMovieID(), rentDate); int count = tf.GetCount(); Transaction[] updatedTransactions = new Transaction[count]; for (int i = 0; i < count - 1; i++) { updatedTransactions[i] = transactions[i]; } updatedTransactions[updatedTransactions.Length - 1] = newTransaction; Console.WriteLine($"\nRented movie: {movieInventory[index].ReadString()}"); tf.WriteFile(updatedTransactions); }