Exemple #1
0
        public async Task <Result <Nothing, Error> > Handle(DeleteNote.Command request, CancellationToken cancellationToken)
        {
            var deletingUser = 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.DeleteNote(request, deletingUser, _clock.GetCurrentInstant())));
            },
                cancellationToken);

            return(result.Unwrap());
        }