Example #1
0
        public async Task <bool> Execute(int auditId, string workflowId)
        {
            Domain.Audit.Audit audit          = _auditRepository.Get(auditId);
            List <string>      EmailsToNotify = new List <string>();

            EmailsToNotify.AddRange(_sectorPlantRepository.GetSectorPlantReferredEmail(audit.PlantID, audit.SectorID));

            //Internal Auditr
            if (audit.Auditor != null)
            {
                EmailsToNotify.Add(audit.Auditor.Email);
            }
            //LEFT EMAIL OF SGC RESPONSIBLE

            if (ALLOWED_CODES.Contains(audit.AuditState.Code))
            {
                try
                {
                    string standards = "";
                    foreach (AuditStandard normas in audit.AuditStandards)
                    {
                        standards += $"<tr><td>{normas.Standard.Name}</td></tr>";
                    }
                    var emailSubject = $"HoshinCloud - Auditoría eliminada - {audit.AuditTypeName}";

                    string content = $"<p><b>Id de Auditoría</b>: {audit.AuditID}</p>";
                    content += $"<p><b>Tipo de Auditoría</b>: {audit.AuditTypeName}</p>";
                    content += $"<p><b>Normas</b>: <table>{standards}</table></p>";
                    content += $"<p><b>Sector</b>: {audit.SectorPlantName}</p>";
                    content += $"<p><b>Auditor Asignado</b>: {audit.AuditorName}</p>";
                    content += $"<p><b>Fecha de Inicio</b>: {audit.AuditInitDate.ToString("dd/MM/yyyy")}</p>";

                    string bodyHtml = $"<html>" +
                                      $"<body>" +
                                      $"<p>Estimado usuario: </p>" +
                                      $"<p>Ha sido reprogramada una auditoría.</p>" +
                                      $"{content}" +
                                      $"<p></p>" +
                                      $"<p>Saludos cordiales.</p>" +
                                      $"</body>" +
                                      $"</html>";

                    await _workflowCore.DeleteWorkflowInstance(workflowId);

                    _auditRepository.Delete(auditId);
                    Task.Run(() => _emailSender.SendEmailAsync(EmailsToNotify.ToArray(), new List <string>().ToArray(), new List <string>().ToArray(), emailSubject, bodyHtml, true, System.Net.Mail.MailPriority.High));
                    return(true);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                throw new InvalidAuditStateException("STATE: " + audit.AuditState.Code);
            }
        }