public async Task <LendingRecord> CheckoutAsync(string bookId)
        {
            if (string.IsNullOrWhiteSpace(bookId))
            {
                throw new ArgumentException("bookId cannot be null");
            }

            var book = await BookService.GetBookByIdAsync(bookId);

            if (book == null)
            {
                throw new DomainOperationException(string.Format("the book with id \"{0}\" could not be found.", bookId));
            }
            if (!book.IsAvailable)
            {
                throw new DomainOperationException("that book is not available for checkout");
            }

            var lendingRecord = LendingRecord.Create(book.Id, "asdf");

            book.Checkout(lendingRecord);

            await LendingRecordStore.CreateAsync(lendingRecord);

            await BookService.UpdateBookAsync(book);

            return(lendingRecord);
        }
示例#2
0
 internal void Checkout( LendingRecord lendingRecord )
 {
     if( !IsAvailable )
     {
         throw new DomainOperationException( "this book is not available for checkout" );
     }
     LendingRecordId = lendingRecord.Id;
     IsAvailable = false;
 }
示例#3
0
 internal void Checkout(LendingRecord lendingRecord)
 {
     if (!IsAvailable)
     {
         throw new DomainOperationException("this book is not available for checkout");
     }
     LendingRecordId = lendingRecord.Id;
     IsAvailable     = false;
 }
        public async Task <LendingRecord> CheckinAsync(string bookId)
        {
            LendingRecord record = await LendingRecordStore.GetRecordWithBookIdAsync(bookId);

            if (record == null)
            {
                throw new DomainOperationException("this book could not be checked in because is it not currently on loan.");
            }

            var book = await BookService.GetBookByIdAsync(bookId);

            book.Checkin();
            record.Checkin();

            await BookService.UpdateBookAsync(book);

            await LendingRecordStore.UpdateAsync(record);

            return(record);
        }