SendDeclineEmail() public static method

Sends the email indicating to an appointment requestor that their request has been declined.
public static SendDeclineEmail ( Appointment appointment, string declineReason ) : void
appointment Appointment The appointment which was declined.
declineReason string The reason for declining the appointment, or null.
return void
        /// <summary>
        /// Handles the <see cref="LinkButton.Click"/> event of the <c>SubmitDeclineReasonButton</c> control in the footer of the <see cref="DeclineReasonRepeater"/>.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void SubmitDeclineReasonButton_Click(object sender, EventArgs e)
        {
            var declinedAppointments = new List <Appointment>();

            foreach (RepeaterItem repeaterItem in this.DeclineReasonRepeater.Items)
            {
                var declinedAppointmentIdHiddenField = (HiddenField)repeaterItem.FindControl("DeclinedAppointmentIdHiddenField");
                var declineReasonTextBox             = (TextBox)repeaterItem.FindControl("DeclineReasonTextBox");

                int appointmentId = int.Parse(declinedAppointmentIdHiddenField.Value, NumberStyles.Integer, CultureInfo.InvariantCulture);
                var appointment   = Appointment.Load(appointmentId);
                if (appointment != null)
                {
                    appointment.Decline(this.UserId);
                    declinedAppointments.Add(appointment);
                    EmailService.SendDeclineEmail(appointment, declineReasonTextBox.Text);
                }
            }

            this.ApprovalMessage.Visible = true;
            this.ApprovalMessage.Text    = this.GenerateAppointmentApprovalMessage(declinedAppointments, "DeclinedAppointments.Text");

            this.BindData(true);
            this.ApprovalMultiview.SetActiveView(this.ApprovalsListView);
        }
Beispiel #2
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string actionKeyString = this.Request.QueryString["ActionKey"];
                if (string.IsNullOrEmpty(actionKeyString))
                {
                    return;
                }

                Guid actionKey;
                try
                {
                    actionKey = new Guid(actionKeyString);
                }
                catch (FormatException)
                {
                    return;
                }
                catch (OverflowException)
                {
                    return;
                }

                Appointment appointment = Appointment.ApproveByKey(actionKey);
                if (appointment == null)
                {
                    return;
                }

                if (appointment.IsAccepted == null)
                {
                    this.ApprovalMessage.TextResourceKey = "UnsuccessfulAccept.Text";
                    return;
                }

                string resourceKey;
                if (appointment.IsAccepted.Value)
                {
                    EmailService.SendAcceptanceEmail(appointment);
                    resourceKey = "SuccessfulAccept.Text";
                }
                else
                {
                    EmailService.SendDeclineEmail(appointment, string.Empty);
                    resourceKey = "SuccessfulDecline.Text";
                }

                this.ApprovalMessage.MessageType     = ModuleMessageType.Success;
                this.ApprovalMessage.TextResourceKey = resourceKey;
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }