public void SendSessionReport(IEnumerable<Topic> topics, SessionReport report) { ViewData.Model = topics; ViewBag.Report = report; ViewBag.Host = FQDN; var mail = Populate(x => { x.Subject = string.Format("Eine Sitzung des Typs »{0}« wurde durchgeführt", report.SessionType.Name); x.ViewName = "NewSessionReport"; foreach (var user in report.SessionType.Attendees.Where(u => u.IsActive)) { if (user.Settings.ReportOccasions == SessionReportOccasions.Always || (user.Settings.ReportOccasions == SessionReportOccasions.WhenAbsent && !report.PresentUsers.Contains(user))) x.To.Add(user.EmailAddress); } }); if (mail.To.Count > 0) mail.Send(); }
private async Task<ActionResult> ProcessTopics(ActiveSession session, SessionReport report) { List<Topic> topics = db.Topics .Include(t => t.SessionType) .Include(t => t.Lock) .Include(t => t.Assignments) .Where(t => t.Lock.Session.ID == session.ID) .ToList(); var mailer = new UserMailer(); try { mailer.SendSessionReport(topics, report); } catch (Exception ex) { // return HTTPStatus(HttpStatusCode.InternalServerError, "Fehler beim Versenden der E-Mails: " + ex.Message); } foreach (var t in topics) { switch (t.Lock.Action) { case TopicAction.None: t.IsReadOnly = false; break; case TopicAction.Decide: t.Decision = new Decision { OriginTopic = t, Report = report, Text = t.Proposal, Type = DecisionType.Resolution }; // Inaktive Aufgaben löschen db.Assignments.RemoveRange(db.Assignments.Where(a => a.TopicID == t.ID && !a.IsActive)); // Für aktive Umsetzungaufgaben E-Mails verschicken var tasks = new List<Task>(); foreach (var duty in t.Assignments.Where(a => a.Type == AssignmentType.Duty && a.IsActive)) tasks.Add(mailer.SendNewAssignment(duty)); await Task.WhenAll(tasks); break; case TopicAction.Close: t.Decision = new Decision { OriginTopic = t, Report = report, Text = t.Proposal, Type = DecisionType.Closed }; break; case TopicAction.Delete: db.DeleteTopic(t.ID); break; default: throw new ArgumentOutOfRangeException(); } if (t.Lock != null) // Wenn gelöscht wird, ist t.Lock hier bereits null db.TopicLocks.Remove(t.Lock); } return null; }