private async Task <Publisher> GetOrCreatePublisherAsync(CreateBookCommand request, CancellationToken cancellationToken) { var publisher = request.PublisherName is not null ? await _publisherRepository.FindByNameAsync(request.PublisherName) ?? _publisherRepository.Add(new Publisher(request.PublisherName)) : null; await _publisherRepository.UnitOfWork.SaveChangesAsync(cancellationToken); return(publisher); }
public async Task <Publisher> FindByNameAsync(string name) { _logger.LogInfoMethodStarted <Publisher>(PublisherRepositoryType, nameof(FindByNameAsync), new object[] { name }); var result = await _publisherRepository.FindByNameAsync(name); if (result is null) { _logger.LogWarningNotFound <Publisher>(PublisherRepositoryType, nameof(FindByNameAsync), new object[] { name }); } _logger.LogInfoMethodEnded(PublisherRepositoryType, nameof(FindByNameAsync), result); return(result); }