private void SendContactUsEmail() { string strContent = string.Empty; BLL.TemplateLib oTemplateLib = new BLL.TemplateLib(); strContent = oTemplateLib.GetTemplateDetailsByTemplateTemplateName("HealthCoachSubmitQuestionEmail").TextAreaHTML; Entity.CompanyInfo oCompanyInfo = new Entity.CompanyInfo(); oCompanyInfo.StrCategoryLevel = ddlLevel.SelectedItem.Text; oCompanyInfo.StrUserName = AppLib.GetLoggedInUserName(); oCompanyInfo.StrCategoryName = ddlCategory.SelectedItem.Text; oCompanyInfo.StrQuestion = txtQuestion.Text.Trim(); oCompanyInfo.StrSubject = txtsubject.Text.Trim(); oCompanyInfo.StrComments = txtComments.Text.Trim(); oCompanyInfo.StrQuestionType = rdoQuestionType.SelectedItem.Text; oCompanyInfo.StrAnswer = string.Empty; oCompanyInfo.DtCreatedOn = DateTime.Now; oCompanyInfo.ChrIsAnsweredGiven = 'N'; oCompanyInfo.ChrIsDeleted = 'N'; BLL.CompanyManager oCompanyManager = new BLL.CompanyManager(); oCompanyManager.SaveQuestionToHealthCoachFromUser(oCompanyInfo); lblMsg.Text = "Your question has been successfully sent to health coach. Health Coach will approach you soon"; strContent = strContent.Replace("[Name]", oCompanyManager.GetUserDetailsByUsername(AppLib.GetLoggedInUserName()).StrUserFullName); strContent = strContent.Replace("[Email]", AppLib.GetLoggedInUserName()); strContent = strContent.Replace("[Category]", ddlCategory.SelectedItem.Text + " - " + ddlLevel.SelectedItem.Text); strContent = strContent.Replace("[Question]", txtQuestion.Text.Trim()); strContent = strContent.Replace("[Subject]", txtsubject.Text); strContent = strContent.Replace("[Comments]", txtComments.Text); strContent = strContent.Replace("[QuestionType]", rdoQuestionType.SelectedItem.Text); strContent = strContent.Replace("[SiteUrl]", AppConfig.GetBaseSiteUrl()); strContent = strContent.Replace("[SiteName]", AppConfig.GetSiteName()); strContent = strContent.Replace("[SitePhone]", AppConfig.GetSITEPHONE()); ///Code for Forum if (rdoQuestionType.SelectedValue == "Public") { string msg = txtQuestion.Text; msg = msg.Trim(); msg = msg.Replace("<", "<").Replace(">", ">"); msg = aspnetforum.Utils.Formatting.FilterBadWords(msg); bool isModer = false; if (msg == "") return; string catgory = ddlCategory.SelectedItem.Text; string lvl = ddlLevel.SelectedValue; string totalvalue = catgory + " - " + lvl; providerFactory = aspnetforum.Utils.DB.CreateDBProviderFactory(); cn = aspnetforum.Utils.DB.CreateConnection(); cmd = providerFactory.CreateCommand(); cmd.Connection = cn; this.cn.Open(); this.cmd.CommandText = "SELECT ForumID FROM Forums WHERE Title='" + totalvalue + "'"; object _forumID = this.cmd.ExecuteScalar(); if (_addTopic || _changeTopic) //creating a new topic or editing topic title { string subj = txtsubject.Text; subj = subj.Trim(); if (subj == "") return; subj = aspnetforum.Utils.Formatting.FilterBadWords(subj); if (_addTopic) { string CurrentUserID = Membership.GetUser().ProviderUserKey.ToString(); this.cmd.Parameters.Clear(); this.cmd.CommandText = "INSERT INTO ForumTopics (ForumID, UserID, Subject, Visible) " + "VALUES (?, convert(uniqueidentifier, ?), ?, ?)"; aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, _forumID, CurrentUserID, subj, !_premoderated); this.cmd.ExecuteNonQuery(); this.cmd.Parameters.Clear(); this.cmd.CommandText = "SELECT MAX(TopicID) FROM ForumTopics WHERE Subject=?"; aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, subj); _topicID = Convert.ToInt32(this.cmd.ExecuteScalar()); this.cmd.Parameters.Clear(); //CREATE A POLL (if specified) string pollQuestion = "";//tbPollQuestion.Text.Trim(); if (pollQuestion.Length > 0) { //add a poll this.cmd.Parameters.Clear(); this.cmd.CommandText = "INSERT INTO ForumPolls (TopicID, Question) " + "VALUES (?, ?)"; aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, _topicID, pollQuestion); this.cmd.ExecuteNonQuery(); this.cmd.Parameters.Clear(); //now get the ID of the poll we just created this.cmd.CommandText = "SELECT MAX(PollID) FROM ForumPolls WHERE TopicID=?"; aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, _topicID); int pollID = Convert.ToInt32(this.cmd.ExecuteScalar()); this.cmd.Parameters.Clear(); int i = 0; while (Request.Form["PollOption" + i] != null && Request.Form["PollOption" + i].Trim().Length > 0) { //add option this.cmd.CommandText = "INSERT INTO ForumPollOptions (PollID, OptionText) " + "VALUES (?, ?)"; aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, pollID, Request.Form["PollOption" + i]); this.cmd.ExecuteNonQuery(); this.cmd.Parameters.Clear(); i++; } } } else if (_changeTopic) //edit topic subj { this.cmd.Parameters.Clear(); this.cmd.CommandText = "UPDATE ForumTopics SET Subject = ? WHERE TopicID = ?"; aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, subj, _topicID); this.cmd.ExecuteNonQuery(); this.cmd.Parameters.Clear(); } } // Inserting or updating? if (_isEditing) { //if moderatro, admin or message author //if (bmoderator || _messageAuthorID == CurrentUserID) //{ // // Record last editor and date at the end of the message. // msg += "\r\n<em>edited by " + Session["aspnetforumUserName"] + // " on " + aspnetforum.Utils.GetCurrTime().ToShortDateString() + "</em>"; // this.cmd.CommandText = "UPDATE ForumMessages SET Body=?, Visible=? " + // "WHERE MessageID=" + _messageId; // aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, msg, !_premoderated); // this.cmd.ExecuteNonQuery(); // this.cmd.Parameters.Clear(); // SaveAttachments(_messageId); //} } else //inserting { this.cmd.CommandText = "INSERT INTO ForumMessages (TopicID, UserID, Body, CreationDate, Visible) " + "VALUES (?, convert(uniqueidentifier, ?), ?, ?, ?)"; aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, _topicID, CurrentUserID, msg, aspnetforum.Utils.GetCurrTime(), !_premoderated); this.cmd.ExecuteNonQuery(); this.cmd.Parameters.Clear(); //incrementing repliescount (well... actually - re-calculating it) this.cmd.CommandText = "SELECT Count(MessageID) FROM ForumMessages WHERE TopicID=" + _topicID; object res = this.cmd.ExecuteScalar(); this.cmd.CommandText = "UPDATE ForumTopics SET RepliesCount=" + res.ToString() + " WHERE TopicID=" + _topicID; this.cmd.ExecuteNonQuery(); //incrementing PostsCount in Users table only for new messages, not edits. //only for registered users (if guestmode is on) if (CurrentUserID != "") { this.cmd.CommandText = "UPDATE ForumUsers SET PostsCount=PostsCount+1 WHERE UserID='" + CurrentUserID + "'"; this.cmd.ExecuteNonQuery(); } //get last message's ID this.cmd.CommandText = "SELECT MAX(MessageID) FROM ForumMessages WHERE TopicID=" + _topicID + " AND UserID='" + CurrentUserID + "'"; aspnetforum.Utils.DB.FillCommandParamaters(ref cmd, true); res = this.cmd.ExecuteScalar(); int lastmsgid = (res == null || res == DBNull.Value) ? 0 : Convert.ToInt32(res); //updating LastMessageID in Topics table this.cmd.CommandText = "UPDATE ForumTopics SET LastMessageID=" + lastmsgid + " WHERE TopicID=" + _topicID; this.cmd.ExecuteNonQuery(); SaveAttachments(lastmsgid); } //saving notifications settings if (_mailNotificationsEnabled) { this.cmd.CommandText = "DELETE FROM ForumSubscriptions WHERE UserID='" + CurrentUserID + "' AND TopicID=" + _topicID; this.cmd.ExecuteNonQuery(); //if(this.cbSubscribe.Checked) //{ this.cmd.CommandText = "INSERT INTO ForumSubscriptions (UserID, TopicID) VALUES ('" + CurrentUserID + "', " + _topicID + ")"; this.cmd.ExecuteNonQuery(); //} } //sending notifications if (_mailNotificationsEnabled) { string url = Request.Url.ToString().ToLower(); url = url.Substring(0, url.IndexOf("addpost.aspx")); if (_addTopic) { if (_forumID != null) { aspnetforum.SendNotifications.SendNewTopicNotificationEmails(Convert.ToInt32(_forumID), CurrentUserID, url); } } else { aspnetforum.SendNotifications.SendNewMsgNotificationEmails(_topicID, CurrentUserID, url); } } } try { AppLib.SendMailToUser(AppLib.GetLoggedInUserName(), txtsubject.Text, strContent, AppConfig.GetAdminEmail()); AppLib.SendMailToUser(AppConfig.GetAdminEmail(), txtsubject.Text, "Dear Admin, Following are the contents that were sent to the user. <br />" + strContent, AppLib.GetLoggedInUserName()); } catch { } oTemplateLib = null; oCompanyManager = null; oCompanyInfo = null; txtQuestion.Text = string.Empty; txtsubject.Text = string.Empty; txtComments.Text = string.Empty; ; rdoQuestionType.SelectedIndex = 0; }