1
0
mirror of https://github.com/bitwarden/server synced 2025-12-16 16:23:31 +00:00
Files
server/src/Infrastructure.EntityFramework/Repositories/TransactionRepository.cs
Justin Baur bae03feffe Revert filescoped (#2227)
* Revert "Add git blame entry (#2226)"

This reverts commit 239286737d.

* Revert "Turn on file scoped namespaces (#2225)"

This reverts commit 34fb4cca2a.
2022-08-29 15:53:48 -04:00

52 lines
2.1 KiB
C#

using AutoMapper;
using Bit.Core.Enums;
using Bit.Core.Repositories;
using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework.Repositories
{
public class TransactionRepository : Repository<Core.Entities.Transaction, Transaction, Guid>, ITransactionRepository
{
public TransactionRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.Transactions)
{ }
public async Task<Core.Entities.Transaction> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var results = await dbContext.Transactions
.FirstOrDefaultAsync(t => (t.GatewayId == gatewayId && t.Gateway == gatewayType));
return Mapper.Map<Core.Entities.Transaction>(results);
}
}
public async Task<ICollection<Core.Entities.Transaction>> GetManyByOrganizationIdAsync(Guid organizationId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var results = await dbContext.Transactions
.Where(t => (t.OrganizationId == organizationId && !t.UserId.HasValue))
.ToListAsync();
return Mapper.Map<List<Core.Entities.Transaction>>(results);
}
}
public async Task<ICollection<Core.Entities.Transaction>> GetManyByUserIdAsync(Guid userId)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var results = await dbContext.Transactions
.Where(t => (t.UserId == userId))
.ToListAsync();
return Mapper.Map<List<Core.Entities.Transaction>>(results);
}
}
}
}