public TeacherController(SIEContext context, IConfiguration configuration) { _bHistory = new BHistory(context); _bActivity = new BActivity(context); _bRoom = new BRoom(context); _bAnswer = new BAnswer(context); _bDocument = new BDocument(context); _bRelUploadActivity = new BRelUploadActivity(context); _uActivity = new UActivity(context); _uRoom = new URoom(context); _uAnswer = new UAnswer(context); _uRelUploadActivity = new URelUploadActivity(context); _uRelUploadAnswer = new URelUploadAnswer(context); _configuration = configuration; }
public StudentController(SIEContext context, IConfiguration configuration) { _context = context; _bHistory = new BHistory(context); _bRelStudentRoom = new BRelStudentRoom(context); _bRoom = new BRoom(context); _bAnswer = new BAnswer(context); _bDocument = new BDocument(context); _bRelUploadAnswer = new BRelUploadAnswer(context); _uActivity = new UActivity(context); _uRelStudentRoom = new URelStudentRoom(context); _uRoom = new URoom(context); _uAnswer = new UAnswer(context); _uRelUploadActivity = new URelUploadActivity(context); _uRelUploadAnswer = new URelUploadAnswer(context); _uPerson = new UPerson(context); _configuration = configuration; }
public async Task ExecuteAsync(CancellationToken cancellationToken) { var serviceProvider = _serviceProvider.GetRequiredService <IServiceScopeFactory>(); using (var scope = serviceProvider.CreateScope()) { var sevenDaysFromNow = DateTime.Now.AddDays(7); var context = scope.ServiceProvider.GetService <SIEContext>(); var toExpire = new UActivity(context) .Get() .Where(r => r.CurrentState == (int)EActivityState.InProgress && r.ExpirationDate != null && r.ExpirationDate <= sevenDaysFromNow) .ToList(); if (!toExpire.Any()) { return; } var uRelStudentRoom = new URelStudentRoom(context); var students = (IEnumerable <RelStudentRoom>) new List <RelStudentRoom>(); foreach (var activity in toExpire) { students = students .Concat(uRelStudentRoom.GetByRoom(activity.Room.Id)); } students = students.DistinctBy(s => s.Person.Id); var sEmail = new EmailService(_configuration); var uAnswer = new UAnswer(context); foreach (var student in students) { var listActivities = toExpire .Where(a => a.Room.Id == student.Room.Id && uAnswer.GetByUser(a.Id, student.Person.Id) == null) .OrderBy(a => a.ExpirationDate) .ToList(); if (!listActivities.Any()) { continue; } var body = "<h3>Atividades a serem entregues na próxima semana</h3><br/>" + "<table border='1' cellpadding='2' cellspacing='0' height='100%' width='100%'>" + "<thead>" + "<tr><td>Título</td><td>Descrição</td><td>Data final para entrega</td></tr>" + "</thead>" + "<tbody>"; listActivities .ForEach(t => { body += "<tr>" + $"<td><a href='http://localhost:8080/#/student/room/{t.Room.Code}/activity/{t.Id}'>{t.Title}</a></td>" + $"<td>{(!string.IsNullOrEmpty(t.Description) ? t.Description : "-")}</td>" + $"<td>{t.ExpirationDate:dd/MM/yyyy}</td>" + "</tr>"; }); body += "</tbody>" + "</table>"; sEmail.SendEmail("Suas atividades a serem entregues nos próximos dias", body, new List <string> { student.Person.Email }); } } }