48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
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;
|
|
}
|
|
|
|
}
|
|
}
|