added RaidDetails.razor + needed services
This commit is contained in:
parent
6da9b06e8a
commit
b18cc58665
15 changed files with 597 additions and 18 deletions
56
Lieb/Data/UserService.cs
Normal file
56
Lieb/Data/UserService.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
using Lieb.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Lieb.Data
|
||||
{
|
||||
public class UserService
|
||||
{
|
||||
private readonly IDbContextFactory<LiebContext> _contextFactory;
|
||||
|
||||
public UserService(IDbContextFactory<LiebContext> contextFactory)
|
||||
{
|
||||
_contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
public async Task<LiebUser> GetLiebUser(ulong discordId)
|
||||
{
|
||||
if (discordId > 0)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
return await context.LiebUsers
|
||||
.Include(u => u.GuildWars2Accounts)
|
||||
.ThenInclude(a => a.EquippedBuilds)
|
||||
.ThenInclude(b => b.GuildWars2Build)
|
||||
.Include(u => u.RoleAssignments)
|
||||
.ThenInclude(r => r.LiebRole)
|
||||
.FirstOrDefaultAsync(u => u.DiscordUserId == discordId);
|
||||
}
|
||||
else
|
||||
return new LiebUser();
|
||||
}
|
||||
|
||||
public LiebUser GetLiebUserSmall(ulong discordId)
|
||||
{
|
||||
if (discordId > 0)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
return context.LiebUsers
|
||||
.Include(u => u.GuildWars2Accounts)
|
||||
.FirstOrDefault(u => u.DiscordUserId == discordId);
|
||||
}
|
||||
else
|
||||
return new LiebUser();
|
||||
}
|
||||
|
||||
public async Task<int> GetLiebUserId(ulong discordId)
|
||||
{
|
||||
if (discordId > 0)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
return (await context.LiebUsers.FirstOrDefaultAsync(u => u.DiscordUserId == discordId)).LiebUserId;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue