コード例 #1
0
        public async Task <ActionResult <List <ContentItemVersionInfo> > > GetVersionsAsync(Guid postId)
        {
            var versions = await Repository.GetVersionsAsync(postId);

            var userIds =
                await _userDataProvider.GetDataAsync(versions.Select(v => v.ChangeAuthorId).Distinct().ToArray());

            return(Ok(versions.Select(v =>
                                      new ContentItemVersionInfo(v.Id, v.DateAdded, userIds.FirstOrDefault(u => u.Id == v.ChangeAuthorId)))
                      .ToList()));
        }
コード例 #2
0
        protected override async Task AfterLoadAsync(Post <TUserPk>[] entities)
        {
            await base.AfterLoadAsync(entities);

            var sectionsIds = entities.SelectMany(p => p.SectionIds).Distinct().ToArray();
            var sections    = await SectionsRepository.GetByIdsAsync(sectionsIds);

            var tagIds = entities.SelectMany(p => p.TagIds).Distinct().ToArray();
            var tags   = await _tagsRepository.GetByIdsAsync(tagIds);

            var userIds = entities.Select(e => e.AuthorId).Distinct().ToArray();
            var users   = await _userDataProvider.GetDataAsync(userIds);

            foreach (var entity in entities)
            {
                entity.Sections = sections.Where(s => entity.SectionIds.Contains(s.Id)).ToList();
                entity.Tags     = tags.Where(t => entity.TagIds.Contains(t.Id)).ToList();
                entity.Author   = users.FirstOrDefault(d => d.Id.Equals(entity.AuthorId));
            }
        }