public async Task <Unit> Handle(UpdateNoteGroupCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } using IReturnDbContext dbContext = this._returnDbContextFactory.CreateForEditContext(); // Find entity NoteGroup noteGroup = await dbContext.NoteGroups .Include(x => x.Retrospective) .Include(x => x.Lane) .FirstOrDefaultAsync(ng => ng.Retrospective.UrlId.StringId == request.RetroId && ng.Id == request.Id, cancellationToken); if (noteGroup == null) { throw new NotFoundException(nameof(NoteGroup), request.Id); } // Validate operation await this._securityValidator.EnsureAddOrUpdate(noteGroup.Retrospective, noteGroup); // Edit noteGroup.Title = request.Name; await dbContext.SaveChangesAsync(cancellationToken); // Broadcast await this._mediator.Publish(new NoteLaneUpdatedNotification(request.RetroId, (int)noteGroup.Lane.Id, noteGroup.Id), cancellationToken); return(Unit.Value); }
public GetRetrospectiveLaneContentQueryHandler(IReturnDbContext returnDbContext, IMapper mapper, ICurrentParticipantService currentParticipantService, ITextAnonymizingService textAnonymizingService) { this._returnDbContext = returnDbContext; this._mapper = mapper; this._currentParticipantService = currentParticipantService; this._textAnonymizingService = textAnonymizingService; }
public async Task <Unit> Handle(MoveNoteCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } IReturnDbContext dbContext = this._returnDbContextFactory.CreateForEditContext(); // Get data Note?note = await dbContext.Notes .Include(x => x.Lane) .Include(x => x.Group) .Include(x => x.Retrospective) .FirstOrDefaultAsync(x => x.Id == request.NoteId, cancellationToken); if (note == null) { throw new NotFoundException(nameof(Note), request.NoteId); } NoteGroup?newTargetGroup = null; if (request.GroupId != null) { newTargetGroup = await dbContext.NoteGroups.Include(x => x.Lane). FirstOrDefaultAsync(x => x.Id == request.GroupId, cancellationToken); if (newTargetGroup == null) { throw new NotFoundException(nameof(NoteGroup), request.GroupId.Value); } } // Validate if (newTargetGroup != null && note.Lane.Id != newTargetGroup.Lane.Id) { throw new InvalidOperationException("Invalid move command: this would result in a lane change."); } NoteGroup involvedGroup = newTargetGroup ?? note.Group ?? throw new InvalidOperationException("Note move from ungrouped to ungrouped"); await this._securityValidator.EnsureAddOrUpdate(note.Retrospective, involvedGroup); // Update note.GroupId = newTargetGroup?.Id; note.Group = newTargetGroup; await dbContext.SaveChangesAsync(cancellationToken); // Broadcast var broadcast = new NoteMovedNotification(note.Retrospective.UrlId.StringId, (int)note.Lane.Id, note.Id, note.GroupId); await this._mediator.Publish(broadcast, cancellationToken); return(Unit.Value); }
public JoinRetrospectiveCommandHandler(IReturnDbContext returnDbContext, ICurrentParticipantService currentParticipantService, IMediator mediator, IMapper mapper) { this._returnDbContext = returnDbContext; this._currentParticipantService = currentParticipantService; this._mediator = mediator; this._mapper = mapper; }
public async Task <Unit> Handle(DeleteNoteCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } using IReturnDbContext dbContext = this._returnDbContextFactory.CreateForEditContext(); // Get Note note = await dbContext.Notes.Include(x => x.Lane).Include(x => x.Retrospective).FirstOrDefaultAsync(x => x.Id == request.NoteId && x.Retrospective.UrlId.StringId == request.RetroId, cancellationToken); if (note == null) { throw new NotFoundException(nameof(Note), request.NoteId); } // Validate await this._securityValidator.EnsureDelete(note.Retrospective, note); // Execute dbContext.Notes.Remove(note); await dbContext.SaveChangesAsync(cancellationToken); // Broadcast await this._mediator.Publish(new NoteDeletedNotification(request.RetroId, (int)note.Lane.Id, note.Id), cancellationToken); return(Unit.Value); }
public CreateRetrospectiveCommandHandler(IReturnDbContext returnDbContext, IPassphraseService passphraseService, ISystemClock systemClock, IUrlGenerator urlGenerator, ILogger <CreateRetrospectiveCommandHandler> logger) { this._returnDbContext = returnDbContext; this._passphraseService = passphraseService; this._systemClock = systemClock; this._urlGenerator = urlGenerator; this._logger = logger; }
public async Task <RetrospectiveNote> Handle(AddNoteCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } // Get the required entities using IReturnDbContext returnDbContext = this._returnDbContextFactory.CreateForEditContext(); Retrospective retrospective = await returnDbContext.Retrospectives.FindByRetroId(request.RetroId, cancellationToken); if (retrospective == null) { throw new NotFoundException(nameof(Retrospective), request.RetroId); } NoteLane noteLane = await returnDbContext.NoteLanes.FindAsync((KnownNoteLane)request.LaneId); if (noteLane == null) { throw new NotFoundException(nameof(NoteLane), (KnownNoteLane)request.LaneId); } // Save the note CurrentParticipantModel currentParticipant = await this._currentParticipantService.GetParticipant(); var note = new Note { Retrospective = retrospective, CreationTimestamp = this._systemClock.CurrentTimeOffset, Lane = noteLane, Participant = await returnDbContext.Participants.FindAsync(currentParticipant.Id), ParticipantId = currentParticipant.Id, Text = String.Empty }; await this._securityValidator.EnsureOperation(retrospective, SecurityOperation.AddOrUpdate, note); returnDbContext.Notes.Add(note); await returnDbContext.SaveChangesAsync(cancellationToken); // Return and broadcast var broadcastNote = this._mapper.Map <RetrospectiveNote>(note); var returnNote = this._mapper.Map <RetrospectiveNote>(note); returnNote.IsOwnedByCurrentUser = true; // ... Broadcast await this._mediator.Publish(new NoteAddedNotification(request.RetroId, request.LaneId, broadcastNote), cancellationToken); return(returnNote); }
private async Task <Unit> HandleNoteGroupVote(int noteGroupId, VoteMutationType mutationType, CancellationToken cancellationToken) { using IReturnDbContext dbContext = this._returnDbContext.CreateForEditContext(); // Get NoteGroup noteGroup = await dbContext.NoteGroups.Include(x => x.Retrospective) .Include(x => x.Lane).FirstOrDefaultAsync(x => x.Id == noteGroupId, cancellationToken); if (noteGroup == null) { throw new NotFoundException(nameof(NoteGroup), noteGroupId); } NoteVote vote = await(mutationType switch { VoteMutationType.Added => this.HandleNoteGroupVoteAdd(noteGroup: noteGroup, dbContext: dbContext, cancellationToken: cancellationToken), VoteMutationType.Removed => this.HandleNoteGroupVoteRemove(noteGroup: noteGroup, dbContext: dbContext, cancellationToken: cancellationToken), _ => throw new InvalidOperationException("Invalid vote mutation type: " + mutationType) });
public async Task <RetrospectiveNoteGroup> Handle(AddNoteGroupCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } using IReturnDbContext dbContext = this._returnDbContextFactory.CreateForEditContext(); // Get the required relations Retrospective?retrospective = await dbContext.Retrospectives.FindByRetroId(request.RetroId, cancellationToken); if (retrospective == null) { throw new NotFoundException(nameof(Retrospective), request.RetroId); } NoteLane?noteLane = await dbContext.NoteLanes.FindAsync(new object[] { (KnownNoteLane)request.LaneId }, cancellationToken); if (noteLane == null) { throw new NotFoundException(nameof(NoteLane), request.LaneId); } // Add it after validation var noteGroup = new NoteGroup { Lane = noteLane, Title = String.Empty, Retrospective = retrospective }; await this._securityValidator.EnsureAddOrUpdate(retrospective, noteGroup); dbContext.NoteGroups.Add(noteGroup); await dbContext.SaveChangesAsync(cancellationToken); // Map it and broadcast var mappedGroup = this._mapper.Map <RetrospectiveNoteGroup>(noteGroup); await this._mediator.Publish(new NoteLaneUpdatedNotification(request.RetroId, request.LaneId, mappedGroup.Id), cancellationToken); return(mappedGroup); }
public async Task <Unit> Handle(UpdateNoteCommand request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } using IReturnDbContext editDbContext = this._returnDbContext.CreateForEditContext(); Note?note = await editDbContext.Notes .Include(x => x.Retrospective) .Include(x => x.Participant) .FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken); if (note == null) { throw new NotFoundException(nameof(Note), request.Id); } // Validate operation await this._securityValidator.EnsureAddOrUpdate(note.Retrospective, note); // Update the note note.Text = request.Text ?? String.Empty; await editDbContext.SaveChangesAsync(cancellationToken); var notification = new NoteUpdatedNotification(NoteUpdate.FromNote(note)); if (note.Retrospective.CurrentStage == RetrospectiveStage.Writing) { notification = new NoteUpdatedNotification(new NoteUpdate(note.Id, this._textAnonymizingService.AnonymizeText(notification.Note.Text))); } await this._mediator.Publish(notification, cancellationToken); return(Unit.Value); }
public GetAvailablePredefinedParticipantColorsQueryHandler(IReturnDbContext dbContext, IMapper mapper) { this._dbContext = dbContext; this._mapper = mapper; }
public InitiateWritingStageCommandHandler(IReturnDbContext returnDbContext, IRetrospectiveStatusUpdateDispatcher retrospectiveStatusUpdateDispatcher, ISystemClock systemClock) : base(returnDbContext, retrospectiveStatusUpdateDispatcher) { this._systemClock = systemClock; }
public GetRetrospectiveStatusQueryHandler(IReturnDbContext returnDbContext, IRetrospectiveStatusMapper mapper) { this._returnDbContext = returnDbContext; this._mapper = mapper; }
public GetParticipantsInfoQueryHandler(IReturnDbContext returnDbContext, IMapper mapper) { this._returnDbContext = returnDbContext; this._mapper = mapper; }
public GetVotesQueryHandler(IReturnDbContext returnDbContext, IMapper mapper) { this._returnDbContext = returnDbContext; this._mapper = mapper; }
public async Task <GetVotesQueryResult> Handle(GetVotesQuery request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } using IReturnDbContext dbContext = this._returnDbContextFactory.CreateForEditContext(); Retrospective retrospective = await dbContext.Retrospectives.AsNoTracking().FindByRetroId(request.RetroId, cancellationToken); if (retrospective == null) { throw new NotFoundException(nameof(Retrospective), request.RetroId); } List <Participant> participants = await dbContext.Participants.AsNoTracking(). Where(x => x.Retrospective.UrlId.StringId == request.RetroId). ToListAsync(cancellationToken); List <NoteLane> lanes = await dbContext.NoteLanes.ToListAsync(cancellationToken); int numberOfVotesPerLane = retrospective.Options.MaximumNumberOfVotes; ILookup <int, NoteVote> votes = dbContext.NoteVotes.AsNoTracking() .Include(x => x.Participant) .Include(x => x.Note) .Include(x => x.Note.Lane) .Include(x => x.NoteGroup) .Include(x => x.NoteGroup.Lane) .Where(x => x.Retrospective.UrlId.StringId == request.RetroId) .AsEnumerable() .ToLookup(x => x.Participant.Id, x => x); var result = new RetrospectiveVoteStatus(numberOfVotesPerLane); foreach (Participant participant in participants) { foreach (NoteLane noteLane in lanes) { int votesCast = 0; foreach (NoteVote noteVote in votes[participant.Id]) { if ((noteVote.Note?.Lane ?? noteVote.NoteGroup?.Lane)?.Id != noteLane.Id) { continue; } result.Votes.Add(this._mapper.Map <VoteModel>(noteVote)); votesCast++; } int votesLeft = numberOfVotesPerLane - votesCast; for (int v = 0; v < votesLeft; v++) { result.Votes.Add(new VoteModel { ParticipantId = participant.Id, ParticipantColor = this._mapper.Map <ColorModel>(participant.Color), ParticipantName = participant.Name }); } } } result.Initialize(); return(new GetVotesQueryResult(result)); }
public RejoinRetrospectiveCommandHandler(IReturnDbContext returnDbContext, ICurrentParticipantService currentParticipantService) { this._returnDbContext = returnDbContext; this._currentParticipantService = currentParticipantService; }
public GetJoinRetrospectiveInfoQueryHandler(IReturnDbContext dbContext, ILogger <GetJoinRetrospectiveInfoQueryHandler> logger) { this._dbContext = dbContext; this._logger = logger; }
public BaseDataSeeder(IReturnDbContext returnDbContext) { this._returnDbContext = returnDbContext; }
public SeedBaseDataCommandHandler(IReturnDbContext returnDbContext) { this._returnDbContext = returnDbContext; }
public RetrospectiveStatusMapper(IReturnDbContext returnDbContext, IMapper mapper) { this._returnDbContext = returnDbContext; this._mapper = mapper; }