public async Task <IActionResult> CreateA(ValueBook book) { var aBook = await bookContext.Books.AddAsync(book.ToBook()); await bookContext.SaveChangesAsync(); await eventBus.Publish(new BookChangeEvent(Guid.NewGuid(), ChangeType.Created, aBook.Entity)); return(new CreatedAtActionResult(nameof(GetABookWith), "Books", new { id = aBook.Entity.Id }, aBook.Entity)); }
public async Task <IActionResult> UpdateABookWith(Guid id, [FromBody] ValueBook book) { var mayBeBook = await bookContext.Books.FindAsync(id); if (mayBeBook == null) { return(new NotFoundResult()); } mayBeBook.Author = book.Author; mayBeBook.Name = book.Name; await eventBus.Publish(new BookChangeEvent(Guid.NewGuid(), ChangeType.Updated, mayBeBook)); bookContext.Entry(mayBeBook).State = EntityState.Modified; await bookContext.SaveChangesAsync(); return(new NoContentResult()); }