public async Task <IActionResult> GetAllAuthors()
        {
            var query    = new GetAllAuthorsQuery();
            var response = await _mediator.Send(query);

            return(response.ToActionResult());
        }
        public async Task <IEnumerable <AuthorDto> > Handle(GetAllAuthorsQuery request, CancellationToken cancellationToken)
        {
            var authors = await _authorRepository.GetAllAsync();


            return(_mapper.Map <IEnumerable <AuthorDto> >(authors));
        }
Example #3
0
        public async Task <IList <Author> > Handle(GetAllAuthorsQuery request, CancellationToken cancellationToken)
        {
            // load from database
            IQueryable <AuthorEntity> entities = await _authorsRepository.GetAllAsync();

            // map
            IList <Author> authors = entities.AsEnumerable().Select(AuthorMapper.MapToModel).ToList();

            // return
            return(authors);
        }
Example #4
0
        public async Task GetAllAuthorsTest()
        {
            var authorsReturns = _authorFaker.GenerateForever().Take(10).ToList();

            _dbContext.GetAuthors().Returns(authorsReturns);
            var getAllAuthorsQueryHandler = new GetAllAuthorsQueryHandler(_dbContext);
            var getAllAuthorsQuery        = new GetAllAuthorsQuery();
            var authors = await getAllAuthorsQueryHandler.Handle(getAllAuthorsQuery, CancellationToken.None);

            authors.Should().Equal(authorsReturns);
        }
Example #5
0
        public async Task <IActionResult> GetAll()
        {
            var getAllAuthorsQuery = new GetAllAuthorsQuery();

            try
            {
                var authors = await _mediator.Send(getAllAuthorsQuery);

                var response = _mapper.Map <IList <Author>, IList <GetAuthorResponse> >(authors);
                return(Ok(response));
            }
            catch (Exception e)
            {
                return(BadRequest(e.ToString()));
            }
        }
 public IActionResult GetAuthors()
 {
     if (ModelState.IsValid)
     {
         GetAllAuthorsQuery getAllAuthorsQuery = new GetAllAuthorsQuery();
         try
         {
             var result = _messages.Dispatch(getAllAuthorsQuery);
             return(Ok(result));
         }
         catch (DomainException ex)
         {
             _logger.LogError(ex.Message);
             return(Error(ex.Message));
         }
         catch (Exception ex)
         {
             _logger.LogCritical(ex.Message);
             return(StatusCode(500));
         }
     }
     return(BadRequest());
 }
 public async Task<IActionResult> GetAllAuthors([FromQuery] GetAllAuthorsQuery query)
 {
     return Ok(await _mediator.Send(query));
 }
        public async Task <IList <Author> > Handle(GetAllAuthorsQuery request, CancellationToken cancellationToken)
        {
            await _dbContext.GetDb();

            return(await _dbContext.GetAuthors());
        }
 public async Task <IEnumerable <Author> > Handle(GetAllAuthorsQuery request, CancellationToken cancellationToken)
 {
     return(await authorRepository.ListAllAsync());
 }