Exemplo n.º 1
0
        static void Main2(string[] args)
        {
            List <int> numbers = new List <int> {
                1, 8, 5, 3, 7, 4, 2, 6
            };

            List <int> evenNumbers = numbers
                                     .Where(c => c % 2 == 0)
                                     .OrderBy(c => c)
                                     .ToList();

            bool s = numbers.Count(c => c % 2 == 0) >= 3;

            var list2 = numbers.OrderByDescending(c => c).ToList();

            List <int> oddNumbers = new List <int>();

            for (int i = 0; i < numbers.Count; i++)
            {
                if (numbers[i] % 2 == 0)
                {
                    oddNumbers.Add(numbers[i]);
                }
            }

            var s23 = numbers.Count(c => c % 2 == 0) >= 3;

            using (BookService service = new BookService())
            {
                List <Book> books = service.GetAll();

                Book book = books.FirstOrDefault();

                book.Quantity++;
                service.EditBook(book);

                Book book2 = service.GetBookByID(book.ID);

                Book newBook = new Book {
                    Author      = "Mecho Puh",
                    Title       = "прасчо и аз",
                    Description = "дълго е за разказване",
                    Genre       = "приказки",
                    Quantity    = 1,
                    CreatedDate = DateTime.Now
                };

                service.AddBook(newBook);


                var booksByAuthor = service.GetByAuthor("Puh");
                if (booksByAuthor.Count > 0)
                {
                    int bookID = booksByAuthor.First().ID;
                    service.DeleteBook(bookID);
                }
            }

            LibraryContext context = new LibraryContext();
            var            x       = context.Books.ToList();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (BookService service = new BookService())
            {
                List <Book> books = service.GetAll();

                // test if we get date from the DB
                Book book = books.FirstOrDefault();

                // edit a book
                book.Quantity++;
                service.EditBook(book);

                // get book by ID
                Book book2 = service.GetBookByID(book.ID);

                // add new book
                Book newBook = new Book
                {
                    Author      = "Microsoft",
                    Title       = "Creating API",
                    Description = "книга за програмиране",
                    Genre       = "programming",
                    Quantity    = 1,
                    CreatedDate = DateTime.Now
                };
                service.AddBook(newBook);

                // find book by author and delete if we have > 1
                var booksByAuthor = service.GetByAuthor("Microsoft");
                if (booksByAuthor.Count > 1)
                {
                    int bookID = booksByAuthor.Last().ID;
                    service.DeleteBook(bookID);
                }
            }

            //// another way to get all books - do not use this way, use BookService
            //LibraryContext context = new LibraryContext();
            //var x = context.Books.ToList();


            using (ReaderService readerService = new ReaderService())
            {
                // add new reader
                Reader newReader = new Reader
                {
                    FirstName   = "reader",
                    LastName    = DateTime.Now.ToShortTimeString(),
                    PhoneNumber = "08812345678",
                    CreatedDate = DateTime.Now
                };
                readerService.AddReader(newReader);

                int readerID = newReader.ID;

                // get reader by ID
                Reader reader2 = readerService.GetReaderByID(readerID);

                // edit reader
                reader2.FirstName = "reader " + readerID;
                readerService.EditReader(reader2);
            }

            using (BookService bookService = new BookService())
                using (ReaderService readerService = new ReaderService())
                {
                    // get some valid IDs
                    int bookID   = bookService.GetByAuthor("Microsoft").First().ID;
                    int readerID = readerService.GetAll().Last().ID;

                    // borrow book
                    readerService.BorrowBook(readerID, bookID);

                    // return book
                    Thread.Sleep(50);
                    readerService.ReturnBook(readerID, bookID);
                }
        }