Exemplo n.º 1
0
    protected void btnSendFlight_Click(object sender, EventArgs e)
    {
        Page.Validate("valSendFlight");
        if (Page.IsValid)
        {
            LogbookEntry         le       = new LogbookEntry(Convert.ToInt32(hdnFlightToSend.Value, CultureInfo.InvariantCulture), Page.User.Identity.Name);
            MyFlightbook.Profile pfSender = MyFlightbook.Profile.GetUser(Page.User.Identity.Name);
            string szRecipient            = txtSendFlightEmail.Text;

            using (MailMessage msg = new MailMessage())
            {
                msg.Body = Branding.ReBrand(Resources.LogbookEntry.SendFlightBody.Replace("<% Sender %>", HttpUtility.HtmlEncode(pfSender.UserFullName))
                                            .Replace("<% Message %>", HttpUtility.HtmlEncode(txtSendFlightMessage.Text))
                                            .Replace("<% Date %>", le.Date.ToShortDateString())
                                            .Replace("<% Aircraft %>", HttpUtility.HtmlEncode(le.TailNumDisplay))
                                            .Replace("<% Route %>", HttpUtility.HtmlEncode(le.Route))
                                            .Replace("<% Comments %>", HttpUtility.HtmlEncode(le.Comment))
                                            .Replace("<% Time %>", le.TotalFlightTime.FormatDecimal(pfSender.UsesHHMM))
                                            .Replace("<% FlightLink %>", le.SendFlightUri(Branding.CurrentBrand.HostName, SendPageTarget).ToString()));

                msg.Subject = String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.SendFlightSubject, pfSender.UserFullName);
                msg.From    = new MailAddress(Branding.CurrentBrand.EmailAddress, String.Format(CultureInfo.CurrentCulture, Resources.SignOff.EmailSenderAddress, Branding.CurrentBrand.AppName, pfSender.UserFullName));
                msg.ReplyToList.Add(new MailAddress(pfSender.Email));
                msg.To.Add(new MailAddress(szRecipient));
                msg.IsBodyHtml = true;
                util.SendMessage(msg);
            }

            modalPopupSendFlight.Hide();
        }
        else
        {
            modalPopupSendFlight.Show();
        }
    }