public async Task <int> Handle( CreateBookCommand request, CancellationToken cancellationToken) { var entity = new Book { Title = request.Title, Author = request.Author, Language = request.Language, Publisher = request.Publisher, ISBN10 = request.ISBN10 }; var @event = new BookCreatedEvent { Title = entity.Title, Author = entity.Author }; entity.Events.Add(@event); var result = await _repository.AddAsync(entity); return(result.Id); }
private void HandleBookCreatedEvent(BookCreatedEvent e) { this.Title = e.Title; this.Author = e.Author; this.Description = e.Description; this.ISBN = e.ISBN; this.Pages = e.Pages; this.Inventory = e.Inventory; }
public bool Handle(BookCreatedEvent message) { string insertBookSql = @"INSERT INTO [Books] ([Title], [Author], [Description], [ISBN], [Pages], [Inventory], [AggregateRootId]) VALUES (@title, @author, @description, @isbn, @pages, @inventory, @aggregateRootId)"; var rowsAffected = SqlHelper.ExecuteNonQuery(QueryDBConnectionString, CommandType.Text, insertBookSql, new SqlParameter("@title", message.Title), new SqlParameter("@author", message.Author), new SqlParameter("@description", message.Description), new SqlParameter("@isbn", message.ISBN), new SqlParameter("@pages", message.Pages), new SqlParameter("@inventory", message.Inventory), new SqlParameter("@aggregateRootId", message.AggregateRootId)); return(rowsAffected > 0); }
public void Test1() { ISerializer serializer = new Serializer(); var @event = new BookCreatedEvent(Guid.NewGuid(), "Test") { Version = 1, TimeStamp = DateTimeOffset.UtcNow.Ticks }; var bytes = serializer.Serialize(@event); var obj = serializer.Deserialize <BookCreatedEvent>(bytes); Assert.Equal(obj.Id, @event.Id); Assert.Equal(obj.Name, @event.Name); }
public static Book Create(string bookName, string authorName) { bookName = bookName?.Trim() ?? string.Empty; if (string.IsNullOrEmpty(bookName)) { throw new BookNameEmptyException(); } authorName = authorName?.Trim() ?? string.Empty; if (string.IsNullOrEmpty(authorName)) { throw new AuthorNameEmptyException(); } Book book = new Book(bookName, authorName); BookCreatedEvent bookCreatedEvent = new BookCreatedEvent(book); book.AddDomainEvent(bookCreatedEvent); return(book); }