当前位置: 首页>>代码示例>>C#>>正文


C# TransactionScope.CommitTransaction方法代码示例

本文整理汇总了C#中TransactionScope.CommitTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# TransactionScope.CommitTransaction方法的具体用法?C# TransactionScope.CommitTransaction怎么用?C# TransactionScope.CommitTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TransactionScope的用法示例。


在下文中一共展示了TransactionScope.CommitTransaction方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanSaveMessageTrackingEntry

        public void CanSaveMessageTrackingEntry()
        {
            var tracking = new MessageTracking
                               {
                                   From = StaticProperties.TestString,
                                   To = StaticProperties.TestString,
                                   SentBy = StaticProperties.TestString,
                                   Body = StaticProperties.TestString,
                                   DateSent = DateTime.Now
                               };

            using (var ts = new TransactionScope())
            {
                GenericBLL<MessageTracking, int>.EnsurePersistent(tracking);

                ts.CommitTransaction();
            }
        }
开发者ID:ucdavis,项目名称:Recruitments,代码行数:18,代码来源:MessageTrackingTest.cs

示例2: UploadReferences

    private bool UploadReferences(int referenceID, byte[] uploadedFile)
    {
        FileType referenceFileType = daoFactory.GetFileTypeDao().GetFileTypeByName(STR_LetterOfRec);

        Reference selectedReference = daoFactory.GetReferenceDao().GetById(referenceID, false);

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

                daoFactory.GetFileDao().Delete(selectedReference.ReferenceFile);
                selectedReference.ReferenceFile = null;

                //Delete the file from the file system
                System.IO.FileInfo fileToDelete = new System.IO.FileInfo(FilePath + fileID.ToString());
                fileToDelete.Delete();

                daoFactory.GetReferenceDao().SaveOrUpdate(selectedReference);

                ts.CommitTransaction();
            }
        }

        File file = new File();

        file.FileName = selectedReference.FullName + ".pdf";
        file.FileType = referenceFileType;

        using (var ts = new TransactionScope())
        {
            file = daoFactory.GetFileDao().Save(file);

            ts.CommitTransaction();
        }

        if (ValidateBO<File>.isValid(file))
        {
            SaveReferenceWithWatermark(uploadedFile, file.ID.ToString());

            selectedReference.ReferenceFile = file;

            using (var ts = new TransactionScope())
            {
                daoFactory.GetReferenceDao().SaveOrUpdate(selectedReference);

                ts.CommitTransaction();
            }

            return true;
        }
        else
        {
            return false;
        }
    }
开发者ID:ucdavis,项目名称:Recruitments,代码行数:58,代码来源:RecruitmentUploadService.cs

示例3: UploadPublications

    private bool UploadPublications(int applicationID, byte[] uploadedFile)
    {
        FileType publicationsFileType = daoFactory.GetFileTypeDao().GetFileTypeByName(STR_Publication);
        Application selectedApplication = daoFactory.GetApplicationDao().GetById(applicationID, false);

        File publication = new File();

        publication.FileName = publicationsFileType.FileTypeName + ".pdf";
        publication.FileType = publicationsFileType;

        using (var ts = new TransactionScope())
        {
            publication = daoFactory.GetFileDao().Save(publication);

            ts.CommitTransaction();
        }

        if (ValidateBO<File>.isValid(publication))
        {
            System.IO.File.WriteAllBytes(FilePath + publication.ID.ToString(), uploadedFile);

            selectedApplication.Files.Add(publication);

            using (var ts = new TransactionScope())
            {
                daoFactory.GetApplicationDao().SaveOrUpdate(selectedApplication);

                ts.CommitTransaction();
            }

            return true;
        }
        else
        {
            return false;
        }
    }
开发者ID:ucdavis,项目名称:Recruitments,代码行数:37,代码来源:RecruitmentUploadService.cs

示例4: UploadFiles

    private bool UploadFiles(int applicationID, int fileTypeID, byte[] uploadedFile)
    {
        FileType selectedFileType = daoFactory.GetFileTypeDao().GetById(fileTypeID, false);
        Application selectedApplication = daoFactory.GetApplicationDao().GetById(applicationID, false);

        //For all fileTypes except for Publications we should remove existing files
        if (selectedFileType.FileTypeName != STR_Publication && selectedFileType.FileTypeName != STR_LetterOfRec)
            RemoveAllFilesOfType(selectedApplication, selectedFileType.FileTypeName);

        File file = new File();

        file.FileName = selectedFileType.FileTypeName + ".pdf";
        file.FileType = selectedFileType;

        using (var ts = new TransactionScope())
        {
            file = daoFactory.GetFileDao().Save(file);

            ts.CommitTransaction();
        }

        if (ValidateBO<File>.isValid(file))
        {
            System.IO.File.WriteAllBytes(FilePath + file.ID.ToString(), uploadedFile);

            selectedApplication.Files.Add(file);

            using (var ts = new TransactionScope())
            {
                daoFactory.GetApplicationDao().SaveOrUpdate(selectedApplication);

                ts.CommitTransaction();
            }

            return true;
        }
        else
        {
            return false;
        }
    }
开发者ID:ucdavis,项目名称:Recruitments,代码行数:41,代码来源:RecruitmentUploadService.cs

示例5: RemoveAllFilesOfType

    /// <summary>
    /// Removes all files of the given type from the current applicaiton.  This removes the files themselves,
    /// the file info entry and the application files link
    /// </summary>
    private void RemoveAllFilesOfType(Application selectedApplication, string fileTypeName)
    {
        List<File> existingFiles = GetFilesOfType(selectedApplication, fileTypeName);

        if (existingFiles.Count != 0)
        {
            using (var ts = new TransactionScope())
            {
                foreach (File existingFile in existingFiles)
                {
                    selectedApplication.Files.Remove(existingFile);
                    daoFactory.GetFileDao().Delete(existingFile);

                    //Delete the file from the file system
                    System.IO.FileInfo file = new System.IO.FileInfo(FilePath + existingFile.ID.ToString());
                    file.Delete();
                }

                daoFactory.GetApplicationDao().SaveOrUpdate(selectedApplication);

                ts.CommitTransaction();
            }
        }
    }
开发者ID:ucdavis,项目名称:Recruitments,代码行数:28,代码来源:RecruitmentUploadService.cs

示例6: SaveDeleteProfile

        public void SaveDeleteProfile()
        {
            Applicant applicant = NHibernateHelper.DaoFactory.GetApplicantDao().GetById(StaticProperties.ExistingApplicantID, false);

            Profile target = new Profile();
            target.AssociatedApplicant = applicant; //associate with the applicant
            target.Address1 = StaticProperties.TestString;
            target.City = StaticProperties.TestString;
            target.State = StaticProperties.TestString;
            target.FirstName = StaticProperties.TestString;
            target.LastName = StaticProperties.TestString;

            //Validate before saving
            Assert.IsTrue(ValidateBO<Profile>.isValid(target), "Target Profile not valid");

            using (var ts = new TransactionScope())
            {
                target = NHibernateHelper.DaoFactory.GetProfileDao().Save(target); //save the target

                ts.CommitTransaction();
            }

            this.TestContext.WriteLine("Profile created: ID={0}", target.ID);

            Assert.IsNotNull(target);
            Assert.IsFalse(target.IsTransient()); //make sure that target is saved to the database

            Profile targetDB = NHibernateHelper.DaoFactory.GetProfileDao().GetById(target.ID, false);

            Assert.IsNotNull(targetDB);
            Assert.AreEqual<Profile>(target, targetDB);

            //Now delete the new profile
            using (var ts = new TransactionScope())
            {
                NHibernateHelper.DaoFactory.GetProfileDao().Delete(target);

                ts.CommitTransaction();
            }
            //Make sure it is deleted
            bool isDeleted = false;

            try
            {
                targetDB = NHibernateHelper.DaoFactory.GetProfileDao().GetById(target.ID, false);
                targetDB.IsTransient(); //check to see if its in the db
            }
            catch (NHibernate.ObjectNotFoundException)
            {
                isDeleted = true;
            }

            Assert.IsTrue(isDeleted);
        }
开发者ID:ucdavis,项目名称:Recruitments,代码行数:54,代码来源:ProfileTest.cs

示例7: LoadData

        public override void LoadData()
        {
            base.LoadData();

            //Add some applications
            Profile profile = ProfileBLL.GetByID(StaticProperties.ExistingProfileID);

            Application application = new Application();
            application.AppliedPosition = PositionBLL.GetByID(StaticProperties.ExistingPositionID);
            application.AssociatedProfile = profile;
            application.Email = StaticProperties.ExistingApplicantEmail;

            application.LastUpdated = DateTime.Now;

            profile.Applications = new List<Application>{application};

            using (var ts = new TransactionScope())
            {
                ApplicationBLL.EnsurePersistent(application);
                ProfileBLL.EnsurePersistent(profile);

                ts.CommitTransaction();
            }
        }
开发者ID:ucdavis,项目名称:Recruitments,代码行数:24,代码来源:ProfileTest.cs

示例8: SaveDeleteApplication

        public void SaveDeleteApplication()
        {
            Application target = new Application();

            target.AppliedPosition = NHibernateHelper.DaoFactory.GetPositionDao().GetById(StaticProperties.ExistingPositionID, false);
            target.AssociatedProfile = NHibernateHelper.DaoFactory.GetProfileDao().GetById(StaticProperties.ExistingProfileID, false);
            //target.ReferSource = NHibernateHelper.DaoFactory.GetReferSourceDao().GetUniqueByExample(new ReferSource("Internet"));

            target.Email = StaticProperties.TestString;
            target.LastUpdated = DateTime.Now;
            target.Submitted = false;

            Assert.IsTrue(ValidateBO<Application>.isValid(target));

            Assert.IsTrue(target.IsTransient());

            using (var ts = new TransactionScope())
            {
                target = NHibernateHelper.DaoFactory.GetApplicationDao().SaveOrUpdate(target);

                ts.CommitTransaction();
            }

            Assert.IsFalse(target.IsTransient());

            Application targetDB = NHibernateHelper.DaoFactory.GetApplicationDao().GetById(target.ID, false);

            Assert.AreEqual<Application>(target, targetDB);

            this.TestContext.WriteLine("Application Created had ID = {0}", target.ID);

            using (var ts = new TransactionScope())
            {
                NHibernateHelper.DaoFactory.GetApplicationDao().Delete(target);

                ts.CommitTransaction();
            }

            //Make sure it is deleted
            bool isDeleted = false;

            try
            {
                target = NHibernateHelper.DaoFactory.GetApplicationDao().GetById(targetDB.ID, false);
                target.IsTransient();
            }
            catch (NHibernate.ObjectNotFoundException)
            {
                isDeleted = true;
            }

            Assert.IsTrue(isDeleted);
        }
开发者ID:ucdavis,项目名称:Recruitments,代码行数:53,代码来源:ApplicationTest.cs

示例9: LoadData

        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();
            }
        }
开发者ID:ucdavis,项目名称:Recruitments,代码行数:58,代码来源:ApplicationTest.cs


注:本文中的TransactionScope.CommitTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。