public bool CheckoutBook(CheckoutDataModel dataModel) { string sql = "insert into customer_book_checkout (customer_id, book_id, checkout_date) values (@customer_id, @book_id, CURDATE());"; var affectedRows = _dbConnection.Execute(sql, dataModel); if (affectedRows == 1) { return(true); } return(false); }
public bool CheckoutABook(CheckoutRequest checkout) { //Check if the customer exists if (_libraryQuery.GetCustomerByIdentifier(checkout.CustomerIdentifier) == null) { throw new Exception("The customer does not exist in this system"); } //Check if book exists if (_libraryQuery.GetBookByIdentifier(checkout.BookIdentifier) == null) { throw new Exception("The book does not exist in this system"); } //Check if Book is available for checkout if (_libraryQuery.IsBookCheckedOut(checkout.BookIdentifier)) { throw new Exception("The book is already checked out and is unavailable"); } //Check if user has too many books checked out List <BookDataModel> dataModels = _libraryQuery.GetBooksByUser(checkout.CustomerIdentifier); if (dataModels == null || dataModels.Count >= 5) { throw new Exception("The customer has too many books checked out"); } //Perform checkout CheckoutDataModel datamodel = new CheckoutDataModel() { BOOK_ID = checkout.BookIdentifier, CUSTOMER_ID = checkout.CustomerIdentifier }; bool result = _libraryQuery.CheckoutBook(datamodel); return(result); }