private async Task <IReadOnlyCollection <TopicReadModel> > LoadTopics() { var command = new EntityIdentifiersQuery <Guid, TopicReadModel>(User, TopicIds); var result = await Mediator.Send(command); return(result); }
protected override async Task <IReadOnlyCollection <TReadModel> > Process(EntityIdentifiersQuery <string, TReadModel> request, CancellationToken cancellationToken) { if (request is null) { throw new System.ArgumentNullException(nameof(request)); } var keys = new HashSet <string>(); foreach (var requestId in request.Ids) { if (CosmosKey.TryDecode(requestId, out var id, out PartitionKey partitionKey)) { keys.Add(id); } } var query = await Repository .GetQueryableAsync() .ConfigureAwait(false); var results = await query .Where(p => keys.Contains(p.Id)) .ToListAsync(cancellationToken) .ConfigureAwait(false); return(Mapper.Map <IList <TEntity>, IReadOnlyCollection <TReadModel> >(results)); }
private async Task <List <TopicMultipleUpdateModel> > LoadTopics() { var command = new EntityIdentifiersQuery <Guid, TopicMultipleUpdateModel>(User, TopicIds); var result = await Mediator.Send(command); return(result .OrderBy(p => p.CalendarYear) .ThenBy(p => p.TargetMonth) .ThenBy(p => p.Title) .ToList()); }
protected override async Task <IReadOnlyCollection <TReadModel> > Process(EntityIdentifiersQuery <TKey, TReadModel> request, CancellationToken cancellationToken) { var model = await DataContext .Set <TEntity>() .AsNoTracking() .Where(p => request.Ids.Contains(p.Id)) .ProjectTo <TReadModel>(Mapper.ConfigurationProvider) .ToListAsync(cancellationToken) .ConfigureAwait(false); return(model); }
protected override async Task <IReadOnlyCollection <TReadModel> > Process(EntityIdentifiersQuery <TKey, TReadModel> request, CancellationToken cancellationToken) { if (request is null) { throw new ArgumentNullException(nameof(request)); } var keys = new HashSet <TKey>(request.Ids); var results = await Repository.Collection .AsQueryable() .Where(p => keys.Contains(p.Id)) .ToListAsync(cancellationToken) .ConfigureAwait(false); return(Mapper.Map <IList <TEntity>, IReadOnlyCollection <TReadModel> >(results)); }
public async Task EntityIdentifiersQuery() { var mediator = ServiceProvider.GetService <IMediator>(); mediator.Should().NotBeNull(); var mapper = ServiceProvider.GetService <IMapper>(); mapper.Should().NotBeNull(); var identifiers = new[] { PriorityConstants.Normal.ToCosmosKey(), PriorityConstants.High.ToCosmosKey() }; var identifierQuery = new EntityIdentifiersQuery <string, PriorityReadModel>(MockPrincipal.Default, identifiers); var identifierResults = await mediator.Send(identifierQuery).ConfigureAwait(false); identifierResults.Should().NotBeNull(); identifierResults.Count.Should().Be(2); }