Пример #1
0
        public static void createBook()
        {
            Console.Clear();
            Console.WriteLine("Enter title of your book");
            string bookName = Console.ReadLine();

            Console.WriteLine("Enter pages");
            int pages;

            int.TryParse(Console.ReadLine(), out pages);
            Library library = loadLibraryFromXml("library.xml");

            library.ShowAuthors();
            Console.WriteLine("chose author id: ");
            int    authorId = Convert.ToInt32(Console.ReadLine());
            Author a        = Author.findAuthorById(authorId);

            Console.WriteLine("chose Departament");
            library.SortDepartamentsByBooks();
            int         depId = Convert.ToInt32(Console.ReadLine());
            Departament d     = library.FindDepartamentById(depId);
            Book        b     = new Book();

            b.author      = a;
            b.AuthorId    = authorId;
            b.Pages       = pages;
            b.Title       = bookName;
            b.departament = d;
            library.Departaments.Find(x => x.Id == depId).books.Add(b);
            XmlSerializer ser = new XmlSerializer(typeof(Library));
            StreamWriter  sw  = new StreamWriter("library.xml");

            ser.Serialize(sw, library);
            sw.Close();
        }
Пример #2
0
        public static void DeleteDepartament(Library library, int departamentId, string FileName)
        {
            Departament departament = library.FindDepartamentById(departamentId);

            library.Departaments.Remove(departament);
            XmlSerializer serializer = new XmlSerializer(typeof(Library));
            StreamWriter  sw         = new StreamWriter(FileName);

            serializer.Serialize(sw, library);
            sw.Close();
        }
Пример #3
0
        public static void UpdateDepartament(Library libarary, int depID, string Filename)
        {
            Departament departament = libarary.FindDepartamentById(depID);

            Console.WriteLine("------current departament--------");
            Console.WriteLine(departament.ToString());
            Console.WriteLine("Enter new name of departament");
            string NewDepName = Console.ReadLine();

            departament.DepName = NewDepName;
            Console.WriteLine("Save all departaments books?(Yes/No)");
            string choice = Console.ReadLine();

            if (choice.ToLower().Trim().Equals("no"))
            {
                departament.books.Clear();
            }
            XmlSerializer serilaizer = new XmlSerializer(typeof(Library));
            StreamWriter  sw         = new StreamWriter(Filename);

            serilaizer.Serialize(sw, libarary);
            sw.Close();
            Console.WriteLine("Succesfull updeate");
        }