Files
SVSimServer/SVSim.Database/Repositories/Viewer/ViewerRepository.cs
2024-09-12 00:35:31 -04:00

36 lines
1.3 KiB
C#

using Microsoft.EntityFrameworkCore;
using SVSim.Database.Enums;
using SVSim.Database.Models;
namespace SVSim.Database.Repositories.Viewer;
public class ViewerRepository : IViewerRepository
{
protected readonly SVSimDbContext _dbContext;
public ViewerRepository(SVSimDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task<Models.Viewer?> GetViewerBySocialConnection(SocialAccountType accountType, ulong socialId)
{
return (await _dbContext.Set<SocialAccountConnection>()
.AsNoTracking()
.Include(sac => sac.Viewer)
.FirstOrDefaultAsync(sac => sac.AccountType == accountType && sac.AccountId == socialId))
?.Viewer;
}
public async Task<Models.Viewer?> GetViewerWithSocials(ulong id)
{
return await _dbContext.Set<Models.Viewer>().AsNoTracking().Include(viewer => viewer.SocialAccountConnections)
.FirstOrDefaultAsync(viewer => viewer.Id == id);
}
public async Task<Models.Viewer?> GetViewerByShortUdid(ulong shortUdid)
{
return await _dbContext.Set<Models.Viewer>().AsNoTracking().Include(viewer => viewer.MissionData)
.Include(viewer => viewer.Info).FirstOrDefaultAsync(viewer => viewer.ShortUdid == shortUdid);
}
}