Example #1
0
            public async Task <CQRSResult <AuthorGetDTO> > Handle(AuthorAddCommand request, CancellationToken cancellationToken)
            {
                var entity = request.ToModel();

                uow.AuthorsRepository.Add(entity);
                await uow.Save(cancellationToken);

                return(AuthorGetMap.ToDTO(entity));
            }
Example #2
0
            public async Task <CQRSResult <AuthorGetDTO> > Handle(AuthorQuery request, CancellationToken cancellationToken)
            {
                var author = uow.AuthorsRepository.GetById(request.Id);

                if (author != null)
                {
                    return(AuthorGetMap.ToDTO(author));
                }
                else
                {
                    return((null as AuthorGetDTO).AsCQRSResult(code: 404));
                };
            }
Example #3
0
 public static BookGetDTO ToDTO(this Book model, bool withLinks = true)
 {
     return(new BookGetDTO
     {
         Id = model.Id,
         Title = model.Title,
         CoverImagePath = model.CoverImagePath,
         Description = model.Description,
         BookAuthors = model.AuthorBooks?.Select(x => BookAuthorGetMap.ToDTO(x)).ToArray(),
         Authors = withLinks
                     ? model.Authors?.Select(x => AuthorGetMap.ToDTO(x, false)).ToArray()
                     : new AuthorGetDTO[0]
     });
 }
            public async Task <CQRSResult <AuthorGetDTO> > Handle(AuthorUpdateCommand request, CancellationToken cancellationToken)
            {
                var exists = uow.AuthorsRepository.Contains(x => x.Id == request.Id);

                if (exists)
                {
                    var entity = request.ToModel();
                    uow.AuthorsRepository.Update(entity);
                    await uow.Save();

                    return(AuthorGetMap.ToDTO(entity));
                }
                else
                {
                    return((null as AuthorGetDTO).AsCQRSResult(code: 404));
                }
            }
            public async Task <CQRSResult <AuthorGetDTO> > Handle(AuthorDeleteCommand request, CancellationToken cancellationToken)
            {
                var author = uow.AuthorsRepository.GetById(request.Id);

                if (author != null)
                {
                    uow.AuthorsRepository.Delete(author);
                }
                else
                {
                    return(AuthorGetMap.ToDTO(null).AsCQRSResult(code: 404));
                }
                await uow.Save(cancellationToken);

                return(AuthorGetMap.ToDTO(new Author {
                    Id = request.Id
                }));
            }
Example #6
0
            public async Task <CQRSResult <List <AuthorGetDTO> > > Handle(AuthorsQuery request, CancellationToken cancellationToken)
            {
                var authors = uow.AuthorsRepository.Get();

                return(authors.Select(x => AuthorGetMap.ToDTO(x)).ToList());
            }