Files
server/src/Infrastructure.Dapper/Repositories/OrganizationRepository.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
3.7 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;
using Bit.Core.Entities;
using Bit.Core.Models.Data;
using Bit.Core.Repositories;
using Bit.Core.Settings;
2021-12-16 15:35:09 +01:00
using Dapper;
namespace Bit.Infrastructure.Dapper.Repositories
{
public class OrganizationRepository : Repository<Organization, Guid>, IOrganizationRepository
{
public OrganizationRepository(GlobalSettings globalSettings)
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
{ }
public OrganizationRepository(string connectionString, string readOnlyConnectionString)
: base(connectionString, readOnlyConnectionString)
{ }
public async Task<Organization> GetByIdentifierAsync(string identifier)
{
using (var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<Organization>(
"[dbo].[Organization_ReadByIdentifier]",
new { Identifier = identifier },
commandType: CommandType.StoredProcedure);
return results.SingleOrDefault();
}
}
2017-08-22 15:27:29 -04:00
public async Task<ICollection<Organization>> GetManyByEnabledAsync()
2017-08-17 00:12:11 -04:00
{
using (var connection = new SqlConnection(ConnectionString))
2017-08-17 00:12:11 -04:00
{
var results = await connection.QueryAsync<Organization>(
2017-08-22 15:27:29 -04:00
"[dbo].[Organization_ReadByEnabled]",
2017-08-17 00:12:11 -04:00
commandType: CommandType.StoredProcedure);
return results.ToList();
}
}
public async Task<ICollection<Organization>> GetManyByUserIdAsync(Guid userId)
{
using (var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<Organization>(
2017-03-02 21:51:03 -05:00
"[dbo].[Organization_ReadByUserId]",
new { UserId = userId },
commandType: CommandType.StoredProcedure);
return results.ToList();
}
}
2017-07-10 16:21:18 -04:00
2018-03-21 17:41:14 -04:00
public async Task<ICollection<Organization>> SearchAsync(string name, string userEmail, bool? paid,
int skip, int take)
{
using (var connection = new SqlConnection(ReadOnlyConnectionString))
2018-03-21 17:41:14 -04:00
{
var results = await connection.QueryAsync<Organization>(
"[dbo].[Organization_Search]",
new { Name = name, UserEmail = userEmail, Paid = paid, Skip = skip, Take = take },
2018-10-11 22:21:59 -04:00
commandType: CommandType.StoredProcedure,
commandTimeout: 120);
2018-03-21 17:41:14 -04:00
2018-03-22 21:10:10 -04:00
return results.ToList();
2018-03-21 17:41:14 -04:00
}
}
2017-07-10 22:08:52 -04:00
public async Task UpdateStorageAsync(Guid id)
2017-07-10 16:21:18 -04:00
{
using (var connection = new SqlConnection(ConnectionString))
2017-07-10 16:21:18 -04:00
{
await connection.ExecuteAsync(
"[dbo].[Organization_UpdateStorage]",
2017-07-10 22:08:52 -04:00
new { Id = id },
2017-07-10 16:21:18 -04:00
commandType: CommandType.StoredProcedure,
commandTimeout: 180);
}
}
public async Task<ICollection<OrganizationAbility>> GetManyAbilitiesAsync()
{
using (var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<OrganizationAbility>(
"[dbo].[Organization_ReadAbilities]",
commandType: CommandType.StoredProcedure);
return results.ToList();
}
}
}
}