/// <inheritdoc/> public async Task <MultipleDocumentResult> GetActivityProfiles(Iri activityId, DateTimeOffset?since = null, CancellationToken cancellationToken = default) { var activity = await mediator.Send(GetActivityQuery.Create(activityId), cancellationToken); if (activity == null) { return(MultipleDocumentResult.Empty()); } var documents = await mediator.Send(new GetActivityProfilesQuery() { ActivityId = activityId, Since = since }, cancellationToken); if (!documents.Any()) { return(MultipleDocumentResult.Empty()); } var ids = documents.Select(x => x.Key).ToHashSet(); var lastModified = documents .OrderByDescending(x => x.UpdatedAt) .Select(x => x.UpdatedAt) .FirstOrDefault(); return(MultipleDocumentResult.Success(ids, lastModified)); }
public async Task <ActionResult> GetActivityDocumentAsync([FromQuery] GetActivityQuery command, CancellationToken cancelToken = default) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var activityEntity = await _mediator.Send(command, cancelToken); ResultFormat format = ResultFormat.Exact; if (!StringValues.IsNullOrEmpty(Request.Headers[HeaderNames.AcceptLanguage])) { format = ResultFormat.Canonical; } if (activityEntity == null) { return(Ok(new Activity())); } var activity = _mapper.Map <Activity>(activityEntity); return(Ok(activity.ToJson(format))); }
public async Task <ActivityProfileEntity> Handle(GetActivityProfileQuery request, CancellationToken cancellationToken) { var activityEntity = await _mediator.Send(GetActivityQuery.Create(request.ActivityId), cancellationToken); if (activityEntity == null) { return(null); } return(await _context.ActivityProfiles.GetProfileAsync(activityEntity.ActivityId, request.ProfileId, request.Registration, cancellationToken)); }
public async Task <Unit> Handle(DeleteActivityProfileCommand request, CancellationToken cancellationToken) { var activity = await _mediator.Send(GetActivityQuery.Create(request.ActivityId), cancellationToken); var profile = await _context.ActivityProfiles.GetProfileAsync(activity.ActivityId, request.ProfileId, request.Registration, cancellationToken); _context.ActivityProfiles.Remove(profile); await _context.SaveChangesAsync(cancellationToken); return(await Unit.Task); }
public async Task <ActionResult> GetActivityDocumentAsync(GetActivityQuery command) { Activity activity = await _mediator.Send(command); if (activity == null) { return(Ok(new Activity())); } // TODO: Return only canonical that match accept-language header, or und return(Ok(activity)); }
public async Task <ICollection <ActivityProfileEntity> > Handle(GetActivityProfilesQuery request, CancellationToken cancellationToken) { var activity = await _mediator.Send(GetActivityQuery.Create(request.ActivityId), cancellationToken); var query = _context.ActivityProfiles.Where(x => x.ActivityId == activity.ActivityId); if (request.Since.HasValue) { query = query.Where(x => x.Document.LastModified >= request.Since); } query = query.OrderByDescending(x => x.Document.LastModified); return(await query.ToListAsync(cancellationToken)); }
public async Task <Unit> Handle(UpdateActivityProfileCommand request, CancellationToken cancellationToken) { var activity = await _mediator.Send(GetActivityQuery.Create(request.ActivityId)); if (activity == null) { throw new NotFoundException("No activity profiles for activity."); } ActivityProfileEntity profile = await _context.ActivityProfiles.GetProfileAsync(activity.ActivityId, request.ProfileId, request.Registration, cancellationToken); profile.Document.UpdateDocument(request.Content, request.ContentType); _context.ActivityProfiles.Update(profile); await _context.SaveChangesAsync(cancellationToken); return(await Unit.Task); }
public ActionResult FetchActivity(GetActivityQuery query) { var activity = this.dispatcher.Query(query); return(IncJson(activity)); }
public async Task <PagedStatementsResult> Handle(PagedStatementsQuery request, CancellationToken cancellationToken) { if (!string.IsNullOrWhiteSpace(request.Cursor)) { string token = request.Cursor; string jsonString = await _distributedCache.GetStringAsync(token, cancellationToken); request = PagedStatementsQuery.FromJson(jsonString); request.Cursor = null; } var query = _context.Statements.AsNoTracking(); if (request.VerbId != null) { string verbHash = request.VerbId.ComputeHash(); query = query.Where(x => x.Verb.Hash == verbHash); } if (request.Agent != null) { var currentAgent = await _mediator.Send(GetAgentQuery.Create(request.Agent)); if (currentAgent != null) { Guid agentId = currentAgent.AgentId; EntityObjectType agentType = currentAgent.ObjectType; if (request.RelatedAgents.GetValueOrDefault()) { query = ( from sta in query join sub in _context.SubStatements on new { ObjectType = sta.ObjectType, ObjectId = sta.ObjectId } equals new { ObjectType = sub.ObjectType, ObjectId = sub.SubStatementId } let ctx = sta.Context where sta.Actor.AgentId == agentId || (sta.ObjectType == agentType && sta.ObjectId == agentId) || (sta.Context.InstructorId == agentId || sta.Context.TeamId == agentId) // SubStatement || sub.Actor.AgentId == agentId || (sub.ObjectType == agentType && sub.ObjectId == agentId) || // Object (sub.Context.InstructorId == agentId || sub.Context.TeamId == agentId) select sta ); } else { query = query.Where(x => x.ActorId == currentAgent.AgentId); } } else { return(new PagedStatementsResult()); } } if (request.ActivityId != null) { var activity = await _mediator.Send(GetActivityQuery.Create(request.ActivityId), cancellationToken); if (activity == null) { return(new PagedStatementsResult()); } if (request.RelatedActivities.GetValueOrDefault()) { query = ( from statement in query join subStatement in _context.SubStatements on new { ObjectId = statement.ObjectId, ObjectType = statement.ObjectType } equals new { ObjectId = subStatement.ObjectId, ObjectType = EntityObjectType.SubStatement } where ( statement.ObjectType == EntityObjectType.Activity && statement.ObjectId == activity.ActivityId ) || ( subStatement.ObjectType == EntityObjectType.Activity && subStatement.ObjectId == activity.ActivityId ) || ( statement.Context != null && statement.Context.ContextActivities != null && ( statement.Context.ContextActivities.Any(x => x.ActivityId == activity.ActivityId) ) ) select statement ); } else { query = query.Where(x => x.ObjectType == EntityObjectType.Activity && x.ObjectId == activity.ActivityId); } } if (request.Registration.HasValue) { Guid registration = request.Registration.Value; query = ( from statement in query where statement.Context != null && statement.Context.Registration == registration select statement ); } if (request.Ascending.GetValueOrDefault()) { query = query.OrderBy(x => x.Stored); } else { query = query.OrderByDescending(x => x.Stored); } if (request.Since.HasValue) { query = query.Where(x => x.Stored > request.Since.Value); } if (request.Until.HasValue) { query = query.Where(x => x.Stored < request.Until.Value); } int pageSize = request.Limit ?? 1000; int skipRows = request.PageIndex * pageSize; IQueryable <StatementEntity> pagedQuery = null; // Include voiding statements query = query.Select(p => p.VoidingStatementId != null ? p.VoidingStatement : p); if (!request.Attachments.GetValueOrDefault()) { pagedQuery = query.Select(p => new StatementEntity { StatementId = p.StatementId, FullStatement = p.FullStatement }); } else { pagedQuery = query.Select(p => new StatementEntity { StatementId = p.StatementId, FullStatement = p.FullStatement, Attachments = p.Attachments, }); } var result = await pagedQuery.Skip(skipRows).Take(pageSize + 1) .ToListAsync(cancellationToken); if (result == null) { return(new PagedStatementsResult()); } List <StatementEntity> statements = result.Take(pageSize).ToList(); if (result.Count > pageSize) { request.Cursor = Guid.NewGuid().ToString(); request.PageIndex += 1; if (!request.Until.HasValue) { request.Until = DateTimeOffset.UtcNow; } var options = new DistributedCacheEntryOptions() .SetSlidingExpiration(TimeSpan.FromSeconds(60 * 10)); await _distributedCache.SetStringAsync(request.Cursor, request.ToJson(), options, cancellationToken); return(new PagedStatementsResult(statements, request.Cursor)); } return(new PagedStatementsResult(statements)); }
public async Task <Activity> GetActivity(Iri activityId, CancellationToken cancellationToken) { var activityEntity = await mediator.Send(GetActivityQuery.Create(activityId), cancellationToken); return(mapper.Map <Activity>(activityEntity)); }