public async Task Handle(RemoveConferenceCommand command) { var conference = await _context.Conferences .Include("Endpoints") .Include("Participants.ParticipantStatuses") .Include(x => x.Participants).ThenInclude(x => x.LinkedParticipants) .Include("ConferenceStatuses") .Include(x => x.Participants).ThenInclude(x => x.TestCallResult) .SingleOrDefaultAsync(x => x.Id == command.ConferenceId); if (conference == null) { throw new ConferenceNotFoundException(command.ConferenceId); } var events = await _context.Events.Where(x => x.ConferenceId == conference.Id).ToListAsync(); var tasks = await _context.Tasks.Where(x => x.ConferenceId == conference.Id).ToListAsync(); _context.Remove(conference); _context.RemoveRange(events); _context.RemoveRange(tasks); await _context.SaveChangesAsync(); }
public async Task Handle(RemoveHeartbeatsForConferencesCommand command) { var expiredConferences = _context.Conferences.Where(c => c.ScheduledDateTime <= DateTime.UtcNow.AddDays(-14)).Select(c => c.Id); var expiredHeartbeats = await _context.Heartbeats.Where(x => expiredConferences.Contains(x.ConferenceId)).ToListAsync(); _context.RemoveRange(expiredHeartbeats); await _context.SaveChangesAsync(); }
public async Task Handle(RemoveInstantMessagesForConferenceCommand command) { var instantMessages = await _context.InstantMessages.Where(x => x.ConferenceId == command.ConferenceId).ToListAsync(); _context.RemoveRange(instantMessages); await _context.SaveChangesAsync(); }
public async Task RemoveHeartbeats(List <Conference> conferences) { var conferenceIds = conferences.Select(conference => conference.Id).ToList(); await using var db = new VideoApiDbContext(_dbContextOptions); var heartbeats = await db.Heartbeats .Where(x => conferenceIds.Contains(x.ConferenceId)) .ToListAsync(); db.RemoveRange(heartbeats); await db.SaveChangesAsync(); }
public async Task RemoveConferences(List <Conference> conferences) { await using var db = new VideoApiDbContext(_dbContextOptions); var conferenceIds = conferences.Select(conference => conference.Id).ToList(); var allConferences = await db.Conferences .Include("Endpoints") .Include("Participants.ParticipantStatuses") .Include("ConferenceStatuses") .Where(x => conferenceIds.Contains(x.Id)).ToListAsync(); db.RemoveRange(allConferences); await db.SaveChangesAsync(); foreach (var id in conferenceIds) { await RemoveAlerts(id); } }