public async Task <DataSourceResponseModel> ExecuteAsync(UserMessageQuery messageQuery, CancellationToken token = default) { var(page, pageSize) = messageQuery; await using var scope = await _transactionScopeFactory.CreateAsync(token); var query = scope.Query <VkRepost>() .Where(f => f.UserId == _authenticatedUserProvider.GetUser().Id).OrderByDescending(f => f.Id); var data = await query.Skip(page *pageSize).Take(pageSize).ToListAsync(token); var posts = await _vkClient.GetById( data.Select(f => new VkRepostViewModel(f.OwnerId, f.MessageId))); var texts = posts .Response.Items .Select(f => new { f.Text, f.Id, DateStatus = data.Where(a => a.OwnerId == f.OwnerId && a.MessageId == f.Id) .Select(a => a.DateStatus) }); return(new DataSourceResponseModel(texts, await query.CountAsync(token))); }
public async Task <VkResponse <List <VkMessage> > > GetReposts(string id, int page, int take, string?search = null) { var data = await _wallService.WallSearch(id, page, take, search); var reposts = data.Response.Items .OrderByDescending(c => c.Date) .Where(c => c.CopyHistory != null && c.CopyHistory.Count > 0) .Select(c => c.CopyHistory.First()) .Distinct() .ToList(); var count = data.Response.Count; var result = reposts.Any() ? await _wallService.GetById(reposts .Select(c => new VkRepostViewModel(c.OwnerId, c.Id)) ) : new VkResponse <List <VkMessage> >(); result.Response ??= new VkResponse <List <VkMessage> > .VkResponseItems(); result.Response.Count = count; return(result); }