Esempio n. 1
0
        protected void postMessageButton_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(messageTextBox.Text))
            {
                int messageId = Convert.ToInt32(Request.QueryString["MessageId"]);
                using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
                {
                    dataContext.InsertMessageReply(messageId, StoredData.User.UserId, messageTextBox.Text);

                    List <SelectRepliesResult> selectReplies = dataContext.SelectReplies(messageId).ToList();
                    messageRepeater.DataSource = selectReplies;
                    messageRepeater.DataBind();

                    List <string> emailIds = new List <string>();
                    if (ViewState["PostOwnerEmail"] != null)
                    {
                        emailIds.Add(ViewState["PostOwnerEmail"].ToString());
                    }
                    foreach (SelectRepliesResult result in selectReplies)
                    {
                        if (result.EmailPost.Value && !emailIds.Contains(result.EmailId))
                        {
                            emailIds.Add(result.EmailId);
                        }
                    }

                    StringBuilder sb      = new StringBuilder();
                    string        subject = string.Empty;
                    if (ViewState["Subject"] != null)
                    {
                        sb.Append(string.Format("Following item was posted by {0} {1} as a reply to {2}", StoredData.User.FirstName, StoredData.User.LastName, ViewState["Subject"].ToString()));
                        subject = "(FlexTennis)" + ViewState["Subject"].ToString();
                    }
                    else
                    {
                        sb.Append("A recent post you have participated in has been updated.");
                        subject = "(FlexTennis) Your post has been updated";
                    }
                    sb.Append("\r\n\r\n-------------------------------------------------\r\n");
                    sb.Append(messageTextBox.Text);

                    messageTextBox.Text = string.Empty;

                    SendEmail(emailIds, sb, subject, StoredData.User.EmailId, StoredData.User.FirstName + " " + StoredData.User.LastName);
                }
            }
        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int messageId = Convert.ToInt32(Request.QueryString["MessageId"]);

            if (!Page.IsPostBack)
            {
                using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
                {
                    List <SelectMessageByIdResult> result = dataContext.SelectMessageById(messageId).ToList();
                    if (result[0].DivisionId != StoredData.User.Division)
                    {
                        Response.Redirect(WebConfigurationManager.AppSettings["MessagePath"]);
                    }

                    messageSourceRepeater.DataSource = result;
                    messageSourceRepeater.DataBind();

                    if (result[0].EmailPost.Value)
                    {
                        ViewState["PostOwnerEmail"] = result[0].EmailId;
                    }
                    if (result[0].Message.Length < 27)
                    {
                        ViewState["Subject"] = result[0].Message;
                    }
                    else
                    {
                        ViewState["Subject"] = result[0].Message.Substring(0, 25) + "..";
                    }

                    List <SelectRepliesResult> selectReplies = dataContext.SelectReplies(messageId).ToList();
                    messageRepeater.DataSource = selectReplies;
                    messageRepeater.DataBind();
                }
            }
        }