public async Task Handle([NotNull] EventEditedEvent notification, CancellationToken cancellationToken)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            var evt = await eventRepository.FindByIdAsync(notification.EventId);

            if (evt == null)
            {
                logger.LogError("Event [{id}] not found!", notification.EventId);
                return;
            }

            var recipients = await recipientsBuilder.GetAllTauchboldeButDeclinedParticipantsAsync(
                evt.OrganisatorId,
                evt.Id);

            var message = $"Aktivität '{evt.Name}' ({evt.StartTime.FormatTimeRange(evt.EndTime)}) von {evt.Organisator?.Realname ?? ""} geändert";

            await notificationPublisher.PublishAsync(
                NotificationType.EditEvent,
                message,
                recipients,
                relatedEventId : evt.Id);
        }
Exemple #2
0
        public async Task Handle([NotNull] ParticipationChangedEvent notification, CancellationToken cancellationToken)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            var participant = await GetParticipantAsync(notification);

            var eventName = await GetEventNameAsync(participant.EventId);

            var diverRealName = await GetDiverRealNameAsync(participant.ParticipatingDiverId);

            var noteText = !string.IsNullOrWhiteSpace(participant.Note)
                ? $"Notiz: {participant.Note}"
                : "";

            var messageBuilder = new Dictionary <ParticipantStatus, Func <string> >
            {
                { ParticipantStatus.None, () => $"{diverRealName} weiss nicht ob Er/Sie an '{eventName}' teil nimmt. {noteText}".Trim() },
                { ParticipantStatus.Accepted, () => $"{diverRealName} nimmt an '{eventName}' teil. {noteText}".Trim() },
                { ParticipantStatus.Declined, () => $"{diverRealName} hat für '{eventName}' abgesagt. {noteText}".Trim() },
                { ParticipantStatus.Tentative, () => $"{diverRealName} nimmt eventuell an '{eventName}' teil. {noteText}".Trim() }
            };

            var recipients = await recipientsBuilder.GetAllTauchboldeButDeclinedParticipantsAsync(
                participant.ParticipatingDiverId,
                participant.EventId);

            await notificationPublisher.PublishAsync(
                mapParticipationStatusToNotificationType[participant.Status],
                messageBuilder[participant.Status](),
                recipients,
                relatedEventId : participant.EventId);
        }
Exemple #3
0
        public PublishParticipationChangedPolicyTests()
        {
            foundParticipant = new Participant
            {
                Id      = validParticipantId,
                EventId = validEventId,
                ParticipatingDiverId = validDiverId,
                Status        = ParticipantStatus.None,
                CountPeople   = 1,
                BuddyTeamName = "team1"
            };

            A.CallTo(() => participantRepository.GetParticipantByIdAsync(A <Guid> ._))
            .ReturnsLazily(call => Task.FromResult(
                               (Guid)call.Arguments[0] == validParticipantId
                        ? foundParticipant
                        : null
                               ));

            A.CallTo(() => eventRepository.FindByIdAsync(A <Guid> ._))
            .ReturnsLazily(call => Task.FromResult(
                               (Guid)call.Arguments[0] == validEventId
                        ? new Event
            {
                Id   = validEventId,
                Name = "Testevent",
            }
                        : null
                               ));

            A.CallTo(() => diverRepository.FindByIdAsync(A <Guid> ._))
            .ReturnsLazily(call => Task.FromResult(
                               (Guid)call.Arguments[0] == validDiverId
                        ? new Diver {
                Id = validDiverId, Fullname = "John Doe"
            }
                        : null
                               ));

            A.CallTo(() => recipientsBuilder.GetAllTauchboldeButDeclinedParticipantsAsync(validDiverId, validEventId))
            .ReturnsLazily(() => Task.FromResult(
                               new List <Diver>
            {
                new Diver {
                    Id = new Guid("A00D5B04-B86D-4DAF-828F-00D286F4093B"), Fullname = "Jane Doe"
                },
                new Diver {
                    Id = new Guid("0DE86468-0F8C-4C02-A3CB-80460D45B0FF"), Fullname = "Jim Doe"
                },
            }
                               ));

            policy = new PublishParticipationChangedPolicy(logger, diverRepository, eventRepository, participantRepository, notificationPublisher, recipientsBuilder);
        }
        public async Task Handle(CommentEditedEvent notification, CancellationToken cancellationToken)
        {
            var comment = await commentRepository.FindByIdAsync(notification.CommentId);

            var author = await diverRepository.FindByIdAsync(notification.AuthorId);

            var evt = await eventRepository.FindByIdAsync(notification.EventId);

            var recipients = await recipientsBuilder.GetAllTauchboldeButDeclinedParticipantsAsync(
                author.Id,
                notification.EventId);

            var startEndTimeAsString = evt.StartTime.FormatTimeRange(evt.EndTime);
            var message =
                $"Neuer Kommentar von '{author.Realname}' für Event '{evt.Name}' ({startEndTimeAsString}): {comment?.Text}";

            await notificationPublisher.PublishAsync(
                NotificationType.Commented,
                message,
                recipients,
                relatedEventId : notification.EventId);
        }
        public async Task Handle([NotNull] CommentCreatedEvent notification, CancellationToken cancellationToken)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            var author = await diverRepository.FindByIdAsync(notification.AuthorId);

            var evt = await eventRepository.FindByIdAsync(notification.EventId);

            var recipients = await recipientsBuilder.GetAllTauchboldeButDeclinedParticipantsAsync(
                author.Id,
                notification.EventId);

            var startEndTimeString = evt.StartTime.FormatTimeRange(evt.EndTime);
            var message            = $"Neuer Kommentar von '{author.Realname}' für Event '{evt.Name}' ({startEndTimeString}): {notification.Text}";

            await notificationPublisher.PublishAsync(
                NotificationType.Commented,
                message,
                recipients,
                relatedEventId : notification.EventId);
        }
        public PublishNewEventPolicyTests()
        {
            A.CallTo(() => eventRepository.FindByIdAsync(A <Guid> ._))
            .ReturnsLazily(call => Task.FromResult(
                               (Guid)call.Arguments[0] == validEventId
                        ? new Event
            {
                Id            = validEventId,
                Name          = "Test Event",
                Location      = "loc",
                MeetingPoint  = "meet",
                Description   = "descr",
                StartTime     = new DateTime(2019, 9, 1, 19, 0, 0),
                OrganisatorId = currentUserId,
                Organisator   = new Diver
                {
                    Id       = new Guid("8DCF530A-E55D-4FED-97D7-D636CDAD8BFC"),
                    Fullname = "John Doe",
                }
            }
                        : null));

            A.CallTo(() => recipientsBuilder.GetAllTauchboldeButDeclinedParticipantsAsync(currentUserId, validEventId))
            .ReturnsLazily(() => Task.FromResult(
                               new List <Diver>
            {
                new Diver {
                    Id = new Guid("A73286C3-BD30-4D2B-BAF4-43F7A0EB7B21")
                },
                new Diver {
                    Id = new Guid("6D717184-7A4B-4091-9133-AC539F55C5C4")
                }
            }));

            policy = new PublishNewEventPolicy(logger, notificationPublisher, recipientsBuilder, eventRepository);
        }