public void PrintBookTc(BookTestContent testContent) { int counter = 1; foreach (Book b in books) { Console.WriteLine("Books:\n" + counter + ". " + b.title); } Console.Write("Choose a book: "); string input = Console.ReadLine(); int indexChoice; while (!Int32.TryParse(input, out indexChoice) || indexChoice < 1 || indexChoice > books.Length) { Console.WriteLine("Invalid input..."); Console.Write("Choose a book: "); input = Console.ReadLine(); } indexChoice--; List <BookInfo> bookInfo = testContent.TestContent.FindAll(o => o.BookTitle == books[indexChoice].title); foreach (BookInfo b in bookInfo) { Console.WriteLine("Book Title: " + b.BookTitle); Console.WriteLine("Book Author: " + b.BookAuthor); Console.WriteLine("Question: " + b.KeyInfo); foreach (string info in b.InfoList) { Console.WriteLine("\t--" + info); } Console.WriteLine("-------------------------------------------------------------"); } }
public void MainProgram(BookTestContent testList) { string input = ""; bool quit = false; //BookTestContent testList = new BookTestContent(); do { Console.WriteLine("\n1. Add test content\n2. Print test content\n3. Quit"); Console.Write("Enter 1-3:"); input = Console.ReadLine(); switch (input) { case "1": Console.WriteLine("TODO"); break; case "2": Console.WriteLine("TODO"); testList.SortByTitle(); PrintBookTc(testList); break; case "3": quit = true; break; default: Console.WriteLine("Invalid input..."); break; } } while(!quit); }
public void SaveToJson(BookTestContent testContent, string fileName) { var options = new JsonSerializerOptions { WriteIndented = true, }; string jsonString = JsonSerializer.Serialize(testContent, options); Console.WriteLine("Saving to file..."); System.IO.File.WriteAllText(fileName, jsonString); }
public BookTestContent LoadFromFile(string file) { BookTestContent btc = null; try { string json = System.IO.File.ReadAllText(file); btc = JsonSerializer.Deserialize <BookTestContent>(json); return(btc); } catch (System.IO.FileNotFoundException) { Console.WriteLine("File does not exist..."); } return(btc); }
static void Main(string[] args) { Program program = new Program(1); BookTestContent testContent = new BookTestContent(); Console.WriteLine("Input a file name (no extension): "); Console.Write(">"); string readFileName = Console.ReadLine(); testContent = program.LoadFromFile("../../json/" + readFileName + ".json"); /* * List<string> infoList = new List<string>(); * infoList.Add("First bullet point"); * infoList.Add("Second bullet point"); * infoList.Add("Third bullet point"); * testContent.AddTestContent(program.books[0].title, program.books[0].author, "This is a test question", infoList); * testContent.AddTestContent(program.books[0].title, program.books[0].author, "This is a test2 question", infoList); * testContent.AddTestContent(program.books[0].title, program.books[0].author, "This is a test3 question", infoList); * testContent.AddTestContent(program.books[0].title, program.books[0].author, "This is a test4 question", infoList); * * testContent.AddTestContent(program.books[1].title, program.books[1].author, "This is a test question", infoList); * testContent.AddTestContent(program.books[1].title, program.books[1].author, "This is a test2 question", infoList); * testContent.AddTestContent(program.books[1].title, program.books[1].author, "This is a test3 question", infoList); * testContent.AddTestContent(program.books[1].title, program.books[1].author, "This is a test4 question", infoList); * * testContent.AddTestContent(program.books[2].title, program.books[2].author, "This is a test question", infoList); * testContent.AddTestContent(program.books[2].title, program.books[2].author, "This is a test2 question", infoList); * testContent.AddTestContent(program.books[2].title, program.books[2].author, "This is a test3 question", infoList); * testContent.AddTestContent(program.books[2].title, program.books[2].author, "This is a test4 question", infoList); * * testContent.AddTestContent(program.books[3].title, program.books[3].author, "This is a test question", infoList); * testContent.AddTestContent(program.books[3].title, program.books[3].author, "This is a test2 question", infoList); * testContent.AddTestContent(program.books[3].title, program.books[3].author, "This is a test3 question", infoList); * testContent.AddTestContent(program.books[3].title, program.books[3].author, "This is a test4 question", infoList); */ program.MainProgram(testContent); Console.WriteLine("Input a file name (no extension): "); Console.Write(">"); string writeFileName = Console.ReadLine(); program.SaveToJson(testContent, "../../json/" + writeFileName + ".json"); }
public void TestMenu() { BookTestContent testContent = new BookTestContent(); List <string> infoList = new List <string>(); infoList.Add("First bullet point"); infoList.Add("Second bullet point"); infoList.Add("Third bullet point"); testContent.AddTestContent("Title", "Author", "This is a test question", infoList); var options = new JsonSerializerOptions { WriteIndented = true, }; string jsonString = JsonSerializer.Serialize(testContent, options); Console.WriteLine(jsonString); System.IO.File.WriteAllText("../../json/testingData.json", jsonString); }