public async Task RemoveBookAsync(int bookId) { var book = await _bookRepository.GetByIdAsync(bookId); if (book != default) { await _bookRepository.RemoveAsync(book); _cacheManager.Remove(CacheKeys.GetBookKey(bookId)); } }
public async Task <BookDTO> GetBookByIdAsync(int bookId) { if (_cacheManager.IsSet(CacheKeys.GetBookKey(bookId))) { return(_mapper.Map <BookDTO>(_cacheManager.Get <Book>(CacheKeys.GetBookKey(bookId)))); } var book = await _bookRepository.GetByIdAsync(bookId); if (book == null) { throw new NotFoundException(nameof(Book), book); } return(_mapper.Map <BookDTO>(book)); }
public async Task UpdateBookAsync(BookDTO bookDTO) { await _bookRepository.UpdateAsync(_mapper.Map <Book>(bookDTO)); _cacheManager.Remove(CacheKeys.GetBookKey(bookDTO.Id)); }