Пример #1
0
        public async Task UpdateAuthorAsync(AuthorDTO authorDTO)
        {
            if (authorDTO != null && authorDTO != default)
            {
                await _authorRepository.UpdateAsync(_mapper.Map <Author>(authorDTO));

                _cacheManager.Remove(CacheKeys.GetAuthorKey(authorDTO.Id));
            }
        }
Пример #2
0
        public async Task RemoveAuthorAsync(int authorId)
        {
            if (authorId >= 1)
            {
                var author = await _authorRepository.GetByIdAsync(authorId);

                if (author != null)
                {
                    await _authorRepository.RemoveAsync(author);

                    _cacheManager.Remove(CacheKeys.GetAuthorKey(author.Id));
                }
            }
        }
Пример #3
0
        public async Task <AuthorDTO> GetAuthorByIdAsync(int authorId)
        {
            if (_cacheManager.IsSet(CacheKeys.GetAuthorKey(authorId)))
            {
                return(_mapper.Map <AuthorDTO>(_cacheManager.Get <Author>(CacheKeys.GetAuthorKey(authorId))));
            }

            var author = await _authorRepository.GetByIdAsync(authorId);

            if (author == null)
            {
                throw new NotFoundException(nameof(Author), author);
            }

            _cacheManager.Set <Author>(CacheKeys.GetAuthorKey(author.Id), author, CacheTimes.AuthorCacheTime);
            return(_mapper.Map <AuthorDTO>(author));
        }