コード例 #1
0
        public async Task <IEnumerable <string> > Get()
        {
            try
            {
                Console.WriteLine($"");
                Console.WriteLine($"Begin Transaction");
                _unitOfWork.BeginTran();
                Console.WriteLine($"");
                var passwords = await _passwordLibServices.Query(d => d.IsDeleted == false);

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


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


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

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

                //......

                Console.WriteLine($"");
                var guestbooks = await _guestbookServices.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 _guestbookServices.Add(new Guestbook()
                {
                    username   = "******",
                    blogId     = 1,
                    createdate = DateTime.Now,
                    isshow     = true
                });

                guestbooks = await _guestbookServices.Query();

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

                _unitOfWork.CommitTran();
            }
            catch (Exception)
            {
                _unitOfWork.RollbackTran();
                var passwords = await _passwordLibServices.Query();

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

                var guestbooks = await _guestbookServices.Query();

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

            return(new string[] { "value1", "value2" });
        }
コード例 #2
0
        public async Task <MessageModel <IEnumerable <string> > > Get()
        {
            List <string> returnMsg = new List <string>()
            {
            };

            try
            {
                returnMsg.Add($"Begin Transaction");

                _unitOfWork.BeginTran();
                var passwords = await _passwordLibServices.Query(d => d.IsDeleted == false);

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


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


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

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

                //......

                var guestbooks = await _guestbookServices.Query();

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

                int ex = 0;
                returnMsg.Add($"There's an exception!!");
                returnMsg.Add($" ");
                int throwEx = 1 / ex;

                var insertGuestbook = await _guestbookServices.Add(new Guestbook()
                {
                    username   = "******",
                    blogId     = 1,
                    createdate = DateTime.Now,
                    isshow     = true
                });

                guestbooks = await _guestbookServices.Query();

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

                _unitOfWork.CommitTran();
            }
            catch (Exception)
            {
                _unitOfWork.RollbackTran();
                var passwords = await _passwordLibServices.Query();

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

                var guestbooks = await _guestbookServices.Query();

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

            return(new MessageModel <IEnumerable <string> >()
            {
                success = true,
                msg = "操作完成",
                response = returnMsg
            });
        }