on master help sign in
47 lines 1.9 kB history raw
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using static ConsoleApp1.Reader;
8namespace ConsoleApp1
9{
10 class Program
11 {
12 static void Main()
13 {
14 var lib = new Library();
15 while (true) {
16 Console.WriteLine("1 - Add Book \n2- write file \n3 - read file \n4 - print library");
17 switch (Console.ReadLine()) {
18 case "1":
19 var book = new Book() {
20 name = GetString("Book name:"),
21 author = GetString("Author name: "),
22 pageCount = GetInt("Page count: ", x => x > 0, "that is not a valid positive int."),
23 dateAdded = GetDate("Date released in dd.mm.yyyy: ", _ => true, "That is not a valid date."),
24 isSpecialEdition = GetBool("Is special edition: ", "That is not a valid bool.")
25 };
26 if (book.isSpecialEdition) {
27 book.value = GetInt("Special edition value: ", x => x > 0, "that is not a valid positive int.");
28 }
29 lib.Add(book);
30 break;
31 case "4":
32 foreach(var b in lib) {
33 Console.WriteLine(b);
34 }
35 break;
36 case "2":
37 lib.SerializeAll("../../../lib.xml");
38 break;
39 case "3":
40 lib.ReadXMLFrom("../../../lib.xml");
41 break;
42 }
43 Console.WriteLine();
44 }
45 }
46 }