private void SendNotifications()
 {
     //Send thank you letter
     if (Master.EmailPINRow != null)
     {
         SurveyTools.SendNotifications(
             Server,
             Master.PropertyShortCode,
             SharedClasses.SurveyType.GEI,
             NotificationReason.ThankYou,
             string.Empty,
             new
         {
             CasinoName       = PropertyTools.GetCasinoName((int)Master.PropertyShortCode),
             FeedbackNoteHTML = String.Empty,
             FeedbackNoteTXT  = String.Empty,
             Attachments      = new SurveyTools.SurveyAttachmentDetails[] {
                 new SurveyTools.SurveyAttachmentDetails()
                 {
                     Path = "~/Images/headers/" + PropertyTools.GetCasinoHeaderImage(Master.PropertyShortCode), ContentID = "HeaderImage"
                 }
             }
         },
             Master.EmailPINRow["EmailAddress"].ToString());
     }
 }
        private void SendNotifications(int surveyID, string feedbackUID)
        {
            string gagLocation = String.Empty;

            if (AlignedPropertyShortCode == GCCPropertyShortCode.GAG)
            {
                if (radGAG_Everett.Checked)
                {
                    gagLocation = "Everett";
                }
                else if (radGAG_Lakewood.Checked)
                {
                    gagLocation = "Lakewood";
                }
                else if (radGAG_Tukwila.Checked)
                {
                    gagLocation = "Tukwila";
                }
                else if (radGAG_DeMoines.Checked)
                {
                    gagLocation = "DeMoines";
                }
                if (gagLocation.Length > 0)
                {
                    gagLocation = " - " + gagLocation;
                }
            }



            // 2018 04 18 Adding notification users for no specific property
            // Adding proper PropertyID for No Specific Property Region Operations

            //if (AlignedPropertyShortCode == GCCPropertyShortCode.GCC && fbkProperty.SelectedIndex == 24)   // No specific Property
            //{


            //    if (Master.PropertyShortCode == GCCPropertyShortCode.GCC)
            //    {
            //        int selectedProp = Conversion.StringToInt(fbkDirectQuestion.SelectedValue, 0);
            //        if (selectedProp != 0)
            //        {
            //            try
            //            {
            //                GCCPropertyShortCode sc = (GCCPropertyShortCode)selectedProp;
            //                NoSpecificPropertyShortCode = sc;
            //            }
            //            catch
            //            {
            //                NoSpecificPropertyShortCode = GCCPropertyShortCode.GCC;
            //            }
            //        }
            //        else
            //        {
            //            NoSpecificPropertyShortCode = GCCPropertyShortCode.GCC;
            //        }
            //    }
            //    else
            //    {
            //        NoSpecificPropertyShortCode = Master.PropertyShortCode;
            //    }



            //  //  AlignedPropertyShortCode = (GCCPropertyShortCode)Convert.ToInt32(fbkDirectQuestion.SelectedValue.ToString());

            //}


            NotificationReason nr = (NotificationReason)fbkQ2.SelectedValue.StringToInt();

            //Send the notification
            SurveyTools.SendNotifications(
                Server,
                AlignedPropertyShortCode,
                SharedClasses.SurveyType.Feedback,
                nr,
                fbkQ3.Text.ToString(),
                new
            {
                Date             = DateTime.Now.ToString("yyyy-MM-dd"),
                CasinoName       = Master.CasinoName + gagLocation,
                FeedbackNoteHTML = String.IsNullOrEmpty(feedbackUID) ? String.Empty : "<p><b>This guest has requested a response.</b> You can view and respond to the feedback request by clicking on (or copying and pasting) the following link:</p>\n<p>" + GCCPortalUrl + "Admin/Feedback/" + feedbackUID + "</p>",
                FeedbackNoteTXT  = String.IsNullOrEmpty(feedbackUID) ? String.Empty : "The guest requested feedback. You can view and respond to the feedback request by clicking on (or copying and pasting) the following link:\n" + GCCPortalUrl + "Admin/Feedback/" + feedbackUID + "\n\n",
                SurveyLink       = GCCPortalUrl + "Display/Feedback/" + surveyID
            },
                String.Empty,
                String.Empty,
                fbkDirectQuestion.SelectedValue.StringToInt(-1)
                );
            //Determine triggers for feedback request
            if (!IsStaffSurvey &&
                !fbkQ5.SelectedValue.Equals("I do not want to be contacted") &&
                !String.IsNullOrEmpty(txtEmailContact.Text))
            {
                //Send thank you letter
                SurveyTools.SendNotifications(
                    Server,
                    AlignedPropertyShortCode,
                    SharedClasses.SurveyType.Feedback,
                    NotificationReason.ThankYou,
                    string.Empty,
                    new
                {
                    CasinoName = PropertyTools.GetCasinoName(Master.PropertyID),

                    Attachments = new SurveyTools.SurveyAttachmentDetails[]
                    {
                        new SurveyTools.SurveyAttachmentDetails()
                        {
                            Path = "~/Images/headers/" + PropertyTools.GetCasinoHeaderImage(AlignedPropertyShortCode), ContentID = "HeaderImage"
                        }
                    }
                },
                    txtEmailContact.Text,
                    String.Empty,
                    fbkDirectQuestion.SelectedValue.StringToInt(-1));
            }
        }
        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;
                    }
                }
            }
        }