public void AddNewRequest(DistanceEdRequest NewRequest) { AddNewRequests(new List <DistanceEdRequest>() { NewRequest }); }
public List <DistanceEdRequest> GetForCourse(string courseID) { List <DistanceEdRequest> returnMe = new List <DistanceEdRequest>(); using (SqlConnection connection = new SqlConnection(_connStr)) { using (SqlCommand sqlCommand = new SqlCommand { Connection = connection, CommandType = CommandType.Text, CommandText = "SELECT * FROM DistanceEdRequest WHERE CourseId=@CID" }) { sqlCommand.Parameters.AddWithValue("@CID", courseID); sqlCommand.Connection.Open(); SqlDataReader dbDataReader = sqlCommand.ExecuteReader(); if (dbDataReader.HasRows) { while (dbDataReader.Read()) { DistanceEdRequest obj = dataReaderToDistanceEdRequest(dbDataReader); if (obj != null) { returnMe.Add(obj); } } } sqlCommand.Connection.Close(); } } return(returnMe); }
public List <DistanceEdRequest> GetAll() { List <DistanceEdRequest> returnMe = new List <DistanceEdRequest>(); using (SqlConnection connection = new SqlConnection(_connStr)) { using (SqlCommand sqlCommand = new SqlCommand { Connection = connection, CommandType = CommandType.Text, CommandText = "SELECT * FROM DistanceEdRequest" }) { sqlCommand.Connection.Open(); SqlDataReader dbDataReader = sqlCommand.ExecuteReader(); if (dbDataReader.HasRows) { while (dbDataReader.Read()) { DistanceEdRequest obj = dataReaderToDistanceEdRequest(dbDataReader); if (obj != null) { returnMe.Add(obj); } } } sqlCommand.Connection.Close(); } } return(returnMe); }
/// <summary> /// Sends all enqueued mail messages /// </summary> /// <returns>ID numbers of successful notifications</returns> public List <int> SendAll(IEnumerable <string> destinations) { List <int> successes = new List <int>(); if (this._mailQueue.Count > 0) { using (SmtpClient smtpClient = new SmtpClient(this.hostname) { Port = this.smtpPort, UseDefaultCredentials = false, EnableSsl = true, Credentials = new NetworkCredential(this.username, this.password) }) { while (this._mailQueue.Count > 0) { DistanceEdRequest request = this._mailQueue.Dequeue(); StringBuilder body = new StringBuilder(); body.Append("<html>"); body.Append("<body>"); body.Append("<h3>LSSD Virtual Distance Ed Request</h3>"); body.Append("<p>A new distance ed request has been submitted. Please register this student in the specified distance ed class.</p>"); body.Append("<p>"); body.Append("<b>Date Submitted</b>: " + request.DateRequested.ToLongDateString() + " " + request.DateRequested.ToShortTimeString() + "<br>"); body.Append("<b>Submitted By</b>: " + request.Requestor + "<br>"); body.Append("<b>Request ID</b>: " + request.ID + "<br>"); body.Append("</p>"); body.Append("<p>"); body.Append("<b>Student Name</b>: " + request.StudentName + "<br>"); body.Append("<b>Student Number</b>: " + request.StudentNumber + "<br>"); body.Append("<b>Student Base School</b>: " + request.StudentBaseSchool + "<br>"); body.Append("</p>"); body.Append("<p>"); body.Append("<b>Mentor Teacher Name</b>: " + request.MentorTeacherName + "<br>"); body.Append("</p>"); body.Append("<p>"); if (request.DistanceEdClass != null) { body.Append("<b>Course Name</b>: " + (request.DistanceEdClass.Name ?? "Unknown") + "<br>"); body.Append("<b>Course Blackboard ID</b>: " + (request.DistanceEdClass.BlackboardID ?? "Unknown") + "<br>"); body.Append("<b>Course Start Date</b>: " + (request.DistanceEdClass.Starts.ToLongDateString() ?? "Unknown") + "<br>"); body.Append("<b>Course End Date</b>: " + (request.DistanceEdClass.Ends.ToLongDateString() ?? "Unknown") + "<br>"); } else { body.Append("This registration is for course with database ID \"" + request.CourseID + "\", but a course with that ID was not found in the database. You may need to investigate."); } body.Append("</p>"); body.Append("<p><b>Comments:<br>" + request.Comments + "</p>"); body.Append("<p>This message comes from an unmonitored email account. Do not reply to this message.</p>"); body.Append("</body>"); body.Append("</html>"); try { // Send the mail message and log the results in the DB MailMessage msg = new MailMessage(); foreach (string dest in destinations) { msg.To.Add(dest); } msg.Body = body.ToString(); if (request.DistanceEdClass != null) { msg.Subject = "Distance Ed Request for " + request.StudentName + " for " + request.DistanceEdClass.Name; } else { msg.Subject = "Distance Ed Request for " + request.StudentName + " for class with database ID \"" + request.ID + "\""; } msg.From = new MailAddress(this.fromaddress, "Distance Ed Registration Form"); msg.ReplyToList.Add(new MailAddress(this.replyToAddress, "Distance Ed Registration Form")); msg.IsBodyHtml = true; smtpClient.Send(msg); successes.Add(request.ID); } catch (Exception ex) { // Log a failure throw new Exception("Error sending email for request ID " + request.ID, ex); } } } } return(successes); }
public void NewMessage(DistanceEdRequest request) { this._mailQueue.Enqueue(request); }
public IActionResult OnPostFormSubmit() { if (ModelState.IsValid) { regErrors.Clear(); string studentName = Request.Form["txtStudentName"].ToString(); string studentNumber = Request.Form["txtStudentNumber"].ToString(); string studentSchool = Request.Form["txtStudentSchool"].ToString(); string comments = Request.Form["txtNotes"].ToString(); string requestor = Request.Form["txtRequestor"].ToString(); string mentorName = Request.Form["txtMentor"].ToString() ?? string.Empty; int courseID = Parsers.ToInt(Request.Form["txtCourseID"].ToString() ?? string.Empty); // Find checked classes // The easy way to do this would be check all submitted form elements for anything that starts with "chkClass_" // The safe way to do this would be to load all valid classes, and compare to that list instead Dictionary <int, DistanceEdClass> availableClasses = _classService.GetAllAvailable(DateTime.Now).ToDictionary(x => x.ID); DistanceEdRequest newRequest = new DistanceEdRequest() { StudentName = studentName, StudentNumber = studentNumber, StudentBaseSchool = studentSchool, Comments = comments, CourseID = courseID, MentorTeacherName = mentorName, Requestor = requestor }; // Validate if (courseID > 0) { DistanceEdClass selectedClass = availableClasses[courseID] ?? null; if (selectedClass == null) { regErrors.Add("Course with ID \"" + courseID + "\" was not found."); } else { if (selectedClass.MentorTeacherRequired) { if (string.IsNullOrEmpty(mentorName)) { regErrors.Add("The class \"" + selectedClass.Name + "\" requires a mentor teacher, but no name was provided."); } } } } else { regErrors.Add("No course selected"); } if (string.IsNullOrEmpty(studentName)) { regErrors.Add("Student name is required"); } if (string.IsNullOrEmpty(studentNumber)) { regErrors.Add("Student number is required"); } if (string.IsNullOrEmpty(studentSchool)) { regErrors.Add("Student base school is required"); } if (string.IsNullOrEmpty(requestor)) { regErrors.Add("Requestor name is required"); } // Submit to DB if (regErrors.Count == 0) { try { _requestService.Add(newRequest); } catch (Exception ex) { regErrors.Add(ex.Message); } } if (regErrors.Count == 0) { return(RedirectToPage("Thanks")); } else { return(Page()); } } else { return(Page()); } }
public void Add(DistanceEdRequest NewRequest) { _repository.AddNewRequest(NewRequest); }
public void MarkAsHelpDeskNotified(DistanceEdRequest request) { MarkAsHelpDeskNotified(request.ID); }