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

            var result = await _aggregateStore.Update <SchoolAggregate, SchoolId, Result <Nothing, Error> >(
                SchoolId.With(request.SchoolId), CommandId.New,
                (aggregate) => aggregate.RecordContact(request, user, _clock.GetCurrentInstant()),
                cancellationToken);

            return(result.Unwrap());
        }
        public async Task <Result <Guid, Error> > Handle(AddNote.Command request, CancellationToken cancellationToken)
        {
            var author = await _userAccessor.GetUser();

            var result = await _aggregateStore.Update <SchoolAggregate, SchoolId, Result <Guid, Error> >(
                SchoolId.With(request.SchoolId), CommandId.New,
                (aggregate) => aggregate.AddNote(request, author, _clock.GetCurrentInstant()),
                cancellationToken);

            return(result.Unwrap());
        }
Beispiel #3
0
        public async Task <Result <Guid, Error> > Handle(RecordAgreementSigned.Command request, CancellationToken cancellationToken)
        {
            var user = await _userAccessor.GetUser();

            var today = _clock.GetTodayDate();

            var result = await _aggregateStore.Update <SchoolAggregate, SchoolId, Result <Guid, Error> >(
                SchoolId.With(request.SchoolId), CommandId.New,
                (aggregate) => aggregate.RecordAgreementSigned(request, user, today),
                cancellationToken);

            return(result.Unwrap());
        }
Beispiel #4
0
        public async Task <Result <Nothing, Error> > Handle(RecordResignation.Command request, CancellationToken cancellationToken)
        {
            var user = await _userAccessor.GetUser();

            var now = _clock.GetTodayDate();

            var result = await _aggregateStore.Update <SchoolAggregate, SchoolId, Result <Nothing, Error> >(
                SchoolId.With(request.SchoolId), CommandId.New,
                (aggregate) => aggregate.RecordResignation(request, user, now),
                cancellationToken);

            return(result.Unwrap());
        }
Beispiel #5
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());
        }
Beispiel #6
0
        public async Task <Result <GetDetails.SchoolDetails, Error> > Handle(GetDetails.Query request, CancellationToken cancellationToken)
        {
            var id = SchoolId.With(request.SchoolId);

            var events = await _eventStore.LoadEventsAsync <SchoolAggregate, SchoolId>(id, cancellationToken);

            var school = await _aggregateStore.LoadAsync <SchoolAggregate, SchoolId>(id, cancellationToken);

            if (school.IsNew)
            {
                return(Result.Failure <GetDetails.SchoolDetails, Error>(new Error.ResourceNotFound()));
            }

            var details = await BuildDetails(school, events);

            return(Result.Success <GetDetails.SchoolDetails, Error>(details));
        }
Beispiel #7
0
        public async Task <Maybe <GetScannedAgreement.ScannedAgreement> > Handle(GetScannedAgreement.Query request, CancellationToken cancellationToken)
        {
            var events = await _eventStore.LoadEventsAsync <SchoolAggregate, SchoolId>(SchoolId.With(request.SchoolId), cancellationToken);

            if (events.None())
            {
                return(Maybe <GetScannedAgreement.ScannedAgreement> .None);
            }

            var permanentAgreement = events
                                     .Where(x => x.GetAggregateEvent() is PermanentAgreementSigned)
                                     .Cast <IDomainEvent <SchoolAggregate, SchoolId, PermanentAgreementSigned> >()
                                     .Select(x => x.AggregateEvent)
                                     .SingleOrDefault(x => x.Id == request.AgreementId);

            if (permanentAgreement != null)
            {
                return(Maybe <GetScannedAgreement.ScannedAgreement> .From(new GetScannedAgreement.ScannedAgreement()
                {
                    Content = permanentAgreement.ScannedDocument,
                    ContentType = permanentAgreement.ScannedDocumentContentType,
                    FileName = $"{request.SchoolId}{permanentAgreement.ScannedDocumentExtension}"
                }));
            }

            var fixedTermAgreement = events
                                     .Where(x => x.GetAggregateEvent() is FixedTermAgreementSigned)
                                     .Cast <IDomainEvent <SchoolAggregate, SchoolId, FixedTermAgreementSigned> >()
                                     .Select(x => x.AggregateEvent)
                                     .SingleOrDefault(x => x.Id == request.AgreementId);

            if (fixedTermAgreement != null)
            {
                return(Maybe <GetScannedAgreement.ScannedAgreement> .From(new GetScannedAgreement.ScannedAgreement()
                {
                    Content = fixedTermAgreement.ScannedDocument,
                    ContentType = fixedTermAgreement.ScannedDocumentContentType,
                    FileName = $"{request.SchoolId}{fixedTermAgreement.ScannedDocumentExtension}"
                }));
            }

            return(Maybe <GetScannedAgreement.ScannedAgreement> .None);
        }