public async Task <HandlerResult <Book> > Handle(CreateNewBookCommand request, CancellationToken cancellationToken) { var handlerResult = new HandlerResult <Book>(); try { var book = new Book { Id = request.Id, Title = request.Title, Year = request.Year }; var result = await _repository.Create(book); if (result) { handlerResult.Data = book; return(handlerResult); } } catch (Exception e) { handlerResult.AddError(e.Message); } return(handlerResult); }
public async Task <HandlerResult <IEnumerable <Book> > > Handle(GetBooksByYearQuery request, CancellationToken cancellationToken) { var handlerResult = new HandlerResult <IEnumerable <Book> >(); try { handlerResult.Data = await _repository.GetBooksByYear(request.Year); } catch (Exception e) { handlerResult.AddError(e.Message); } return(handlerResult); }