public async Task <IActionResult> OnPostAsync() { // Get the Assingment AssignmentID = Assignment.AssignmentID; var assignment = await _context.GetAssignmentAsync(Assignment.AssignmentID); var document = new Document { AssignmentID = Assignment.AssignmentID, Assignment = assignment }; document = await MemoryStreamExtention.FileToDocumentAsync(FileUpload, document); var documentSuccess = await _context.AddDocumentAsync(document); var assignmentSuccess = true; if (assignment.DateCompleted == new DateTime()) { assignment.DateCompleted = DateTime.Now; assignmentSuccess = await _context.UpdateAssignmentAsync(assignment); } if (documentSuccess && assignmentSuccess) { var protege = await _context.GetProtegeByIDAsync(assignment.Session.Course.Pair.ProtegeID); var mentor = await _context.GetMentorByIDAsync(assignment.Session.Course.Pair.MentorID); var client = await _context.GetClientByIDAsync(assignment.Session.Course.Pair.ClientID); var subject = $"{protege?.AppUser?.Email} uploaded Assignment {assignment?.Title}"; var message = "<h1>Assignment Uploaded</h1>" + $"<p>The Assigment <strong>{assignment.Title}</strong> was submitted by <strong>{protege?.AppUser?.Email}</strong> at <strong>{assignment?.DateCompleted}</strong></p>"; if (protege != null && mentor != null) { await _emailSender.SendEmailAsync(protege.AppUser.Email, subject, message); } if (mentor != null) { await _emailSender.SendEmailAsync(mentor.AppUser.Email, subject, message); } if (client != null) { await _emailSender.SendEmailAsync(client.AppUser.Email, subject, message); } return(RedirectToPage("./Details", new { id = assignment.AssignmentID })); } return(RedirectToPage("/Error")); }
/// <summary> /// Creates an assignment, sends an email to the protege /// </summary> /// <returns>The post async.</returns> public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Assignment.SessionID = SessionID; var session = await _context.GetSessionAsync(SessionID); Assignment.Session = session; var success = await _context.AddAssingmentAsync(Assignment); var subject = session.Course.CourseName + " New Assigment Created"; var message = $"<h1>Hello!</h1> <p>A new assigment: {Assignment.Title} was just created<p/>.<br/><p>Due Date: {Assignment.DueDate}</p> <br/> <p>Description: {Assignment.Description}</p>"; if (success) { var protegeID = session.Course.Pair.ProtegeID; var protege = await _context.GetProtegeByIDAsync(protegeID); if (protege != null) { try { await _emailSender.SendEmailAsync( protege.AppUser.Email, subject, message); } catch (Exception ex) { Console.WriteLine(ex.Message); } } var client = await _context.GetClientByIDAsync(session.Course.Pair.ClientID); if (client != null) { await _emailSender.SendEmailAsync( client.AppUser.Email, subject, message); } return(RedirectToPage("/Sessions/Details", new { id = SessionID })); } return(RedirectToPage("/Error")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var course = await _context.GetCourseAsync(CourseID); Event.Course = course; Event.CourseID = CourseID; var success = await _context.AddEventAsync(Event); if (!success) { return(RedirectToPage("/Error")); } var mentor = await _context.GetMentorByIDAsync(course.Pair.MentorID); var protege = await _context.GetProtegeByIDAsync(course.Pair.ProtegeID); var client = await _context.GetClientByIDAsync(course.Pair.ClientID); var subject = $"{mentor?.AppUser?.Email} created an Event {Event.EventName}"; var message = "<h1>Assignment Uploaded</h1>" + $"<p>The Event <strong>{Event.EventName}</strong> was created by <strong>{mentor?.AppUser?.Email}</strong> and starts at <strong>{Event.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("/Mentor/Course/Index", new { id = course.CourseID })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var session = await _context.GetSessionAsync(SessionID); if (session == null) { return(RedirectToPage("/Error")); } var fileUpload = new FileUpload { Category = "Agenda", Document = FileUpload }; var document = new Document(); document = await MemoryStreamExtention.FileToDocumentAsync(fileUpload, document); var agenda = new Agenda { CreationDate = DateTime.Now, Name = Name, SessionID = SessionID, Session = session, Document = document }; var success = await _context.AddAgendaAsync(agenda); if (success) { var protege = await _context.GetProtegeByIDAsync(session.Course.Pair.ProtegeID); var mentor = await _context.GetMentorByIDAsync(session.Course.Pair.MentorID); var client = await _context.GetClientByIDAsync(session.Course.Pair.ClientID); var subject = $"{protege?.AppUser?.Email} uploaded Agenda {agenda.Name}"; var message = "<h1>Agenda Uploaded</h1>" + $"<p>The Assigment <strong>{agenda.Name}</strong> was submitted by <strong>{protege?.AppUser?.Email}</strong> at <strong>{agenda.CreationDate}</strong></p>"; if (protege != null) { await _emailSender.SendEmailAsync(protege.AppUser.Email, subject, message); } if (mentor != null) { await _emailSender.SendEmailAsync(mentor.AppUser.Email, subject, message); } if (client != null) { await _emailSender.SendEmailAsync(client.AppUser.Email, subject, message); } return(RedirectToPage("/Sessions/Details", new { id = session.SessionID })); } return(RedirectToPage("./Index")); }