Пример #1
0
        public async Task Handle(AddAuthor message, CancellationToken cancellationToken)
        {
            AuthorEntityHandler.Add(message.Author);

            await Mediator.Send(new SaveChanges());

            await Mediator.Publish(new AuthorAdded(message.Author, message.UserId));
        }
Пример #2
0
        public async Task Handle(UpdateAuthor message, CancellationToken cancellationToken)
        {
            var oldAuthor = await AuthorEntityHandler.Get(message.Author.Id);

            if (oldAuthor == null)
            {
                throw new EntityNotFoundException <Author>(message.Author);
            }

            var newAuthor = oldAuthor.Update(message.Author, DateTime.UtcNow);

            AuthorEntityHandler.Update(newAuthor);

            await Mediator.Send(new SaveChanges());

            await Mediator.Publish(new AuthorUpdated(newAuthor, oldAuthor, message.UserId));
        }
Пример #3
0
 public async Task <Author> Handle(GetAuthor request, CancellationToken cancellationToken) =>
 await AuthorEntityHandler.Get(request.Id);
Пример #4
0
 public async Task <IEnumerable <Author> > Handle(GetAuthors request, CancellationToken cancellationToken) =>
 await AuthorEntityHandler.Get();