Example #1
0
        public async Task Handle(AddEndpointCommand command)
        {
            var conference = await _context.Conferences.Include(x => x.Endpoints)
                             .SingleOrDefaultAsync(x => x.Id == command.ConferenceId);

            if (conference == null)
            {
                throw new ConferenceNotFoundException(command.ConferenceId);
            }

            var ep = new Endpoint(command.DisplayName, command.SipAddress, command.Pin, command.DefenceAdvocate);

            conference.AddEndpoint(ep);
            _context.Entry(ep).State = EntityState.Added;
            await _context.SaveChangesAsync();
        }
        public async Task Handle(AddParticipantsToConferenceCommand command)
        {
            var conference = await _context.Conferences.Include("Participants")
                             .SingleOrDefaultAsync(x => x.Id == command.ConferenceId);

            if (conference == null)
            {
                throw new ConferenceNotFoundException(command.ConferenceId);
            }

            foreach (var participant in command.Participants)
            {
                conference.AddParticipant(participant);
                _context.Entry(participant).State = EntityState.Added;
            }

            await _context.SaveChangesAsync();
        }
        public async Task Handle(AddParticipantsToConferenceCommand command)
        {
            var conference = await _context.Conferences.Include(x => x.Participants)
                             .SingleOrDefaultAsync(x => x.Id == command.ConferenceId);

            if (conference == null)
            {
                throw new ConferenceNotFoundException(command.ConferenceId);
            }

            foreach (var participant in command.Participants)
            {
                conference.AddParticipant(participant);
                _context.Entry(participant).State = EntityState.Added;
            }

            foreach (var linkedParticipant in command.LinkedParticipants)
            {
                try
                {
                    var primaryParticipant =
                        conference.Participants.Single(x => x.ParticipantRefId == linkedParticipant.ParticipantRefId);

                    var secondaryParticipant =
                        conference.Participants.Single(x => x.ParticipantRefId == linkedParticipant.LinkedRefId);

                    primaryParticipant.AddLink(secondaryParticipant.Id, linkedParticipant.Type);
                }
                catch (Exception)
                {
                    throw new ParticipantLinkException(linkedParticipant.ParticipantRefId, linkedParticipant.LinkedRefId);
                }
            }

            await _context.SaveChangesAsync();
        }