Exemplo n.º 1
0
        public CancelCustomerStatusCodes CancelCustomer(int customerNumber)
        {
            var customer = customerManager.GetCustomerByCustomerNumber(customerNumber);

            if (customer == null)
            {
                return(CancelCustomerStatusCodes.NoSuchCustomer);
            }
            if (customer.IsGuardian == true)
            {
                return(CancelCustomerStatusCodes.CustomerIsGuardian);
            }
            if (customer.Debt > 0)
            {
                return(CancelCustomerStatusCodes.CustomerHasUnpaidDebt);
            }
            var borrow = borrowManager.GetAllCurrentBorrowFromCustomer(customerNumber);

            if (borrow.Count > 0)
            {
                return(CancelCustomerStatusCodes.CustomerHasBorrowedBooks);
            }

            customerManager.CancelCustomer(customer.CustomerID);
            return(CancelCustomerStatusCodes.Ok);
        }
Exemplo n.º 2
0
        public AddBorrowStatusCodes AddBorrow(int customerNumber, string bookTitle)
        {
            var newBorrowDate = DateTime.Today;
            var newReturnDate = DateTime.Today.AddDays(30);

            var customer = customerManager.GetCustomerByCustomerNumber(customerNumber);

            if (customer == null)
            {
                return(AddBorrowStatusCodes.NoSuchCustomer);
            }
            var book = bookManager.GetBookByBookTitle(bookTitle);

            if (book == null)
            {
                return(AddBorrowStatusCodes.NoSuchBook);
            }
            var newBorrow = borrowManager.GetBorrowFromCustomerAndBook(customerNumber, bookTitle);

            if (book.IsBorrowed == true)
            {
                if (newBorrow != null && customer.Debt == 0)
                {
                    borrowManager.ExtendBorrowDate(newBorrow.BorrowID, newBorrowDate, newReturnDate);
                    borrowManager.AddToHistoryListOfBorrow(customerNumber, bookTitle, newBorrowDate);
                    return(AddBorrowStatusCodes.ExtendBorrowForCustomer);
                }
                else if (newBorrow != null && customer.Debt > 0)
                {
                    return(AddBorrowStatusCodes.CustomerHasDebtCanNotExtendBorrow);
                }

                return(AddBorrowStatusCodes.BookIsUnavailable);
            }
            if (borrowManager.GetAllCurrentBorrowFromCustomer(customerNumber).Count >= 5)
            {
                return(AddBorrowStatusCodes.CustomerCanNotExceedMaxBookQuantity);
            }
            if (customer.Debt > 0)
            {
                return(AddBorrowStatusCodes.CustomerHasDebt);
            }

            borrowManager.AddBorrow(customerNumber, bookTitle, newBorrowDate, newReturnDate);
            borrowManager.AddBorrowToBook(bookTitle, true, newBorrow);
            borrowManager.AddToHistoryListOfBorrow(customerNumber, bookTitle, newBorrowDate);
            return(AddBorrowStatusCodes.Ok);
        }