public static void DeleteOrphans() { using (var db = new MedSimDbContext()) { var threeWeeksPrior = DateTime.UtcNow.AddDays(-21); var dpts = db.Departments.Include("Participants").Where(d => !d.AdminApproved && d.CreatedUtc < threeWeeksPrior && !d.Participants.Any()).ToList(); db.Departments.RemoveRange(dpts); db.SaveChanges(); var insts = db.Institutions.Where(i => !i.AdminApproved && i.CreatedUtc < threeWeeksPrior && !i.Departments.Any()); db.Institutions.RemoveRange(insts); db.SaveChanges(); } }
public static void RescheduleReadings(Course course, MedSimDbContext context) { var existingJobs = context.CourseHangfireJobs.Where(ch => ch.CourseId == course.Id).ToList(); foreach (var ej in existingJobs) { BackgroundJob.Delete(ej.HangfireId); context.CourseHangfireJobs.Remove(ej); } context.SaveChanges(); context.CourseHangfireJobs.AddRange(EnqueReading(course)); context.SaveChanges(); }
public static void SendReading(Guid courseId, DateTime schedule, PerformContext context) { using (var db = new MedSimDbContext()) { var course = db.Courses.Include("CourseFormat.CourseType.CandidatePrereadings").Include("CourseParticipants.Participant").Include("HangfireJobs") .First(c => c.Id == courseId); var readings = GetSupplementReadings(course, schedule); using (var mail = new MailMessage()) { mail.To.AddParticipants(from cp in course.CourseParticipants where !cp.IsFaculty select cp.Participant); var confirmEmail = new CandidateReadingMessage { Course = course, }; mail.CreateHtmlBody(confirmEmail); foreach (var a in GetSupplementReadings(course, schedule)) { mail.Attachments.Add(a); } using (var smtp = new SmtpClient()) { smtp.Send(mail); } } db.CourseHangfireJobs.RemoveRange(course.HangfireJobs.Where(hj => hj.HangfireId == context.BackgroundJob.Id)); db.SaveChanges(); } }