コード例 #1
0
        private void UploadReferences()
        {
            FileType  referenceFileType = FileTypeBLL.GetByName(STR_LetterOfRec);
            Reference selectedReference = ReferenceBLL.GetByID(int.Parse(dlistReferences.SelectedValue));

            //If there is already a reference file, we need to delete it
            if (selectedReference.ReferenceFile != null)
            {
                using (var ts = new TransactionScope())
                {
                    FileBLL.DeletePDF(selectedReference.ReferenceFile);
                    selectedReference.ReferenceFile = null;

                    ReferenceBLL.EnsurePersistent(selectedReference);

                    ts.CommitTransaction();
                }
            }

            if (fileUpload.HasFile)
            {
                using (var ts = new TransactionScope())
                {
                    File file = FileBLL.SavePDFWithWatermark(fileUpload, referenceFileType);

                    if (file != null)
                    {
                        selectedReference.ReferenceFile        = file;
                        selectedReference.UnsolicitedReference = chkUnsolicited.Checked;

                        ReferenceBLL.EnsurePersistent(selectedReference);

                        lblStatus.Text = "File Uploaded Successfully";
                    }
                    else
                    {
                        lblStatus.Text = "File Upload Did Not Succeed: Ensure That File Is A PDF File";
                    }

                    ts.CommitTransaction();
                }
            }
        }