1
0
mirror of https://github.com/bitwarden/server synced 2025-12-25 20:53:16 +00:00

Revert filescoped (#2227)

* Revert "Add git blame entry (#2226)"

This reverts commit 239286737d.

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

This reverts commit 34fb4cca2a.
This commit is contained in:
Justin Baur
2022-08-29 15:53:48 -04:00
committed by GitHub
parent 239286737d
commit bae03feffe
1208 changed files with 74317 additions and 73126 deletions

View File

@@ -4,91 +4,92 @@ using Bit.Infrastructure.EntityFramework.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework.Repositories;
public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
namespace Bit.Infrastructure.EntityFramework.Repositories
{
public GrantRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper)
{ }
public async Task DeleteByKeyAsync(string key)
public class GrantRepository : BaseEntityFrameworkRepository, IGrantRepository
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var query = from g in dbContext.Grants
where g.Key == key
select g;
dbContext.Remove(query);
await dbContext.SaveChangesAsync();
}
}
public GrantRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper)
{ }
public async Task DeleteManyAsync(string subjectId, string sessionId, string clientId, string type)
{
using (var scope = ServiceScopeFactory.CreateScope())
public async Task DeleteByKeyAsync(string key)
{
var dbContext = GetDatabaseContext(scope);
var query = from g in dbContext.Grants
where g.SubjectId == subjectId &&
g.ClientId == clientId &&
g.SessionId == sessionId &&
g.Type == type
select g;
dbContext.Remove(query);
await dbContext.SaveChangesAsync();
}
}
public async Task<Core.Entities.Grant> GetByKeyAsync(string key)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var query = from g in dbContext.Grants
where g.Key == key
select g;
var grant = await query.FirstOrDefaultAsync();
return grant;
}
}
public async Task<ICollection<Core.Entities.Grant>> GetManyAsync(string subjectId, string sessionId, string clientId, string type)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var query = from g in dbContext.Grants
where g.SubjectId == subjectId &&
g.ClientId == clientId &&
g.SessionId == sessionId &&
g.Type == type
select g;
var grants = await query.ToListAsync();
return (ICollection<Core.Entities.Grant>)grants;
}
}
public async Task SaveAsync(Core.Entities.Grant obj)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var existingGrant = await (from g in dbContext.Grants
where g.Key == obj.Key
select g).FirstOrDefaultAsync();
if (existingGrant != null)
using (var scope = ServiceScopeFactory.CreateScope())
{
dbContext.Entry(existingGrant).CurrentValues.SetValues(obj);
}
else
{
var entity = Mapper.Map<Grant>(obj);
await dbContext.AddAsync(entity);
var dbContext = GetDatabaseContext(scope);
var query = from g in dbContext.Grants
where g.Key == key
select g;
dbContext.Remove(query);
await dbContext.SaveChangesAsync();
}
}
public async Task DeleteManyAsync(string subjectId, string sessionId, string clientId, string type)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var query = from g in dbContext.Grants
where g.SubjectId == subjectId &&
g.ClientId == clientId &&
g.SessionId == sessionId &&
g.Type == type
select g;
dbContext.Remove(query);
await dbContext.SaveChangesAsync();
}
}
public async Task<Core.Entities.Grant> GetByKeyAsync(string key)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var query = from g in dbContext.Grants
where g.Key == key
select g;
var grant = await query.FirstOrDefaultAsync();
return grant;
}
}
public async Task<ICollection<Core.Entities.Grant>> GetManyAsync(string subjectId, string sessionId, string clientId, string type)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var query = from g in dbContext.Grants
where g.SubjectId == subjectId &&
g.ClientId == clientId &&
g.SessionId == sessionId &&
g.Type == type
select g;
var grants = await query.ToListAsync();
return (ICollection<Core.Entities.Grant>)grants;
}
}
public async Task SaveAsync(Core.Entities.Grant obj)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var existingGrant = await (from g in dbContext.Grants
where g.Key == obj.Key
select g).FirstOrDefaultAsync();
if (existingGrant != null)
{
dbContext.Entry(existingGrant).CurrentValues.SetValues(obj);
}
else
{
var entity = Mapper.Map<Grant>(obj);
await dbContext.AddAsync(entity);
await dbContext.SaveChangesAsync();
}
}
}
}
}