private async Task <GetDetails.SchoolDetails> BuildDetails(SchoolAggregate school, IReadOnlyCollection <IDomainEvent <SchoolAggregate, SchoolId> > events) { var today = _clock.GetTodayDate(); return(new GetDetails.SchoolDetails() { Id = school.Id.GetGuid(), Name = school.SchoolName, Address = school.Address, City = school.City, ContactData = school.ContactData, Events = await BuildEventData(school, events), Notes = await Task.WhenAll(school.Notes.Select(async x => new GetDetails.NoteData() { Id = x.NoteId, CreatedAt = x.CreationTimestamp.InMainTimezone().ToOffsetDateTime(), EditedAt = x.LastEditTimestamp?.InMainTimezone().ToOffsetDateTime(), WasEdited = x.WasEdited, Author = await GetUserName(x.AuthorId), Content = x.Content })), HasAgreedInitially = school.HasAgreedInitially, HasSignedPermanentAgreement = school.HasSignedPermanentAgreement, HasSignedFixedTermAgreement = school.HasSignedFixedTermAgreement(today), AgreementEndDate = school.AgreementEndDate, HasResignedPermanently = school.HasResignedPermanently, HasResignedTemporarily = school.HasResignedTemporarily(today), ResignationEndDate = school.ResignationEndDate }); }
private async Task <GetDetails.EventData> BuildEventData(SchoolAggregate school, IDomainEvent <SchoolAggregate, SchoolId> @event) { switch (@event.GetAggregateEvent()) { case SchoolRegistered e: return(new GetDetails.SchoolRegisteredEventData() { DateTime = e.Timestamp.InMainTimezone().ToOffsetDateTime() }); case ContactOccured e: return(new GetDetails.ContactOccuredEventData() { DateTime = e.ContactTimestamp.InMainTimezone().ToOffsetDateTime(), CommunicationChannel = e.CommunicationChannel, ContactPersonName = e.ContactPersonName, PhoneNumber = e.PhoneNumber, EmailAddress = e.EmailAddress, Content = e.Content, AdditionalNotes = e.AdditionalNotes, RecordingUser = await GetUserName(e.RecordingUserId) }); case InitialAgreementAchieved e: return(new GetDetails.InitialAgreementAchievedEventData() { DateTime = OffsetDateTime.FromDateTimeOffset(@event.Timestamp), AgreeingPersonName = e.AgreeingPersonName, AdditionalNotes = e.AdditionalNotes, RecordingUser = await GetUserName(e.RecordingUserId) }); case FixedTermAgreementSigned e: return(new GetDetails.FixedTermAgreementSignedEventData() { AgreementId = e.Id, DateTime = OffsetDateTime.FromDateTimeOffset(@event.Timestamp), AgreementEndDate = e.AgreementEndDate, AdditionalNotes = e.AdditionalNotes, RecordingUser = await GetUserName(e.RecordingUserId) }); case PermanentAgreementSigned e: return(new GetDetails.PermanentAgreementSignedEventData() { AgreementId = e.Id, DateTime = OffsetDateTime.FromDateTimeOffset(@event.Timestamp), AdditionalNotes = e.AdditionalNotes, RecordingUser = await GetUserName(e.RecordingUserId) }); case SchoolResignedFromCooperation e: return(new GetDetails.SchoolResignedFromCooperationEventData() { DateTime = OffsetDateTime.FromDateTimeOffset(@event.Timestamp), PotentialNextContactDate = e.PotentialNextContactDate, AdditionalNotes = e.AdditionalNotes, RecordingUser = await GetUserName(e.RecordingUserId) }); case NoteAdded _: case NoteEdited _: case NoteDeleted _: return(null); default: throw new NotImplementedException(); } }
private async Task <IReadOnlyCollection <GetDetails.EventData> > BuildEventData(SchoolAggregate school, IEnumerable <IDomainEvent <SchoolAggregate, SchoolId> > events) { var eventData = await Task.WhenAll(events.Select(async @event => await BuildEventData(school, @event))); return(eventData.Where(x => x != null).ToList()); }