Esempio n. 1
0
        public async Task SendRepairStatusNotifyEmailAsync(int repairId, CustomerDecisionLink links)
        {
            var repair = await GetRepairByIdAsync(repairId);

            // Send Email and wait for customer decision affter add RepairItem to Repair
            if (repair.StatusId == 2)
            {
                var subject = await _unitOfWork.EmailSubject.GetEmailSubjectByIdAsync(1);

                var emailTemplate = await _unitOfWork.EmailTemplate.GetEmailTemplateByIdAsync(2);

                await _emailSender.SendRepairStatusChangeEmailAsync(emailTemplate.TemplateName, subject.Subject, repair, links);
            }
            // Send Email when customer accept Repair
            if (repair.StatusId == 3)
            {
                var subject = await _unitOfWork.EmailSubject.GetEmailSubjectByIdAsync(2);

                var emailTemplate = await _unitOfWork.EmailTemplate.GetEmailTemplateByIdAsync(1);

                await _emailSender.SendRepairStatusChangeEmailAsync(emailTemplate.TemplateName, subject.Subject, repair, links);
            }
            // Send Email when custmer reject Repair or when repair is done
            if (repair.StatusId == 4 ||
                repair.StatusId == 5 ||
                repair.StatusId == 6 ||
                repair.StatusId == 7)
            {
                var subject = await _unitOfWork.EmailSubject.GetEmailSubjectByIdAsync(4);

                var emailTemplate = await _unitOfWork.EmailTemplate.GetEmailTemplateByIdAsync(1);

                await _emailSender.SendRepairStatusChangeEmailAsync(emailTemplate.TemplateName, subject.Subject, repair, links);
            }
        }
Esempio n. 2
0
        public async Task SendRepairStatusChangeEmailAsync(string templateName, string subject, RepairDetailsResponse repair, CustomerDecisionLink links)
        {
            var email = repair.CustomerDetails.Email;

            // Use diferent messageBody Builder if links are empty.
            if (links != null)
            {
                string messageBody = BuildCustomerDecisionMessageBody(templateName, repair, links);
                await SendEmailAsync(email, subject, messageBody);
            }
            else
            {
                string messageBody = BuildStatusChangeMessageBody(templateName, repair, links);
                await SendEmailAsync(email, subject, messageBody);
            }
        }
Esempio n. 3
0
        public string BuildStatusChangeMessageBody(string templateName, RepairDetailsResponse repair, CustomerDecisionLink links)
        {
            var email       = repair.CustomerDetails.Email;
            var builder     = new BodyBuilder();
            var _pathToFile = GetTemplateFilePathAsync(templateName);

            using (StreamReader SourceReader = System.IO.File.OpenText(_pathToFile))
            {
                builder.HtmlBody = SourceReader.ReadToEnd();
            }

            //{0} : Customer.Name
            //{1} : RepairStatus.name

            string messageBody = string.Format(builder.HtmlBody,
                                               repair.CustomerDetails.Name,
                                               repair.StatusName
                                               );

            return(messageBody);
        }