Esempio n. 1
0
        /// <inheritdoc />
        public async Task Handle(AttendeeCreatedIntegrationEvent notification, CancellationToken cancellationToken)
        {
            Maybe <Attendee> maybeAttendee = await _attendeeRepository.GetByIdAsync(notification.AttendeeId);

            if (maybeAttendee.HasNoValue)
            {
                throw new DomainException(DomainErrors.Attendee.NotFound);
            }

            Attendee attendee = maybeAttendee.Value;

            Maybe <GroupEvent> maybeGroupEvent = await _groupEventRepository.GetByIdAsync(attendee.EventId);

            if (maybeGroupEvent.HasNoValue)
            {
                throw new DomainException(DomainErrors.GroupEvent.NotFound);
            }

            Maybe <User> maybeUser = await _userRepository.GetByIdAsync(attendee.UserId);

            if (maybeUser.HasNoValue)
            {
                throw new DomainException(DomainErrors.User.NotFound);
            }

            GroupEvent groupEvent = maybeGroupEvent.Value;

            User user = maybeUser.Value;

            var attendeeCreatedEmail = new AttendeeCreatedEmail(
                user.Email,
                user.FullName,
                groupEvent.Name,
                groupEvent.DateTimeUtc.ToString(CultureInfo.InvariantCulture));

            await _emailNotificationService.SendAttendeeCreatedEmail(attendeeCreatedEmail);
        }