示例#1
0
        private async Task <Response> SendOPMPublishResultEmail(EmailDetails emailDetails)
        {
            var response    = new Response();
            var emailEntity = new EmailEntity();

            if (emailDetails.RequestIds == null || !emailDetails.RequestIds.Any())
            {
                return(response);
            }
            var requestDetails = await _requestRepository.GetRequestDetailsForEmailAsync(emailDetails.RequestIds);

            foreach (var request in requestDetails)
            {
                emailEntity.Subject = "Yorbit: Assignment result published";
                emailEntity.Body    = ReadEmailTemplate("OPMPublishResult.html");
                emailEntity.Body    = emailEntity.Body.Replace("{LearnerName}", request.LearnerName);
                emailEntity.Body    = emailEntity.Body.Replace("{CourseName}", request.CourseName);
                emailEntity.Body    = emailEntity.Body.Replace("{Result}", requestResultCodes.GetStatusName(request.ResultId));
                emailEntity.Body    = emailEntity.Body.Replace("{Score}", request.Score == null ? "-": request.Score.ToString());
                emailEntity.Body    = emailEntity.Body.Replace("{Comments}", string.IsNullOrEmpty(request.Comments) ? "-" : request.Comments.Trim());
                emailEntity.Body    = emailEntity.Body.Replace("{ScoreCardFile}",
                                                               string.IsNullOrEmpty(request.ScoreCardFile)
                    ? "-"
                    : "Click <a href=" + await _blobHelper.GetBlobUriAsync("assignments", request.ScoreCardFile) + ">&nbsp;<span><b>here</b></span></a>");
                emailEntity.ToRecipients = new List <string> {
                    request.LearnerEmail
                };
                emailEntity.CCRecipients = new List <string> {
                    _learningOPMEmail
                };
                await _emailHelper.SendMail(emailEntity);
            }
            return(response);
        }
示例#2
0
        private async Task <Response> SendEvaluatorReminderEmail(EmailDetails emailDetails)
        {
            var response    = new Response();
            var emailEntity = new EmailEntity();

            if (emailDetails.RequestIds == null || !emailDetails.RequestIds.Any())
            {
                return(response);
            }
            var requestDetails = (await _requestRepository.GetRequestDetailsForEmailAsync(emailDetails.RequestIds));

            foreach (var requestDetail in requestDetails)
            {
                emailEntity.Subject      = "Yorbit: Evaluation reminder";
                emailEntity.Body         = ReadEmailTemplate("EvaluatorReminder.html");
                emailEntity.Body         = emailEntity.Body.Replace("{EvaluatorName}", requestDetail.EvaluatorName);
                emailEntity.Body         = emailEntity.Body.Replace("{CourseName}", requestDetail.CourseName);
                emailEntity.Body         = emailEntity.Body.Replace("{YorbitCourseId}", requestDetail.YorbitCourseId);
                emailEntity.ToRecipients = new List <string> {
                    requestDetail.EvaluatorEmail
                };
                await _emailHelper.SendMail(emailEntity);
            }
            return(response);
        }
示例#3
0
        private async Task <Response> SendEvaluatorErrorFileUploadEmail(EmailDetails emailDetails)
        {
            var response    = new Response();
            var emailEntity = new EmailEntity();

            if (emailDetails.RequestIds == null || !emailDetails.RequestIds.Any())
            {
                return(response);
            }
            var requestDetails = (await _requestRepository.GetRequestDetailsForEmailAsync(emailDetails.RequestIds))?.FirstOrDefault();

            emailEntity.Subject      = "Yorbit: Error found in assignment";
            emailEntity.Body         = ReadEmailTemplate("EvaluatorErrorFileUpload.html");
            emailEntity.Body         = emailEntity.Body.Replace("{LearnerName}", requestDetails.LearnerName);
            emailEntity.Body         = emailEntity.Body.Replace("{CourseName}", requestDetails.CourseName);
            emailEntity.Body         = emailEntity.Body.Replace("{Comments}", string.IsNullOrEmpty(requestDetails.Comments) ? "-" : requestDetails.Comments.Trim());
            emailEntity.Body         = emailEntity.Body.Replace("{ErrorFile}", string.IsNullOrEmpty(requestDetails.ErrorFile) ? "-" : await _blobHelper.GetBlobUriAsync("assignments", requestDetails.ErrorFile));
            emailEntity.ToRecipients = new List <string> {
                requestDetails.LearnerEmail
            };
            emailEntity.CCRecipients = new List <string> {
                _learningOPMEmail
            };
            await _emailHelper.SendMail(emailEntity);

            return(response);
        }
示例#4
0
        private async Task <Response> SendLearnerReminderEmail(EmailDetails emailDetails)
        {
            var response    = new Response();
            var emailEntity = new EmailEntity();

            if (emailDetails.RequestIds == null || !emailDetails.RequestIds.Any())
            {
                return(response);
            }
            var requestDetails = (await _requestRepository.GetRequestDetailsForEmailAsync(emailDetails.RequestIds));

            foreach (var requestDetail in requestDetails)
            {
                emailEntity.Subject      = "Yorbit: Assignment submission reminder";
                emailEntity.Body         = ReadEmailTemplate("LearnerReminder.html");
                emailEntity.Body         = emailEntity.Body.Replace("{LearnerName}", requestDetail.LearnerName);
                emailEntity.Body         = emailEntity.Body.Replace("{CourseName}", requestDetail.CourseName);
                emailEntity.Body         = emailEntity.Body.Replace("{AssignmentDueDate}", requestDetail.AssignmentDueDate.ToString("dd-MM-yyyy"));
                emailEntity.ToRecipients = new List <string> {
                    requestDetail.LearnerEmail
                };
                await _emailHelper.SendMail(emailEntity);
            }
            return(response);
        }
示例#5
0
        /// <summary>
        /// Sends mail using SMTP
        /// </summary>
        /// <param name="emailEntity"></param>
        /// <returns></returns>
        public async Task <Response> SendMail(EmailEntity emailEntity)
        {
            var response = new Response();

            try
            {
                if (emailEntity.ToRecipients == null || !emailEntity.ToRecipients.Any())
                {
                    response.Message = "No recipents found.";
                    return(response);
                }

                MailMessage message = new MailMessage();
                foreach (var email in emailEntity.ToRecipients)
                {
                    if (!string.IsNullOrEmpty(email))
                    {
                        message.To.Add(email);
                    }
                }

                message.From    = new MailAddress(smtpUserName, "Yorbit Notification");
                message.Subject = emailEntity.Subject;
                message.Body    = emailEntity.Body;
                if (emailEntity.CCRecipients != null)
                {
                    foreach (var email in emailEntity.CCRecipients)
                    {
                        if (!string.IsNullOrEmpty(email))
                        {
                            message.CC.Add(email);
                        }
                    }
                }
                message.IsBodyHtml = true;

                using (var client = new SmtpClient())
                {
                    client.UseDefaultCredentials = false;
                    client.Credentials           = new System.Net.NetworkCredential(smtpUserName, smtpPassword);
                    client.Port           = smtpPort;
                    client.Host           = smtpHost;
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.EnableSsl      = true;

                    await client.SendMailAsync(message);
                }
                response.IsSuccess = true;
            }
            catch (Exception ex)
            {
                Logging.Logger.LogException(ex);
            }
            return(response);
        }
示例#6
0
        private async Task <Response> SendEvaluatorScoreUploadEmail(EmailDetails emailDetails)
        {
            var response    = new Response();
            var emailEntity = new EmailEntity();

            if (emailDetails.RequestIds == null || !emailDetails.RequestIds.Any())
            {
                return(response);
            }
            var requestDetails = (await _requestRepository.GetRequestDetailsForEmailAsync(emailDetails.RequestIds))?.FirstOrDefault();

            emailEntity.Subject      = "Yorbit: Assignment score submitted";
            emailEntity.Body         = ReadEmailTemplate("EvaluatorCompleteEvaluation.html");
            emailEntity.Body         = emailEntity.Body.Replace("{YorbitRequestId}", requestDetails.YorbitRequestId);
            emailEntity.Body         = emailEntity.Body.Replace("{YorbitCourseId}", requestDetails.YorbitCourseId);
            emailEntity.Body         = emailEntity.Body.Replace("{CourseName}", requestDetails.CourseName);
            emailEntity.ToRecipients = new List <string> {
                _learningOPMEmail
            };
            await _emailHelper.SendMail(emailEntity);

            return(response);
        }
示例#7
0
        private async Task <Response> SendLearnerAssignmentUploadEmail(EmailDetails emailDetails)
        {
            var response    = new Response();
            var emailEntity = new EmailEntity();

            if (emailDetails.RequestIds == null || !emailDetails.RequestIds.Any())
            {
                return(response);
            }
            var requestDetails = (await _requestRepository.GetRequestDetailsForEmailAsync(emailDetails.RequestIds))?.FirstOrDefault();

            emailEntity.Subject = string.Format("Yorbit: {0} Assignment submitted", requestDetails.CourseName);

            emailEntity.Body         = ReadEmailTemplate("LearnerAssignmentUpload.html");
            emailEntity.Body         = emailEntity.Body.Replace("{LearnerName}", requestDetails.LearnerName);
            emailEntity.Body         = emailEntity.Body.Replace("{CourseName}", requestDetails.CourseName);
            emailEntity.ToRecipients = new List <string> {
                requestDetails.LearnerEmail
            };
            response = await _emailHelper.SendMail(emailEntity);

            emailEntity.Body         = ReadEmailTemplate("EvaluatorAssignmentUpload.html");
            emailEntity.Body         = emailEntity.Body.Replace("{EvaluatorName}", requestDetails.EvaluatorName);
            emailEntity.Body         = emailEntity.Body.Replace("{YorbitRequestId}", requestDetails.YorbitRequestId);
            emailEntity.Body         = emailEntity.Body.Replace(" {YorbitCourseId}", requestDetails.YorbitCourseId);
            emailEntity.Body         = emailEntity.Body.Replace("{CourseName}", requestDetails.CourseName);
            emailEntity.Body         = emailEntity.Body.Replace("{AssignmentFile}", string.IsNullOrEmpty(requestDetails.AssignmentFile) ? "-" : await _blobHelper.GetBlobUriAsync("assignments", requestDetails.AssignmentFile));
            emailEntity.ToRecipients = new List <string> {
                requestDetails.EvaluatorEmail
            };
            emailEntity.CCRecipients = new List <string> {
                _learningOPMEmail
            };
            response = await _emailHelper.SendMail(emailEntity);

            return(response);
        }