Beispiel #1
0
        public override async Task <IActionResult> OnGetAsync()
        {
            var topicTask = base.OnGetAsync();

            var query       = new TopicHistoryQuery(User, Id);
            var historyTask = Mediator.Send(query);

            await Task.WhenAll(
                topicTask,
                historyTask
                );

            History = historyTask.Result;

            return(Page());
        }
        private async Task <List <AuditRecord <Guid> > > CollectTopicHistory(TopicHistoryQuery request, CancellationToken cancellationToken)
        {
            var sql = new StringBuilder();

            sql.AppendLine("SELECT *");
            sql.AppendLine("FROM [IQ].[Topic]");
            sql.AppendLine("FOR SYSTEM_TIME ALL");
            sql.AppendLine("WHERE [Id] = {0}");

            var entities = await DataContext.Topics
                           .FromSqlRaw(sql.ToString(), request.Id)
                           .AsNoTracking()
                           .OrderBy(p => p.PeriodEnd)
                           .ProjectTo <TopicReadModel>(Mapper.ConfigurationProvider)
                           .ToListAsync(cancellationToken);

            var historyList = _changeCollector.CollectChanges(entities, nameof(Topic), t => t.Title);

            return(historyList.ToList());
        }
        private async Task <IReadOnlyCollection <AuditRecord <Guid> > > CollectSessionInstructorHistory(TopicHistoryQuery request, CancellationToken cancellationToken)
        {
            var command = new SessionInstructorHistoryQuery(request.Principal)
            {
                TopicId = request.Id
            };

            return(await _mediator.Send(command, cancellationToken));
        }
        protected override async Task <IReadOnlyCollection <AuditRecord <Guid> > > Process(TopicHistoryQuery request, CancellationToken cancellationToken)
        {
            var historyList = new List <AuditRecord <Guid> >();

            var topicHistoryList = await CollectTopicHistory(request, cancellationToken);

            historyList.AddRange(topicHistoryList);

            var sessionHistoryList = await CollectSessionHistory(request, cancellationToken);

            historyList.AddRange(sessionHistoryList);

            var instructorHistoryList = await CollectSessionInstructorHistory(request, cancellationToken);

            historyList.AddRange(instructorHistoryList);

            var discussionHistoryList = await CollectDiscussionHistory(request, cancellationToken);

            historyList.AddRange(discussionHistoryList);

            return(historyList
                   .Where(p => p.Operation != AuditOperation.Update || (p.Operation == AuditOperation.Update && p.Changes?.Count > 0))
                   .OrderBy(p => p.ActivityDate)
                   .ToList());
        }