public async Task <IEnumerable <GetMediaByArrayOfIdsResult> > Handle(GetMediaByArrayOfIdsQuery query, CancellationToken cancellationToken) { var mapper = new Mapper(_mapperConfiguration); var projection = Builders <ContentDAO> .Projection.Expression(x => mapper.Map <GetMediaByArrayOfIdsResult>(x)); var ids = query.Ids.Select(x => ObjectId.Parse(x)).ToList(); var filter = Builders <ContentDAO> .Filter.In(x => x.Id, ids); var media = await _db.Content .Find(filter) .Project(projection) .ToListAsync(); return(media); }
public async Task <IEnumerable <Media> > Handle(GetMediaByArrayOfIdsQuery query, CancellationToken cancellationToken) { var mediaIds = query.Ids.Select(x => new KeyValuePair <string, string>("mediaIds", x)).ToList(); var accessToken = await _httpContextAcessor.HttpContext.GetTokenAsync("access_token"); string uri = $"multi"; var queryString = $"{uri}{QueryString.Create(mediaIds).ToString()}"; _httpClient.SetBearerToken(accessToken); var response = await _httpClient.GetAsync(queryString); if (response.StatusCode.Equals(HttpStatusCode.NoContent)) { return(JsonSerializer.Deserialize <IEnumerable <Media> >("[]", DefaultJsonSettings.Settings)); } var content = await response.Content.ReadAsStringAsync(); return(JsonSerializer.Deserialize <IEnumerable <Media> >(content, DefaultJsonSettings.Settings)); }