调整事物
This commit is contained in:
47
src/WMS.Web.Repositories/TransactionRepositories.cs
Normal file
47
src/WMS.Web.Repositories/TransactionRepositories.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
using WMS.Web.Repositories.Configuration;
|
||||
|
||||
namespace WMS.Web.Repositories
|
||||
{
|
||||
public class TransactionRepositories: ITransactionRepositories
|
||||
{
|
||||
private RepositoryDbContext _context;
|
||||
|
||||
|
||||
public TransactionRepositories(RepositoryDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
public IDbContextTransaction GetTransaction()
|
||||
{
|
||||
return _context.Database.BeginTransaction();
|
||||
}
|
||||
|
||||
public bool CommitTransaction(bool isRollback, IDbContextTransaction transaction)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (transaction == null)
|
||||
return true;
|
||||
|
||||
if (isRollback)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user