2022-06-29 19:46:41 -04:00
|
|
|
|
using System.Data;
|
2022-01-11 10:40:51 +01:00
|
|
|
|
using Bit.Core.Entities;
|
2019-02-01 22:22:08 -05:00
|
|
|
|
using Bit.Core.Enums;
|
2022-01-11 10:40:51 +01:00
|
|
|
|
using Bit.Core.Repositories;
|
2021-02-22 15:35:16 -06:00
|
|
|
|
using Bit.Core.Settings;
|
2019-01-31 16:45:01 -05:00
|
|
|
|
using Dapper;
|
2023-01-10 15:58:41 -05:00
|
|
|
|
using Microsoft.Data.SqlClient;
|
2019-01-31 16:45:01 -05:00
|
|
|
|
|
2022-01-11 10:40:51 +01:00
|
|
|
|
namespace Bit.Infrastructure.Dapper.Repositories;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2022-01-11 10:40:51 +01:00
|
|
|
|
public class TransactionRepository : Repository<Transaction, Guid>, ITransactionRepository
|
2019-01-31 16:45:01 -05:00
|
|
|
|
{
|
|
|
|
|
|
public TransactionRepository(GlobalSettings globalSettings)
|
|
|
|
|
|
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
public TransactionRepository(string connectionString, string readOnlyConnectionString)
|
|
|
|
|
|
: base(connectionString, readOnlyConnectionString)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<ICollection<Transaction>> GetManyByUserIdAsync(Guid userId)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2019-01-31 16:45:01 -05:00
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<Transaction>(
|
|
|
|
|
|
$"[{Schema}].[Transaction_ReadByUserId]",
|
|
|
|
|
|
new { UserId = userId },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2019-01-31 16:45:01 -05:00
|
|
|
|
return results.ToList();
|
|
|
|
|
|
}
|
2022-08-29 16:06:55 -04:00
|
|
|
|
}
|
2019-01-31 16:45:01 -05:00
|
|
|
|
|
|
|
|
|
|
public async Task<ICollection<Transaction>> GetManyByOrganizationIdAsync(Guid organizationId)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2019-01-31 16:45:01 -05:00
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<Transaction>(
|
|
|
|
|
|
$"[{Schema}].[Transaction_ReadByOrganizationId]",
|
|
|
|
|
|
new { OrganizationId = organizationId },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2019-01-31 16:45:01 -05:00
|
|
|
|
return results.ToList();
|
|
|
|
|
|
}
|
2022-08-29 16:06:55 -04:00
|
|
|
|
}
|
2019-02-01 22:22:08 -05:00
|
|
|
|
|
|
|
|
|
|
public async Task<Transaction> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2019-02-01 22:22:08 -05:00
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<Transaction>(
|
|
|
|
|
|
$"[{Schema}].[Transaction_ReadByGatewayId]",
|
|
|
|
|
|
new { Gateway = gatewayType, GatewayId = gatewayId },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2019-02-01 22:22:08 -05:00
|
|
|
|
return results.SingleOrDefault();
|
|
|
|
|
|
}
|
2019-01-31 16:45:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|