public bool Handle(UserReturnBookEvent message)
        {
            string updateHistorySql = @"UPDATE [BookTransferHistory] SET 
[Returned]=@returned, [ReturnedDate]=@returnedDate WHERE [UserID]=@userId AND [BookID]=@bookId";
            Guid?  userId           = this.GetIDByAggregateRootId("UserAccounts", message.UserAccountId);

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

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

            return(rowsAffected > 0);
        }
Exemple #2
0
 private void HandleEvent(UserReturnBookEvent domainEvent)
 {
     using (QueryDBEntities _dbContext = new QueryDBEntities())
     {
         BorrowRecord record = _dbContext.BorrowRecord.FirstOrDefault(t => t.UserAggregateRootId == domainEvent.UserAggregateRootId && t.BookAggregateRootId == domainEvent.BookAggregateRootId && !t.Returned);
         record.Returned                = true;
         record.ReturnedDate            = domainEvent.ReturnedDate;
         _dbContext.Entry(record).State = EntityState.Modified;
         _dbContext.SaveChanges();
     }
 }
 private void HandleReturnBookEvent(UserReturnBookEvent e)
 {
     this.bookIds.Remove(e.BookId);
 }
Exemple #4
0
 public void HandleEvent(UserReturnBookEvent e)
 {
     this._bookIds.Remove(e.BookAggregateRootId);
 }