/// <summary> /// Perform the necessary action to update the module's state, and /// send the email to the module submitter if emails are enabled. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SendBtn_Click(object sender, System.EventArgs e) { Emails.formatEmailBody(Message, CustomMessage.Text); MailMessage msg = Emails.constructMailMessage(Message, UserName, Globals.EditorsEmail); switch (Message.Type) { case EmailType.SubmitterApproved: UsersControl.approveSubmitter(UserName); break; case EmailType.SubmitterDenied: UsersControl.rejectSubmitter(UserName); break; case EmailType.ModuleApproved: ModulesControl.approveModule(ModuleID); break; case EmailType.ModuleDeniedSave: ModulesControl.rejectModule(ModuleID, true); break; case EmailType.ModuleDeniedDelete: ModulesControl.rejectModule(ModuleID, false); deleteMaterials(); break; case EmailType.FacultyApproved: UsersControl.approveFaculty(UserName); break; case EmailType.FacultyDenied: UsersControl.rejectFaculty(UserName); break; } // Message to be displayed on editors page. string successMessage = "Operation successful. "; // Only send an email if they're enabled. if (Globals.EmailsEnabled) { try { SmtpMail.SmtpServer = AspNetForums.Components.Globals.SmtpServer; SmtpMail.Send(msg); successMessage += "Email sent to user."; } catch (Exception ex) { successMessage += "But an error occurred while sending an email to the user."; } } else { successMessage += "Email not sent to user because they are disabled."; } Response.Redirect("EditorsPage.aspx?message=" + HttpUtility.UrlEncode(successMessage)); }
/// <summary> /// Handles the Submit button-click event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SubmitBtn_Click(object sender, EventArgs e) { string message = ""; bool isValid = validate(); // If invalid/incomplete data exists, alert the user to the problem, // redirect them to the right location, and don't attempt to save // or submit the module. (we don't save because duplicate items may // be the cause of invalid data, and the DB can't handle duplicates) if (!isValid) { ErrorMessage.Text = "Some required items are missing or invalid. " + "Please review the following fields before attempting to submit again."; // Now we should find where the first error is and redirect the // user to that upload step if (!(TitleValidator.IsValid && AbstractValidator.IsValid && CategoriesControl1.validate())) { UploadStep = 0; } else if (!AuthorsControl1.validate()) { UploadStep = 1; } else if (!(PrerequisitesControl1.validate() && ObjectivesControl1.validate() && TopicsControl1.validate())) { UploadStep = 2; } else if (!(MaterialsControl1.validate() && ResourcesControl1.validate())) { UploadStep = 3; } else if (!(SeeAlsoControl1.validate() && CheckInValidator.IsValid)) { UploadStep = 4; } else { ErrorMessage.Text = "Could not locate problem."; UploadStep = 4; } StepLbl.Text = "" + (UploadStep + 1); toggleButtonsAndPanels(UploadStep); NextBtn.CausesValidation = true; return; } // If the module was valid, save it and submit it for approval. // (if an admin is submitting, it doesn't need approval) try { ModuleStatus status; Modules.ModuleInfo module; if ((User.Identity.IsAuthenticated && User.IsInRole(UserRole.Admin.ToString()))) { status = ModuleStatus.Approved; module = saveModule(status); ModulesControl.approveModule(module.Id); } else { status = ModuleStatus.PendingApproval; module = saveModule(status); // Send a Module Approval notification to the editors Email email = Emails.getEmail(EmailType.ApproveModule); Emails.formatEmail(email, User.Identity.Name, module.Id); MailMessage msg = Emails.constructEditorsMail(email, Globals.AdminsEmail); SmtpMail.SmtpServer = AspNetForums.Components.Globals.SmtpServer; SmtpMail.Send(msg); } // Postprocessing // Only reset if everything worked. Otherwise, the data will // be saved so the user may try again. reset(); Response.Redirect("uploadResult.aspx?moduleID=" + ModuleID, true); } catch (Exception ex) { ErrorMessage.Text = ex.Message + "..." + ex.StackTrace; } }