mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 01:22:50 -05:00

* Move RevisionDate Bumps to Extension Class * Add Tests against live databases * Run Formatting * Fix Typo * Fix Test Solution Typo * Await ReplaceAsync
52 lines
1.9 KiB
C#
52 lines
1.9 KiB
C#
using AutoMapper;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Infrastructure.EntityFramework.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Bit.Infrastructure.EntityFramework.Repositories;
|
|
|
|
public class SendRepository : Repository<Core.Entities.Send, Send, Guid>, ISendRepository
|
|
{
|
|
public SendRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
|
|
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.Sends)
|
|
{ }
|
|
|
|
public override async Task<Core.Entities.Send> CreateAsync(Core.Entities.Send send)
|
|
{
|
|
send = await base.CreateAsync(send);
|
|
using (var scope = ServiceScopeFactory.CreateScope())
|
|
{
|
|
var dbContext = GetDatabaseContext(scope);
|
|
if (send.UserId.HasValue)
|
|
{
|
|
await UserUpdateStorage(send.UserId.Value);
|
|
await dbContext.UserBumpAccountRevisionDateAsync(send.UserId.Value);
|
|
await dbContext.SaveChangesAsync();
|
|
}
|
|
}
|
|
|
|
return send;
|
|
}
|
|
|
|
public async Task<ICollection<Core.Entities.Send>> GetManyByDeletionDateAsync(DateTime deletionDateBefore)
|
|
{
|
|
using (var scope = ServiceScopeFactory.CreateScope())
|
|
{
|
|
var dbContext = GetDatabaseContext(scope);
|
|
var results = await dbContext.Sends.Where(s => s.DeletionDate < deletionDateBefore).ToListAsync();
|
|
return Mapper.Map<List<Core.Entities.Send>>(results);
|
|
}
|
|
}
|
|
|
|
public async Task<ICollection<Core.Entities.Send>> GetManyByUserIdAsync(Guid userId)
|
|
{
|
|
using (var scope = ServiceScopeFactory.CreateScope())
|
|
{
|
|
var dbContext = GetDatabaseContext(scope);
|
|
var results = await dbContext.Sends.Where(s => s.UserId == userId).ToListAsync();
|
|
return Mapper.Map<List<Core.Entities.Send>>(results);
|
|
}
|
|
}
|
|
}
|