public async Task PostAsync(PublicationDto publicationDto, CancellationToken cancellationToken = default) { var publication = new Publication { Title = publicationDto.Title, Description = publicationDto.Description, Authors = (await Task.WhenAll( publicationDto.AuthorsIds.Select(async authorId => await _dataContext.Authors.SingleAsync(author => author.Id == authorId, cancellationToken) ) )).ToList(), Reviews = (await Task.WhenAll( publicationDto.ReviewsIds.Select(async reviewId => await _dataContext.Reviews.SingleAsync(review => review.Id == reviewId, cancellationToken) ) )).ToList(), Publisher = publicationDto.PublisherId != null ? await _dataContext.Publishers.SingleAsync(publisher => publisher.Id == publicationDto.PublisherId, cancellationToken ) : null }; await _dataContext.Publications.AddAsync(publication, cancellationToken); await _dataContext.SaveChangesAsync(cancellationToken); }
public async Task PostAsync(AuthorDto authorDto, CancellationToken cancellationToken = default) { var author = new Author { Name = authorDto.Name, Biography = authorDto.Biography }; await _dataContext.Authors.AddAsync(author, cancellationToken); await _dataContext.SaveChangesAsync(cancellationToken); }
public async Task PostAsync(ReviewDto reviewDto, CancellationToken cancellationToken = default) { var review = new Review { ReviewerName = reviewDto.ReviewerName, IsPositive = reviewDto.IsPositive, Comment = reviewDto.Comment, Publication = reviewDto.PublicationId != null ? await _dataContext.Publications.SingleAsync(publication => publication.Id == reviewDto.PublicationId, cancellationToken ) : null }; await _dataContext.Reviews.AddAsync(review, cancellationToken); await _dataContext.SaveChangesAsync(cancellationToken); }
public async Task PostAsync(PublisherDto publisherDto, CancellationToken cancellationToken = default) { var publisher = new Publisher { Name = publisherDto.Name, Email = publisherDto.Email, Publications = (await Task.WhenAll( publisherDto.PublicationsIds.Select(async publicationId => await _dataContext.Publications.SingleAsync( publication => publication.Id == publicationId, cancellationToken ) ) )).ToList() }; await _dataContext.Publishers.AddAsync(publisher, cancellationToken); await _dataContext.SaveChangesAsync(cancellationToken); }