public async Task <IReadOnlyList <AttendanceDto> > HandleAsync(BrowseAttendances query)
        {
            var participant = await _participantsRepository.GetAsync(query.ConferenceId, query.UserId);

            if (participant is null)
            {
                return(null);
            }

            var attendances = new List <AttendanceDto>();
            var tracks      = await _agendasApiClient.GetAgendaAsync(query.ConferenceId);

            var slots = tracks.SelectMany(x => x.Slots.OfType <RegularAgendaSlotDto>()).ToArray();

            foreach (var attendance in participant.Attendances)
            {
                var slot = slots.Single(x => x.AgendaItem.Id == attendance.AttendableEventId);
                attendances.Add(new AttendanceDto
                {
                    ConferenceId = query.ConferenceId,
                    EventId      = slot.Id,
                    From         = attendance.From,
                    To           = attendance.To,
                    Title        = slot.AgendaItem.Title,
                    Description  = slot.AgendaItem.Description,
                    Level        = slot.AgendaItem.Level
                });
            }

            return(attendances);
        }
        public async Task HandleAsync(TicketPurchased @event)
        {
            var participant = await _participantsRepository.GetAsync(@event.ConferenceId, @event.UserId);

            if (participant is not null)
            {
                return;
            }

            participant = new Participant(Guid.NewGuid(), @event.ConferenceId, @event.UserId);
            await _participantsRepository.AddAsync(participant);

            _logger.LogInformation($"Added a participant with ID: '{participant.Id}' " +
                                   $"for conference: '{participant.ConferenceId}', user: '******'.");
        }
Esempio n. 3
0
        public async Task HandleAsync(AttendEvent command)
        {
            var attendableEvent = await _attendableEventsRepository.GetAsync(command.Id);

            if (attendableEvent is null)
            {
                throw new AttendableEventNotFoundException(command.Id);
            }

            var participant = await _participantsRepository
                              .GetAsync(attendableEvent.ConferenceId, command.ParticipantId);

            if (participant is null)
            {
                throw new ParticipantNotFoundException(attendableEvent.ConferenceId, command.ParticipantId);
            }

            attendableEvent.Attend(participant);
            await _participantsRepository.UpdateAsync(participant);

            await _attendableEventsRepository.UpdateAsync(attendableEvent);
        }