public bool Handle(UserBorrowBookEvent message)
        {
            string insertHistorySql = @"INSERT INTO [BookTransferHistory] 
 ([UserID], [BookID], [Returned], [ReturnedDate], [BorrowedDate]) VALUES
 (@userId, @bookId, @returned, @returnedDate, @borrowedDate)";
            Guid?  userGUID         = this.GetIDByAggregateRootId("UserAccounts", message.UserAccountId);

            if (userGUID == null)
            {
                throw new InvalidOperationException(string.Format("Cannot find the UserAccount with the AggregateRootId={0}", message.UserAccountId));
            }
            Guid?bookGUID = this.GetIDByAggregateRootId("Books", message.BookId);

            if (bookGUID == null)
            {
                throw new InvalidOperationException(string.Format("Cannot find the Book with the AggregateRootId={0}", message.BookId));
            }
            var rowsAffected = SqlHelper.ExecuteNonQuery(this.QueryDBConnectionString,
                                                         CommandType.Text,
                                                         insertHistorySql,
                                                         new SqlParameter("@userId", userGUID.Value),
                                                         new SqlParameter("@bookId", bookGUID.Value),
                                                         new SqlParameter("@returned", false),
                                                         new SqlParameter("@returnedDate", SqlDateTime.MinValue),
                                                         new SqlParameter("@borrowedDate", new SqlDateTime(message.TransferDateTime)));

            return(rowsAffected > 0);
        }
Example #2
0
 private void HandleEvent(UserBorrowBookEvent domainEvent)
 {
     using (QueryDBEntities _dbContext = new QueryDBEntities())
     {
         BorrowRecord record = new BorrowRecord
         {
             UserAggregateRootId = domainEvent.UserAggregateRootId,
             BookAggregateRootId = domainEvent.BookAggregateRootId,
             BorrowedDate        = domainEvent.BorrowedDate
         };
         _dbContext.BorrowRecord.Add(record);
         _dbContext.SaveChanges();
     }
 }
 private void HandleBorrowBookEvent(UserBorrowBookEvent e)
 {
     this.bookIds.Add(e.BookId);
 }
Example #4
0
 public void HandleEvent(UserBorrowBookEvent e)
 {
     this._bookIds.Add(e.BookAggregateRootId);
 }