// Edit a Borrower // Ability to borrow a book if available public void BorrowBook(BorrowerBooksAccount BorrowerBooksAccount, bool isBorrowing) { try { // Get the list of books var books = _redisCacheProvider.GetAll <Book>(); var borrowers = _redisCacheProvider.GetAll <Borrower>(); ValidateBorrowBook(BorrowerBooksAccount, books, borrowers, isBorrowing); // create a borrowerBookAccount for new Account to be created var bbaToCreate = BorrowerBooksAccount.Map(); if (isBorrowing) { bbaToCreate.Id = _redisCacheProvider.GetNextSequenceForBorrowerBookAccount(); } _redisCacheProvider.SaveBorrowerBooksAccount(bbaToCreate); // Update the Book var book = books.FirstOrDefault(x => x.Id == bbaToCreate.BookId); if (book == null) { throw new Exception("Cannot find the book"); } book.IsAvailable = false; _redisCacheProvider.SaveBook(book); } catch (Exception ex) { throw new Exception(ex.Message); } }