Add transaction support between services
This commit is contained in:
@ -3,22 +3,34 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hcs.WebApp.Services
|
||||
{
|
||||
public class RegistryService(IDbContextFactory<HcsDbContext> factory)
|
||||
public class RegistryService(IDbContextFactory<HcsDbContext> factory) : HcsServiceBase(factory)
|
||||
{
|
||||
private readonly IDbContextFactory<HcsDbContext> factory = factory;
|
||||
|
||||
public async Task<IEnumerable<Registry>> GetAllRegistriesAsync(bool isCommon)
|
||||
{
|
||||
using var context = factory.CreateDbContext();
|
||||
using var context = GetNewContext();
|
||||
return await (from registry in context.Registries
|
||||
where registry.IsCommon == isCommon
|
||||
select registry).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<Registry> GetRegistryByOperationId(int operationId)
|
||||
public async Task<Registry> GetRegistryByOperationIdAsync(int operationId)
|
||||
{
|
||||
using var context = factory.CreateDbContext();
|
||||
using var context = GetNewContext();
|
||||
return await context.Registries.SingleAsync(x => x.LastSyncOperationId == operationId);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Registry>> GetRegistriesByOperationId(int operationId)
|
||||
{
|
||||
using var context = GetNewContext();
|
||||
return await (from registry in context.Registries
|
||||
where registry.LastSyncOperationId == operationId
|
||||
select registry).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task SetOperationIdToAllRegistries(HcsDbContext context, int operationId)
|
||||
{
|
||||
await context.Registries.ForEachAsync(x => x.LastSyncOperationId = operationId);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user