/// <summary> /// Gets the email body. /// </summary> /// <param name="FileId">The file id.</param> /// <param name="EmailTemplId">The email templ id.</param> /// <param name="LoanAlertId">The loan alert id.</param> /// <param name="em">The em.</param> /// <returns></returns> private string GetEmailBody(int FileId, int EmailTemplId, int LoanAlertId, EmailManager.EmailMgr em) { var ereq = new EmailPreviewRequest { FileId = FileId, EmailTemplId = EmailTemplId, LoanAlertId = LoanAlertId }; try { EmailPreviewResponse epr = em.PreviewEmail(ereq); if (epr.resp.Successful) { string emailBody = string.Empty; if (epr.EmailHtmlContent != null && epr.EmailHtmlContent.Length > 0) { emailBody = Encoding.UTF8.GetString(epr.EmailHtmlContent); } return(emailBody); } } catch (Exception exception) { string err = MethodBase.GetCurrentMethod() + string.Format("Generate email body faild for FileId={0} EmailTemplId={1}. Exception: {2}", FileId, EmailTemplId, exception); int Event_id = 4025; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } return(string.Empty); }
public IHttpActionResult RenderPreview([FromUri] EmailPreviewRequest request) { var emailTemplate = _vendr.GetEmailTemplate(request.TemplateId); if (emailTemplate == null) { return(BadRequest($"Failed to find template {request.TemplateId}")); } var order = _vendr.GetOrder(request.OrderId); if (order == null) { return(BadRequest($"Failed to find order {request.OrderId}")); } var view = _emailTemplateEngine.RenderTemplateView(emailTemplate.TemplateView, order, request.Culture); if (string.IsNullOrWhiteSpace(view) == true) { return(NotFound()); } var response = new HttpResponseMessage { Content = new StringContent(view) }; return(ResponseMessage(response)); }
/// <summary> /// Acknowledges the alert. /// </summary> /// <param name="currentLoanAlertId">The current loan alert id.</param> /// <param name="userId">The user id.</param> /// <returns></returns> public bool AcknowledgeAlert(int currentLoanAlertId, int userId) { string err = ""; bool logErr = false; DataSet ds = null; try { EmailManager.EmailMgr em = EmailManager.EmailMgr.Instance; bool status = false; ds = m_da.AcknowledgeAlert(currentLoanAlertId, userId, out status); if (status == false) { return(false); } //if ((ds == null) || (ds.Tables.Count <= 0) || (ds.Tables[0].Rows.Count <= 0)) //{ // err = MethodBase.GetCurrentMethod() + " failed to Acknowledge Rule Alert, AlertId=" + currentLoanAlertId; // logErr = true; // return false; //} if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < 1; i++) { int FileId = Convert.ToInt32(ds.Tables[0].Rows[i]["FileId"]); int EmailTemplId = Convert.ToInt32(ds.Tables[0].Rows[i]["AlertEmailTemplId"]); int LoanAlertId = Convert.ToInt32(ds.Tables[0].Rows[i]["LoanAlertId"]); var ereq = new EmailPreviewRequest { FileId = FileId, EmailTemplId = EmailTemplId, LoanAlertId = LoanAlertId }; try { EmailPreviewResponse epr = em.PreviewEmail(ereq); if (!epr.resp.Successful) { err = MethodBase.GetCurrentMethod() + ", failed to get email body from Email Manager. \r\nreason:" + epr.resp.StatusInfo; int Event_id = 4032; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); return(false); } string emailBody = string.Empty; if (epr.EmailHtmlContent != null && epr.EmailHtmlContent.Length > 0) { emailBody = Encoding.UTF8.GetString(epr.EmailHtmlContent); } m_da.AcknowledgeAlertEmailQue(currentLoanAlertId, userId, emailBody, epr.EmailHtmlContent); return(true); } catch (Exception exception) { err = MethodBase.GetCurrentMethod() + "\r\n\r\nException: " + exception.Message + "\r\n\r\nStackTrace: " + exception.StackTrace; int Event_id = 4033; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); return(false); } } } return(true); } catch (Exception e) { err = MethodBase.GetCurrentMethod() + "\r\n\r\nException: " + e.Message + "\r\n\r\nStackTrace: " + e.StackTrace; int Event_id = 4035; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); return(false); } finally { if (logErr) { Trace.TraceError(err); int Event_id = 4037; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } if (ds != null) { ds.Clear(); ds.Dispose(); ds = null; } } }
public void ProcessLoanRulesOld() { string err = ""; bool logErr = false; DataSet ds = null; try { EmailManager.EmailMgr em = EmailManager.EmailMgr.Instance; ds = m_da.ProcessLoanRules(); if ((ds == null) || (ds.Tables.Count <= 0) || (ds.Tables[0].Rows.Count <= 0)) { err = MethodBase.GetCurrentMethod() + " no rules to process."; int Event_id = 4003; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Information, Event_id, Category); return; } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { int EmailId = Convert.ToInt32(ds.Tables[0].Rows[i]["EmailId"]); int FileId = Convert.ToInt32(ds.Tables[0].Rows[i]["FileId"]); int EmailTemplId = Convert.ToInt32(ds.Tables[0].Rows[i]["EmailTmplId"]); int LoanAlertId = Convert.ToInt32(ds.Tables[0].Rows[i]["LoanAlertId"]); int AlertEmailType = Convert.ToInt32(ds.Tables[0].Rows[i]["AlertEmailType"]); var ereq = new EmailPreviewRequest { FileId = FileId, EmailTemplId = EmailTemplId, LoanAlertId = LoanAlertId }; try { EmailPreviewResponse epr = em.PreviewEmail(ereq); if (epr.resp.Successful) { string emailBody = string.Empty; if (epr.EmailHtmlContent != null && epr.EmailHtmlContent.Length > 0) { emailBody = Encoding.UTF8.GetString(epr.EmailHtmlContent); } m_da.UpdateEmailBody(EmailId, LoanAlertId, AlertEmailType, emailBody, epr.EmailHtmlContent); } } catch (Exception exception) { err = MethodBase.GetCurrentMethod() + "\r\n\r\nException: " + exception.Message + "\r\n\r\nStackTrace: " + exception.StackTrace; int Event_id = 4005; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } } } catch (Exception e) { err = MethodBase.GetCurrentMethod() + "\r\n\r\nException: " + e.Message + "\r\n\r\nStackTrace: " + e.StackTrace; int Event_id = 4007; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); return; } finally { if (logErr) { Trace.TraceError(err); int Event_id = 4008; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } if (ds != null) { ds.Clear(); ds.Dispose(); ds = null; } } }
protected void Page_Load(object sender, EventArgs e) { #region 校验页面参数 string sErrorJs = "alert('Missing required query string.');window.close();"; #region UseEmailTemplate if (this.Request.QueryString["UseEmailTemplate"] == null) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Missing3", sErrorJs, true); return; } string sUseEmailTemplate = this.Request.QueryString["UseEmailTemplate"].ToString(); if (sUseEmailTemplate != "0" && sUseEmailTemplate != "1") { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Invalid3", "alert('Invalid query string.');window.close();", true); return; } bool bUseEmailTemplate = sUseEmailTemplate == "1" ? true : false; #endregion #region EmailTemplateID bool bIsValid = PageCommon.ValidateQueryString(this, "EmailTemplateID", QueryStringType.ID); if (bIsValid == false) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Missing1", sErrorJs, true); return; } string sEmailTemplateID = this.Request.QueryString["EmailTemplateID"].ToString(); #endregion #region text email body if (this.Request.QueryString["TextBody"] == null) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Missing6", sErrorJs, true); return; } string sTextBody = this.Request.QueryString["TextBody"].ToString(); #endregion #region LoanID or ProspectID or ProspectAlertID string sLoanID = string.Empty; string sProspectID = string.Empty; string sProspectAlertID = string.Empty; if (this.Request.QueryString["LoanID"] == null && this.Request.QueryString["ProspectID"] == null && this.Request.QueryString["ProspectAlertID"] == null) { this.ClientScript.RegisterStartupScript(this.GetType(), "_Missing11", sErrorJs, true); return; } if (this.Request.QueryString["LoanID"] != null) { #region LoanID bIsValid = PageCommon.ValidateQueryString(this, "LoanID", QueryStringType.ID); if (bIsValid == false) { this.ClientScript.RegisterStartupScript(this.GetType(), "_Missing12", sErrorJs, true); return; } sLoanID = this.Request.QueryString["LoanID"].ToString(); #endregion } else if (this.Request.QueryString["ProspectID"] != null) { #region ProspectID bIsValid = PageCommon.ValidateQueryString(this, "ProspectID", QueryStringType.ID); if (bIsValid == false) { this.ClientScript.RegisterStartupScript(this.GetType(), "_Missing13", sErrorJs, true); return; } sProspectID = this.Request.QueryString["ProspectID"].ToString(); #endregion } else if (this.Request.QueryString["ProspectAlertID"] != null) { #region ProspectAlertID bIsValid = PageCommon.ValidateQueryString(this, "ProspectAlertID", QueryStringType.ID); if (bIsValid == false) { this.ClientScript.RegisterStartupScript(this.GetType(), "_Missing14", sErrorJs, true); return; } sProspectAlertID = this.Request.QueryString["ProspectAlertID"].ToString(); #endregion } #endregion #region Append My Picture and Signature if (this.Request.QueryString["AppendMyPic"] == null) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Missing4", sErrorJs, true); return; } string sAppendMyPic = this.Request.QueryString["AppendMyPic"].ToString(); if (sAppendMyPic != "0" && sAppendMyPic != "1") { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Invalid4", "alert('Invalid query string.');window.close();", true); return; } bool bAppendMyPic = sAppendMyPic == "1" ? true : false; #endregion #endregion #region 生成email body // workflow api string sHtmlBody = string.Empty; try { ServiceManager sm = new ServiceManager(); using (LP2ServiceClient service = sm.StartServiceClient()) { EmailPreviewRequest req = new EmailPreviewRequest(); if (bUseEmailTemplate == true) { req.EmailTemplId = Convert.ToInt32(sEmailTemplateID); req.EmailBody = null; req.AppendPictureSignature = false; } else { req.EmailTemplId = 0; string sTextBody_Decode = Encrypter.Base64Decode(sTextBody); req.EmailBody = Encoding.UTF8.GetBytes(sTextBody_Decode); req.AppendPictureSignature = bAppendMyPic; } if (this.Request.QueryString["LoanID"] != null) { req.FileId = Convert.ToInt32(sLoanID); } else if (this.Request.QueryString["ProspectID"] != null) { req.ProspectId = Convert.ToInt32(sProspectID); } else if (this.Request.QueryString["ProspectAlertID"] != null) { req.PropsectTaskId = Convert.ToInt32(sProspectAlertID); } req.hdr = new ReqHdr(); req.UserId = this.CurrUser.iUserID; EmailPreviewResponse response = service.PreviewEmail(req); if (response.resp.Successful == false) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_FailedGetHtml", "alert('Failed to preview email: " + response.resp.StatusInfo + "');window.close();", true); return; } sHtmlBody = Encoding.UTF8.GetString(response.EmailHtmlContent); } } catch (System.ServiceModel.EndpointNotFoundException ee) { PageCommon.AlertMsg(this, "Failed to preview email, Email Manager is not running, error: " + ee.ToString()); } #endregion this.ltEmailBody.Text = sHtmlBody; }