public async Task <Result <Nothing, Error> > Handle(EditNote.Command request, CancellationToken cancellationToken)
        {
            var editingUser = await _userAccessor.GetUser();

            var result = await _aggregateStore.Update <SchoolAggregate, SchoolId, Result <Nothing, Error> >(
                SchoolId.With(request.SchoolId), CommandId.New,
                async (aggregate, token) => {
                var notes = aggregate.Notes.Where(x => x.NoteId == request.NoteId).ToList();
                var note  = aggregate.Notes.SingleOrDefault(x => x.NoteId == request.NoteId);
                return
                (await _authService.AuthorizeAsResult(await _userAccessor.GetClaimsPrincipal(), note, AuthorizationPolicies.OwningCoordinatorOnly)
                 .Tap(result => aggregate.EditNote(request, editingUser, _clock.GetCurrentInstant())));
            },
                cancellationToken);

            return(result.Unwrap());
        }
 public Result <Nothing, Error> EditNote(EditNote.Command command, ApplicationUser editingUser, Instant now)
 {
     Guard.Against.Null(command, nameof(command));
     Guard.Against.Null(editingUser, nameof(editingUser));
     Guard.Against.Default(now, nameof(now));
     ValidateIdMatchOrThrow(command.SchoolId);
     return(Validate(new EditNote.Validator(), command)
            .Ensure(
                _ => this.IsNew == false,
                new Error.ResourceNotFound(Messages.School_not_found))
            .Ensure(
                _ => this.Notes.Any(x => x.NoteId == command.NoteId),
                new Error.DomainError(DeleteNote_Messages.Note_does_not_exist)
                )
            .Tap(
                _ => Emit(new NoteEdited(
                              timestamp: now,
                              noteId: command.NoteId,
                              editingUserId: editingUser.Id,
                              content: command.Content))
                ));
 }
        public async Task <IActionResult> EditNote(EditNote.Command command)
        {
            var result = await _engine.Execute(command);

            return(result.MatchToActionResult(success => Ok()));
        }