private void UploadReferences() { FileType referenceFileType = FileTypeBLL.GetByName(STR_LetterOfRec); if (fileUploadReference.HasFile) { if (FileBLL.IsPostedFilePDF(fileUploadReference.PostedFile)) { File file = new File(); file.FileName = fileUploadReference.FileName; file.FileType = referenceFileType; using (var ts = new TransactionScope()) { FileBLL.EnsurePersistent(file, true); ts.CommitTransaction(); } if (ValidateBO <File> .isValid(file)) { SaveReferenceWithWatermark(fileUploadReference, file.ID.ToString()); currentReference.ReferenceFile = file; using (var ts = new TransactionScope()) { ReferenceBLL.EnsurePersistent(currentReference); ts.CommitTransaction(); } //Send confirmation email after success -- if there are errors, ignore try { System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient(); string subject = "Reference Upload Confirmation"; StringBuilder bodyText = new StringBuilder(); bodyText.AppendFormat("Your reference letter for {0}, who applied to the {1} position at the University of California, has been successfully received.", currentReference.AssociatedApplication.AssociatedProfile.FullName, currentReference.AssociatedApplication.AppliedPosition.PositionTitle); bodyText.AppendFormat(" We appreciate your comments.", currentReference.AssociatedApplication.AssociatedProfile.LastName); MailMessage message = new MailMessage(currentReference.AssociatedApplication.AppliedPosition.HREmail, currentReference.Email, subject, bodyText.ToString()); message.IsBodyHtml = true; mail.Send(message); //Send the message } catch (Exception) { } //Continue on failure Response.Redirect(UploadReferenceSuccessURL); } else { lblUploadStatus.Text = "There was an unexpected error uploading your file"; } } else { lblUploadStatus.Text = "Please upload a file in PDF format"; } } }
public override void LoadData() { base.LoadData(); var application = ApplicationBLL.GetByID(StaticProperties.ExistingApplicationID); //Add some applications info CurrentPosition currentPosition = new CurrentPosition { Address1 = StaticProperties.TestString, City = StaticProperties.TestString, Country = StaticProperties.TestString, Department = StaticProperties.TestString, Institution = StaticProperties.TestString, Title = StaticProperties.TestString, Zip = StaticProperties.TestString, State = StaticProperties.TestString, ApplicationStepType = ApplicationStepType.CurrentPosition, AssociatedApplication = application }; Education education = new Education { ApplicationStepType = ApplicationStepType.Education, AssociatedApplication = application, Date = DateTime.Now, Discipline = StaticProperties.TestString, Institution = StaticProperties.TestString }; Reference reference = new Reference { AssociatedApplication = application }; Survey survey = new Survey { AssociatedApplication = application, Other = StaticProperties.TestString }; File file = new File { FileName = StaticProperties.TestString, }; FileType fileType = new FileType { ApplicationFile = true, FileTypeName = StaticProperties.TestString }; file.FileType = fileType; using (var ts = new TransactionScope()) { FileTypeBLL.EnsurePersistent(fileType); FileBLL.EnsurePersistent(file); application.CurrentPositions = new List <CurrentPosition> { currentPosition }; application.Education = new List <Education> { education }; application.References = new List <Reference> { reference }; application.Surveys = new List <Survey> { survey }; application.Files = new List <File> { file }; ApplicationBLL.EnsurePersistent(application); ts.CommitTransaction(); } }