public static void SendFeedbackNotifications(HttpServerUtility server, string feedbackUID, bool toGuest) { SQLDatabase sql = new SQLDatabase(); sql.CommandTimeout = 120; SQLParamList sqlParams = new SQLParamList().Add("GUID", feedbackUID); DataSet ds = sql.ExecStoredProcedureDataSet("spFeedback_GetItem", sqlParams); string GCCPortalUrl = ConfigurationManager.AppSettings["GCCPortalURL"].ToString(); if (!sql.HasError && ds.Tables[0].Rows.Count > 0) { DataRow fbkDR = ds.Tables[0].Rows[0]; GCCPropertyShortCode property = (GCCPropertyShortCode)fbkDR["PropertyID"].ToString().StringToInt(); SurveyType surveyType = (SurveyType)fbkDR["SurveyTypeID"].ToString().StringToInt(); NotificationReason reason = (NotificationReason)fbkDR["ReasonID"].ToString().StringToInt(); string emailAddress = String.Empty; if (toGuest) { if (ds.Tables[2].Columns.Contains("ContactEmail")) { emailAddress = ds.Tables[2].Rows[0]["ContactEmail"].ToString(); } if (String.IsNullOrWhiteSpace(emailAddress) && ds.Tables[2].Columns.Contains("Email")) { emailAddress = ds.Tables[2].Rows[0]["Email"].ToString(); } if (String.IsNullOrWhiteSpace(emailAddress) && ds.Tables[2].Columns.Contains("Q5Email")) { emailAddress = ds.Tables[2].Rows[0]["Q5Email"].ToString(); } if (String.IsNullOrWhiteSpace(emailAddress)) { //Nothing to do return; } } string template = String.Empty; string title = String.Empty; object replacementModel; title = PropertyTools.GetCasinoName((int)property) + " - Feedback Reply Notification"; if (toGuest) { template = "GuestFeedbackNotification"; replacementModel = new { CasinoName = PropertyTools.GetCasinoName((int)property), Link = GCCPortalUrl + "F/" + feedbackUID, Attachments = new SurveyTools.SurveyAttachmentDetails[] { new SurveyTools.SurveyAttachmentDetails() { Path = "~/Images/headers/" + PropertyTools.GetCasinoHeaderImage(property), ContentID = "HeaderImage" } } }; } else { template = "StaffFeedbackNotification"; replacementModel = new { Date = DateTime.Now.ToString("yyyy-MM-dd"), CasinoName = PropertyTools.GetCasinoName((int)property), Link = GCCPortalUrl + "Admin/Feedback/" + feedbackUID }; } MailMessage msg = null; try { string path = server.MapPath("~/Content/notifications/"); msg = EmailManager.CreateEmailFromTemplate( Path.Combine(path, template + ".htm"), Path.Combine(path, template + ".txt"), replacementModel); PropertyInfo attachmentProp = replacementModel.GetType().GetProperty("Attachments"); if (attachmentProp != null) { SurveyAttachmentDetails[] attachments = attachmentProp.GetValue(replacementModel) as SurveyAttachmentDetails[]; foreach (SurveyAttachmentDetails att in attachments) { LinkedResource lr = new LinkedResource(server.MapPath(att.Path)); lr.ContentId = att.ContentID; msg.AlternateViews[0].LinkedResources.Add(lr); } } msg.From = new MailAddress("*****@*****.**"); msg.Subject = title; bool hasAddress = false; if (!String.IsNullOrWhiteSpace(emailAddress)) { msg.To.Add(emailAddress); hasAddress = true; } else { sql = new SQLDatabase(); DataTable dt = sql.QueryDataTable(@" SELECT [SendType], u.[FirstName], u.[LastName], u.[Email] FROM [tblNotificationUsers] ne INNER JOIN [tblNotificationPropertySurveyReason] psr ON ne.[PropertySurveyReasonID] = psr.[PropertySurveyReasonID] INNER JOIN [tblCOM_Users] u ON ne.UserID = u.UserID WHERE psr.PropertyID = @PropertyID AND psr.SurveyTypeID = @SurveyID AND psr.ReasonID = @ReasonID ;", new SQLParamList() .Add("@PropertyID", (int)property) .Add("@SurveyID", (int)surveyType) .Add("@ReasonID", (int)reason) ); if (!sql.HasError && dt.Rows.Count > 0) { StringBuilder addrs = new StringBuilder(); foreach (DataRow dr in dt.Rows) { switch (dr["SendType"].ToString()) { case "1": msg.To.Add(dr["Email"].ToString()); addrs.Append(dr["FirstName"].ToString() + " " + dr["LastName"].ToString() + " <" + dr["Email"].ToString() + ">" + "\n"); hasAddress = true; break; case "2": msg.CC.Add(dr["Email"].ToString()); //Colin requested that CC addresses not show on the call Aug 10,2015 //addrs.Append( dr["FirstName"].ToString() + " " + dr["LastName"].ToString() + " <" + dr["Email"].ToString() + ">" + "\n" ); hasAddress = true; break; case "3": msg.Bcc.Add(dr["Email"].ToString()); hasAddress = true; break; } } using (StreamReader sr = new StreamReader(msg.AlternateViews[0].ContentStream)) { msg.AlternateViews[0] = AlternateView.CreateAlternateViewFromString(sr.ReadToEnd().Replace("{Recipients}", server.HtmlEncode(addrs.ToString()).Replace("\n", "<br />")), null, MediaTypeNames.Text.Html); } using (StreamReader sr = new StreamReader(msg.AlternateViews[1].ContentStream)) { msg.AlternateViews[1] = AlternateView.CreateAlternateViewFromString(sr.ReadToEnd().Replace("{Recipients}", addrs.ToString()), null, MediaTypeNames.Text.Plain); } //using (StreamReader sr = new StreamReader(msg.AlternateViews[0].ContentStream)) //{ // msg.AlternateViews[0] = AlternateView.CreateAlternateViewFromString(sr.ReadToEnd().Replace("{Recipients}", server.HtmlEncode(addrs.ToString()).Replace("\n", "<br />")).Replace("{Business}", server.HtmlEncode(reason.ToString()).Replace("\n", "<br />")).Replace("{Comments}", server.HtmlEncode(Comments.ToString()).Replace("\n", "<br />")), null, MediaTypeNames.Text.Html); //} //using (StreamReader sr = new StreamReader(msg.AlternateViews[1].ContentStream)) //{ // msg.AlternateViews[1] = AlternateView.CreateAlternateViewFromString(sr.ReadToEnd().Replace("{Recipients}", addrs.ToString()).Replace("{Business}", reason.ToString()).Replace("{Comments}", Comments.ToString()), null, MediaTypeNames.Text.Plain); //} } } if (hasAddress) { msg.Send(); } } catch (Exception ex) { } finally { if (msg != null) { msg.Dispose(); msg = null; } } } }
//20170116 adding commentws for email notification //public static void SendNotifications<T>( HttpServerUtility server, GCCPropertyShortCode property, SurveyType surveyType, NotificationReason reason, T replacementModel, string emailAddress, string subjectPrefix ) public static void SendNotifications <T>(HttpServerUtility server, GCCPropertyShortCode property, SurveyType surveyType, NotificationReason reason, string Comments, T replacementModel, string emailAddress, string subjectPrefix, int operationsArea) where T : class { string template = String.Empty; string title = String.Empty; string propertyName = PropertyTools.GetCasinoName((int)property); if (property == GCCPropertyShortCode.GAG) { PropertyInfo nameProp = replacementModel.GetType().GetProperty("CasinoName"); if (nameProp != null) { string name = nameProp.GetValue(replacementModel) as string; if (!String.IsNullOrWhiteSpace(name)) { propertyName = name; } } } switch (surveyType) { case SurveyType.GEI: if (reason == NotificationReason.ThankYou) { title = "Thank You For Your Feedback"; template = "GEIThankYou"; } else { template = "GEITemplate"; title = String.Format("{0}GEI Feedback Notification for {1} - {2}", subjectPrefix, propertyName, DateTime.Now.ToString("MMMM dd, yyyy")); } break; case SurveyType.GEIProblemResolution: if (reason == NotificationReason.ThankYou) { title = "Thank You For Your Feedback"; template = "GEIThankYou"; } else { if (replacementModel.ToString().Contains("FeedbackCategory")) { template = "GEIFeedbackCategoryTemplate"; title = String.Format("{0}GEI Feedback Category Notification for {1} - {2}", subjectPrefix, propertyName, DateTime.Now.ToString("MMMM dd, yyyy")); } else { template = "GEITemplate"; title = String.Format("{0}GEI Problem Resolution Feedback Notification for {1} - {2}", subjectPrefix, propertyName, DateTime.Now.ToString("MMMM dd, yyyy")); } } break; case SurveyType.Hotel: if (reason == NotificationReason.ThankYou) { title = "Thank You For Your Feedback"; template = "HotelThankYou"; } else { template = "HotelTemplate"; title = String.Format("{0}Hotel Survey Notification - {1}", subjectPrefix, DateTime.Now.ToString("MMMM dd, yyyy")); } break; case SurveyType.Feedback: if (reason == NotificationReason.ThankYou) { title = "Thank You For Your Feedback"; template = "FeedbackThankYou"; } else if (reason == NotificationReason.Tier3Alert) { title = String.Format("{0}Tier 3 Alert for {1} - {2}", subjectPrefix, propertyName, DateTime.Now.ToString("MMMM dd, yyyy")); template = "Tier3Alert"; } else { template = "FeedbackTemplate"; title = String.Format("{0}Feedback Follow-up Notification for {1} - {2}", subjectPrefix, propertyName, DateTime.Now.ToString("MMMM dd, yyyy")); } break; case SurveyType.Donation: template = "DonationTemplate"; title = String.Format("{0}Sponsorship / Donation Request Notification for {1} - {2}", subjectPrefix, propertyName, DateTime.Now.ToString("MMMM dd, yyyy")); break; } if (template.Equals(String.Empty)) { return; } MailMessage msg = null; try { string path = server.MapPath("~/Content/notifications/"); msg = EmailManager.CreateEmailFromTemplate( Path.Combine(path, template + ".htm"), Path.Combine(path, template + ".txt"), replacementModel); PropertyInfo attachmentProp = replacementModel.GetType().GetProperty("Attachments"); if (attachmentProp != null) { SurveyAttachmentDetails[] attachments = attachmentProp.GetValue(replacementModel) as SurveyAttachmentDetails[]; foreach (SurveyAttachmentDetails att in attachments) { LinkedResource lr = new LinkedResource(server.MapPath(att.Path)); lr.ContentId = att.ContentID; msg.AlternateViews[0].LinkedResources.Add(lr); } } msg.From = new MailAddress("*****@*****.**"); msg.Subject = title; //Add high priority flag to tier 3 alerts if (reason == NotificationReason.Tier3Alert) { msg.Priority = MailPriority.High; } bool hasAddress = false; if (!String.IsNullOrEmpty(emailAddress)) { msg.To.Add(emailAddress); hasAddress = true; } else { SQLDatabase sql = new SQLDatabase(); sql.CommandTimeout = 120; DataTable dt = sql.QueryDataTable(@" SELECT [SendType], u.[FirstName], u.[LastName], u.[Email] FROM [tblNotificationUsers] ne INNER JOIN [tblNotificationPropertySurveyReason] psr ON ne.[PropertySurveyReasonID] = psr.[PropertySurveyReasonID] INNER JOIN [tblCOM_Users] u ON ne.UserID = u.UserID WHERE psr.PropertyID = @PropertyID AND psr.SurveyTypeID = @SurveyID AND psr.ReasonID = @ReasonID ;", //AND ( ( @OperationsAreaID < 0 AND psr.OperationsAreaID IS NULL ) OR psr.OperationsAreaID = @OperationsAreaID ) new SQLParamList() .Add("@PropertyID", (int)property) .Add("@SurveyID", (int)surveyType) .Add("@ReasonID", (int)reason) .Add("@OperationsAreaID", operationsArea) ); if (!sql.HasError && dt.Rows.Count > 0) { StringBuilder addrs = new StringBuilder(); foreach (DataRow dr in dt.Rows) { switch (dr["SendType"].ToString()) { case "1": msg.To.Add(dr["Email"].ToString()); //201701 Testing Email error //msg.Bcc.Add("*****@*****.**"); addrs.Append(dr["FirstName"].ToString() + " " + dr["LastName"].ToString() + " <" + dr["Email"].ToString() + ">" + "\n"); hasAddress = true; break; case "2": msg.CC.Add(dr["Email"].ToString()); //201701 Testing Email error //msg.Bcc.Add("*****@*****.**"); //Colin requested that CC addresses not show on the call Aug 10,2015 //addrs.Append( dr["FirstName"].ToString() + " " + dr["LastName"].ToString() + " <" + dr["Email"].ToString() + ">" + "\n" ); hasAddress = true; break; case "3": msg.Bcc.Add(dr["Email"].ToString()); //201701 Testing Email error // msg.Bcc.Add("*****@*****.**"); hasAddress = true; break; } } using (StreamReader sr = new StreamReader(msg.AlternateViews[0].ContentStream)) { msg.AlternateViews[0] = AlternateView.CreateAlternateViewFromString(sr.ReadToEnd().Replace("{Recipients}", server.HtmlEncode(addrs.ToString()).Replace("\n", "<br />")).Replace("{Business}", server.HtmlEncode(reason.ToString()).Replace("\n", "<br />")).Replace("{Comments}", server.HtmlEncode(Comments.ToString()).Replace("\n", "<br />")), null, MediaTypeNames.Text.Html); } using (StreamReader sr = new StreamReader(msg.AlternateViews[1].ContentStream)) { msg.AlternateViews[1] = AlternateView.CreateAlternateViewFromString(sr.ReadToEnd().Replace("{Recipients}", addrs.ToString()).Replace("{Business}", reason.ToString()).Replace("{Comments}", Comments.ToString()), null, MediaTypeNames.Text.Plain); } } } if (hasAddress) { msg.Send(); } } catch (Exception ex) { } finally { if (msg != null) { msg.Dispose(); msg = null; } } }