Пример #1
0
        public static void PopulateLibrary()
        {
            var cli = new LibraryManagerClient();

            cli.Open();
            cli.AddBook("123", "A22", "C# For Dummmies", "Martin Fowler", "Programming");
            cli.AddBook("1234", "A21", "Japanese Cooking", "Nakamoto", "Cooking");
            cli.AddBook("1235", "A27", "How to be Rich", "Jonathan Martin", "SelfHelping");
            cli.AddBook("12376", "A28", "Java Spring", "Michael Jr", "Programming");
            cli.AddBook("1235000", "A30", "Body Language Expert", "Jonathan Martin", "SelfHelping");
            cli.AddBook("1234", "A45", "Cool Places in Japan", "Nakamoto", "Tourism");
            cli.Close();
        }
Пример #2
0
        public bool BorrowBook(string code, string client, DateTime date)
        {
            try
            {
                if (!authenticated)
                {
                    throw new FaultException <NotAuthenticatedException>(new NotAuthenticatedException($"Restricted Area"));
                }

                using (var cli = new LibraryManagerClient())
                {
                    cli.Open();

                    var book = cli.GetBooksByCode(code);

                    if (book == null)
                    {
                        throw new FaultException <BookNotFoundException>(new BookNotFoundException($"Book Code {code} Not Found"),
                                                                         new FaultReason($"Book Code {code} Not Found"));
                    }

                    lock (locker)
                    {
                        if (book.IsBorrowed)
                        {
                            throw new FaultException <BookBorrowedException>(new BookBorrowedException($"Book Code {code} already borrowed"),
                                                                             new FaultReason($"Book Code {code} already borrowed"));
                        }

                        var loans = cli.GetLoansFromClient(client);

                        if (loans.Count == MAX_BOOKS_ALLOWED)
                        {
                            throw new FaultException <MaximumExceededException>(new MaximumExceededException($"You cannot borrow more than {MAX_BOOKS_ALLOWED} books"),
                                                                                new FaultReason($"You cannot borrow more than {MAX_BOOKS_ALLOWED} books"));
                        }

                        cli.UpdateToBorrowed(book.Id, client, date);
                    }


                    cli.Close();
                }

                return(true);
            }
            catch { throw; }
        }
Пример #3
0
        public static void SearchBooks()
        {
            var cli   = new LibraryManagerClient();
            var books = cli.GetBooksBySubject("SelfHelping");

            Console.WriteLine("Books of SelfHelping");
            PrintBooks(books);

            Console.WriteLine("\n\n\n");

            books = cli.GetBooksByAuthor("Nakamoto");
            Console.WriteLine("Books from Nakamoto");
            PrintBooks(books);

            Console.WriteLine("\n\n\n");

            cli.Close();
        }
Пример #4
0
        public bool ReturnBook(string code, string client, DateTime date)
        {
            try {
                if (!authenticated)
                {
                    throw new FaultException <NotAuthenticatedException>(new NotAuthenticatedException($"Restricted Area"));
                }


                using (var cli = new LibraryManagerClient())
                {
                    cli.Open();
                    var book = cli.GetBooksByCode(code);

                    if (book == null)
                    {
                        throw new FaultException <BookNotFoundException>(new BookNotFoundException($"Book Code {code} Not Found"));
                    }

                    if (!book.IsBorrowed)
                    {
                        throw new FaultException <BookReturnedException>(new BookReturnedException($"Book Code {code} already returned"));
                    }

                    var loan = cli.GetLoan(book.Id);

                    var delay = date - loan.LoanDate;

                    if (delay.Days > MAX_DAYS_ALLOWED)
                    {
                        throw new FaultException <FineException>(new FineException($"Fine of $ {(delay.Days - MAX_DAYS_ALLOWED) * FINE }"));
                    }

                    cli.UpdateToAvaible(book.Id, client, date);

                    cli.Close();
                }

                return(true);
            }
            catch { throw; }
        }