public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var course = await _context.GetCourseAsync(CourseID); if (course == null) { return(RedirectToPage("/Error")); } Session.CourseID = CourseID; var success = await _context.CreateSessionAsync(Session); if (success) { var mentor = await _context.GetMentorByIDAsync(course.Pair.MentorID); var client = await _context.GetClientByIDAsync(course.Pair.ClientID); var protege = await _context.GetClientByIDAsync(course.Pair.ProtegeID); var subject = $"New Session Created for {course.CourseName}"; var message = "<h1>Session Created</h1>" + $"<p>The Session <strong>{Session.Name}</strong> was created by <strong>{mentor?.AppUser?.Email}</strong> and starts at <strong>{Session.StartDate}</strong></p>"; if (mentor != null) { await _emailSender.SendEmailAsync(mentor.AppUser.Email, subject, message); } if (protege != null) { await _emailSender.SendEmailAsync(protege.AppUser.Email, subject, message); } if (client != null) { await _emailSender.SendEmailAsync(client.AppUser.Email, subject, message); } return(RedirectToPage("./Details", new { id = Session.SessionID })); } else { return(RedirectToPage("/Error")); } }