99
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Practices.Unity.InterceptionExtension;
|
||||
using MyCode.Project.Infrastructure.Common;
|
||||
using System.Data.Common;
|
||||
using MyCode.Project.Repositories.Common;
|
||||
|
||||
namespace MyCode.Project.Repositories.Common
|
||||
{
|
||||
public class TransactionCallHandler : ICallHandler
|
||||
{
|
||||
|
||||
|
||||
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
|
||||
{
|
||||
|
||||
if (MallSqlSugarClient.Ado.Transaction != null) {
|
||||
|
||||
IMethodReturn method = getNext()(input, getNext);
|
||||
|
||||
if (method.Exception != null)
|
||||
{
|
||||
return input.CreateExceptionMethodReturn(method.Exception);
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
MallSqlSugarClient.Ado.BeginTran();
|
||||
|
||||
IMethodReturn methodReturn = getNext()(input, getNext);
|
||||
|
||||
if (methodReturn.Exception != null) {
|
||||
|
||||
MallSqlSugarClient.Ado.RollbackTran();
|
||||
|
||||
return input.CreateExceptionMethodReturn(methodReturn.Exception);
|
||||
}
|
||||
|
||||
MallSqlSugarClient.Ado.CommitTran();
|
||||
|
||||
return methodReturn;
|
||||
}
|
||||
|
||||
public int Order { get; set; }
|
||||
|
||||
public MyCodeSqlSugarClient MallSqlSugarClient { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user