/// <summary> /// Check how many lectures a student missed and send him a message if there are more than 3 passes /// </summary> /// <param name="lectureId">Last lecture id at course</param> /// <param name="messageSenderService"></param> /// <returns>Task</returns> public async Task CheckNumberOfStudentsLecturesMissed(int lectureId, IMessageSenderService messageSenderService) { if (messageSenderService == null) { throw new EntityNullException(nameof(messageSenderService)); } var lecture = await _unitOfWork.Lectures.GetLectureWithStudentsById(lectureId); if (lecture == null) { throw new EntityNotFoundException($"Lecture with {lectureId} id doesn't exist in database"); } var lecturer = await GetLecturerOfLecture(lectureId); foreach (var student in lecture.StudentLectures) { // There is no need to send a message to the student if he is in class if (student.Attendance == false) { var countOfMissedLectures = await GetNumberOfStudentLecturesMissed(student.StudentId, lecture.CourseId); if (countOfMissedLectures > 3) { _logger.LogInformation(DateTime.Now + $"\nStudent with {student.StudentId} id has missed more than 3 lecture, sending mail to student and lecturer email"); messageSenderService.Send("You have missed more than 3 lectures", student.Student.Email); messageSenderService.Send($"Student {student.Student.Name} has missed more than 3 lectures", lecturer.Email); } } } }
/// <summary> /// Send a reset email for the user password. /// </summary> /// <param name="siteAddress">Site address</param> /// <param name="userNameOrEmail">User name or Email address</param> /// <returns>Token generated</returns> public string SendResetPasswordEmail(int siteAddressId, string userName) { User u = FindUser(siteAddressId, userName); string token = CreateResetPasswordToken(siteAddressId, userName); IMessage m = new Message { Body = string.Format("Your token is: {0}.", token), Subject = "Subject" }; _messageSenderService.Send(m, u.ToUserInfo()); return(token); }
private async void Job() { try { var messageJob = _messageJobFactory.GetStreamsMessageJob(); var messages = await messageJob.Invoke(); if (messages == null) { return; } foreach (var message in messages) { if (string.IsNullOrWhiteSpace(message)) { continue; } _logger.LogInformation($"LiveStreamsMessage: {message}"); await _messageSender.Send(message); } } catch (Exception ex) { _logger.LogCritical($"Unhandled Exception; {ex}"); } }
/// <summary> /// Check the student average grade for the course and send message, if it lower than four /// </summary> /// <param name="studentId">Student Id</param> /// <param name="courseId">Course Id</param> /// <param name="messageSenderService">Message sender</param> /// <returns>Task</returns> public async Task CheckAverageMark(int studentId, int courseId, IMessageSenderService messageSenderService) { if (messageSenderService == null) { throw new EntityNullException(nameof(messageSenderService)); } var student = await _unitOfWork.Students.GetByIdAsync(studentId); if (student == null) { throw new EntityNotFoundException($"Student with {studentId} id doesn't exist in database"); } var course = await _unitOfWork.Courses.GetByIdAsync(courseId); if (student == null) { throw new EntityNotFoundException($"Course with {courseId} id doesn't exist in database"); } var averageMark = await GetAverageMark(studentId, courseId); if (averageMark < 4) { _logger.LogInformation(DateTime.Now + $"\nStudent's mark with {studentId} id is lower than 4 at course {course.Name}, sending message to student"); messageSenderService.Send($"Your {course.Name}'s mark is lower than 4", student.Mobile); } }
private void SendConfirmationToken(User u) { var data = new ActivateData { ConfirmUrl = string.Format(@"/Validation/ConfirmEmail/default.aspx?token={0}", HttpUtility.UrlEncode(CreateUserConfirmationToken(u))), FullName = string.Format("{0} {1}", u.FirstName, u.LastName) }; var template = new FileMessageTemplate { Discriminator = "activate", Owner = u.ToUserInfo() }; template.SystemData = data; _messageSenderService.Send(template, u.ToUserInfo()); }
private async void Job() { try { var action = _messageJobFactory.GetJob(); var message = await action.Invoke(); if (message == null) { return; } _logger.LogInformation($"Message to send: {message}"); await _messageSender.Send(message); } catch (Exception ex) { _logger.LogCritical($"Unhandled Exception; {ex}"); } }