public async Task <bool> TestTranInRepositoryAOP()
        {
            var passwords = await _passwordLibRepository.Query();

            Console.WriteLine($"first time : the count of passwords is :{passwords.Count}");


            Console.WriteLine($"insert a data into the table PasswordLib now.");
            var insertPassword = await _passwordLibRepository.Add(new PasswordLib()
            {
                IsDeleted     = false,
                plAccountName = "aaa",
                plCreateTime  = DateTime.Now
            });


            passwords = await _passwordLibRepository.Query(d => d.IsDeleted == false);

            Console.WriteLine($"second time : the count of passwords is :{passwords.Count}");

            //......

            Console.WriteLine($"");
            var guestbooks = await _dal.Query();

            Console.WriteLine($"first time : the count of guestbooks is :{guestbooks.Count}");

            int ex = 0;

            Console.WriteLine($"\nThere's an exception!!");
            int throwEx = 1 / ex;

            Console.WriteLine($"insert a data into the table Guestbook now.");
            var insertGuestbook = await _dal.Add(new Guestbook()
            {
                username   = "******",
                blogId     = 1,
                createdate = DateTime.Now,
                isshow     = true
            });

            guestbooks = await _dal.Query();

            Console.WriteLine($"second time : the count of guestbooks is :{guestbooks.Count}");

            return(true);
        }
        public async Task <MessageModel <string> > TestTranInRepository()
        {
            try
            {
                Console.WriteLine($"");
                Console.WriteLine($"事务操作开始");
                _unitOfWork.BeginTran();
                Console.WriteLine($"");

                Console.WriteLine($"insert a data into the table PasswordLib now.");
                var insertPassword = await _passwordLibRepository.Add(new PasswordLib()
                {
                    IsDeleted     = false,
                    plAccountName = "aaa",
                    plCreateTime  = DateTime.Now
                });


                var passwords = await _passwordLibRepository.Query(d => d.IsDeleted == false);

                Console.WriteLine($"second time : the count of passwords is :{passwords.Count}");

                //......

                Console.WriteLine($"");
                var guestbooks = await _dal.Query();

                Console.WriteLine($"first time : the count of guestbooks is :{guestbooks.Count}");

                int ex = 0;
                Console.WriteLine($"\nThere's an exception!!");
                int throwEx = 1 / ex;

                Console.WriteLine($"insert a data into the table Guestbook now.");
                var insertGuestbook = await _dal.Add(new Guestbook()
                {
                    username   = "******",
                    blogId     = 1,
                    createdate = DateTime.Now,
                    isshow     = true
                });

                guestbooks = await _dal.Query();

                Console.WriteLine($"second time : the count of guestbooks is :{guestbooks.Count}");


                _unitOfWork.CommitTran();

                return(new MessageModel <string>()
                {
                    success = true,
                    msg = "操作完成"
                });
            }
            catch (Exception)
            {
                _unitOfWork.RollbackTran();
                var passwords = await _passwordLibRepository.Query();

                Console.WriteLine($"third time : the count of passwords is :{passwords.Count}");

                var guestbooks = await _dal.Query();

                Console.WriteLine($"third time : the count of guestbooks is :{guestbooks.Count}");

                return(new MessageModel <string>()
                {
                    success = false,
                    msg = "操作异常"
                });
            }
        }
Exemple #3
0
        public async Task <bool> TestTranInRepository()
        {
            try
            {
                Console.WriteLine($"");
                Console.WriteLine($"Begin Transaction");
                m_UnitOfWork.BeginTran();

                var passwords = await m_PasswordLibRepository.Query();

                Console.WriteLine($"First time: the count of password is: {passwords.Count}.");

                Console.WriteLine($"Insert a data into the table PasswordLib now.");
                var insertPassword = await m_PasswordLibRepository.Add(new PasswordLib()
                {
                    IsDeleted     = false,
                    PLAccountName = "aaa",
                    PLCreateTime  = DateTime.Now
                });

                passwords = await m_PasswordLibRepository.Query(d => d.IsDeleted == false);

                Console.WriteLine($"Second time: the count of passwords is: {passwords.Count}.");

                var guestbooks = await m_Dal.Query();

                Console.WriteLine($"\nFirst time: the count of guestbooks is: {guestbooks.Count}.");

                int ex = 0;
                Console.WriteLine($"\nThere's an exception!");
                int throwEx = 1 / ex;

                Console.WriteLine($"Insert a data into the table Guestbook now.");
                var insertGuestBook = await m_Dal.Add(new GuestBook()
                {
                    UserName   = "******",
                    BlogId     = 1,
                    Createdate = DateTime.Now,
                    IsShow     = true,
                });

                guestbooks = await m_Dal.Query();

                Console.WriteLine($"Second time: the count of guestbooks is: {guestbooks.Count}.");

                m_UnitOfWork.CommitTran();
                return(true);
            }
            catch (Exception)
            {
                m_UnitOfWork.RollBackTran();
                var passwords = await m_PasswordLibRepository.Query();

                Console.WriteLine($"Third time: the count of passwords is: {passwords.Count}.");

                var guestBooks = await m_Dal.Query();

                Console.WriteLine($"Third time: the count of guestbooks is: {guestBooks.Count}.");
                return(false);
            }
        }