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); }
public List <Customer> GetListOfCustomersWithBirthdayToday() { var customersWithBirthday = new List <Customer>(); foreach (Customer customer in customerManager.GetAllCustomers()) { if (customer.DateOfBirth.Month == DateTime.Today.Month && customer.DateOfBirth.Day == DateTime.Today.Day) { customersWithBirthday.Add(customer); if (DateTime.Today.Year - customer.DateOfBirth.Year == 15) { borrowManager.AddBorrow(customer, SendMostPopularBook(customer)); } } } return(customersWithBirthday); }
public BorrowErrorCodes BorrowBook(int customerID, string bookTitle) { var customer = customerManager.GetCustomer(customerID); if (customer == null) { return(BorrowErrorCodes.NoSuchCustomer); } var book = bookManager.GetListOfBooksByTitle(bookTitle); if (book == null) { return(BorrowErrorCodes.NoSuchBook); } if (customer.Borrows != null && CheckIfCustomerAlreadyBorrowedBook(customer, book.First()) == true) { return(BorrowErrorCodes.CustomerBorrowHasBeenExteneded); } if (CheckIfCanBorrow(customer) == false) { return(BorrowErrorCodes.CustomerNotAllowedToBorrowMoreBooks); } var availableBook = new List <Book>(); foreach (Book book1 in book) { if (book1.Borrow == null) { availableBook.Add(book1); } } if (availableBook.Count == 0) { return(BorrowErrorCodes.BookAlreadyBorrowed); } borrowManager.AddBorrow(customer, availableBook.First()); return(BorrowErrorCodes.ok); }