Пример #1
0
        public async Task <AuthorDto> GetAuthorAsync(Guid authorId)
        {
            if (authorId == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(authorId));
            }

            AuthorEntity author = await _context.Authors.FirstOrDefaultAsync(x => x.Id == authorId);

            return(author.ToDto());
        }
Пример #2
0
        public async Task <AuthorDto> UpdateAuthorAsync(Guid authorId, AuthorUpdateRequest authorRequest)

        {
            if (authorId == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(authorId));
            }

            AuthorEntity author = await _context.Authors.FirstOrDefaultAsync(x => x.Id == authorId);

            if (author == null)
            {
                return(null);
            }

            authorRequest.ToUpdateEntity(ref author);

            await _context.SaveChangesAsync();

            return(author.ToDto());
        }