merged LiebUserId with DiscordId
This commit is contained in:
parent
49374412b3
commit
d54ce50336
19 changed files with 109 additions and 142 deletions
|
@ -40,11 +40,11 @@ namespace Lieb.Data
|
|||
GuildWars2Account bloodseeker = new GuildWars2Account() { AccountName = "Bloodseeker.2043" };
|
||||
var users = new LiebUser[]
|
||||
{
|
||||
//new LiebUser{DiscordUserId=0, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
||||
new LiebUser{DiscordUserId=194863625477816321, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
||||
new LiebUser{Id=0, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
||||
//new LiebUser{Id=194863625477816321, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
||||
#if DEBUG
|
||||
new LiebUser{DiscordUserId=1, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}},
|
||||
new LiebUser{DiscordUserId=2, Name="Simon", GuildWars2Accounts = new List<GuildWars2Account>(){ bloodseeker}}
|
||||
new LiebUser{Id=1, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}},
|
||||
new LiebUser{Id=2, Name="Simon", GuildWars2Accounts = new List<GuildWars2Account>(){ bloodseeker}}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -59,18 +59,18 @@ namespace Lieb.Data
|
|||
|
||||
var assignments = new RoleAssignment[]
|
||||
{
|
||||
new RoleAssignment{LiebUserId = users[0].LiebUserId, LiebRoleId = AdminRoleId },
|
||||
new RoleAssignment{LiebUserId = users[0].LiebUserId, LiebRoleId = GuildLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[0].LiebUserId, LiebRoleId = RaidLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[0].LiebUserId, LiebRoleId = UserRoleId }
|
||||
new RoleAssignment{LiebUserId = users[0].Id, LiebRoleId = AdminRoleId },
|
||||
new RoleAssignment{LiebUserId = users[0].Id, LiebRoleId = GuildLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[0].Id, LiebRoleId = RaidLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[0].Id, LiebRoleId = UserRoleId }
|
||||
#if DEBUG
|
||||
,new RoleAssignment{LiebUserId = users[1].LiebUserId, LiebRoleId = AdminRoleId },
|
||||
new RoleAssignment{LiebUserId = users[1].LiebUserId, LiebRoleId = GuildLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[1].LiebUserId, LiebRoleId = RaidLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[1].LiebUserId, LiebRoleId = UserRoleId },
|
||||
new RoleAssignment{LiebUserId = users[2].LiebUserId, LiebRoleId = GuildLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[2].LiebUserId, LiebRoleId = RaidLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[2].LiebUserId, LiebRoleId = UserRoleId }
|
||||
,new RoleAssignment{LiebUserId = users[1].Id, LiebRoleId = AdminRoleId },
|
||||
new RoleAssignment{LiebUserId = users[1].Id, LiebRoleId = GuildLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[1].Id, LiebRoleId = RaidLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[1].Id, LiebRoleId = UserRoleId },
|
||||
new RoleAssignment{LiebUserId = users[2].Id, LiebRoleId = GuildLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[2].Id, LiebRoleId = RaidLeadRoleId },
|
||||
new RoleAssignment{LiebUserId = users[2].Id, LiebRoleId = UserRoleId }
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -158,11 +158,11 @@ namespace Lieb.Data
|
|||
|
||||
var signUps = new RaidSignUp[]
|
||||
{
|
||||
new RaidSignUp{GuildWars2AccountId = linaith.GuildWars2AccountId, LiebUserId = users[0].LiebUserId, RaidRoleId = ele.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp },
|
||||
new RaidSignUp{GuildWars2AccountId = hierpiepts.GuildWars2AccountId, LiebUserId = users[1].LiebUserId, RaidRoleId = flexTest1.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp },
|
||||
new RaidSignUp{GuildWars2AccountId = bloodseeker.GuildWars2AccountId, LiebUserId = users[2].LiebUserId, RaidRoleId = flexTest2.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp },
|
||||
new RaidSignUp{GuildWars2AccountId = hierpiepts.GuildWars2AccountId, LiebUserId = users[1].LiebUserId, RaidRoleId = flexTest2.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.Flex },
|
||||
new RaidSignUp{GuildWars2AccountId = bloodseeker.GuildWars2AccountId, LiebUserId = users[2].LiebUserId, RaidRoleId = flexTest3.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.Flex }
|
||||
new RaidSignUp{GuildWars2AccountId = linaith.GuildWars2AccountId, LiebUserId = users[0].Id, RaidRoleId = ele.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp },
|
||||
new RaidSignUp{GuildWars2AccountId = hierpiepts.GuildWars2AccountId, LiebUserId = users[1].Id, RaidRoleId = flexTest1.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp },
|
||||
new RaidSignUp{GuildWars2AccountId = bloodseeker.GuildWars2AccountId, LiebUserId = users[2].Id, RaidRoleId = flexTest2.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp },
|
||||
new RaidSignUp{GuildWars2AccountId = hierpiepts.GuildWars2AccountId, LiebUserId = users[1].Id, RaidRoleId = flexTest2.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.Flex },
|
||||
new RaidSignUp{GuildWars2AccountId = bloodseeker.GuildWars2AccountId, LiebUserId = users[2].Id, RaidRoleId = flexTest3.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.Flex }
|
||||
};
|
||||
|
||||
context.RaidSignUps.AddRange(signUps);
|
||||
|
|
|
@ -22,14 +22,14 @@ namespace Lieb.Data
|
|||
.FirstOrDefault(a => a.GuildWars2AccountId == gw2AccountId);
|
||||
}
|
||||
|
||||
public async Task AddOrEditAccount(GuildWars2Account account, int userId)
|
||||
public async Task AddOrEditAccount(GuildWars2Account account, ulong userId)
|
||||
{
|
||||
if (account != null)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
if (account.GuildWars2AccountId == 0)
|
||||
{
|
||||
LiebUser? user = context.LiebUsers.FirstOrDefault(u => u.LiebUserId == userId);
|
||||
LiebUser? user = context.LiebUsers.FirstOrDefault(u => u.Id == userId);
|
||||
if(user != null)
|
||||
{
|
||||
user.GuildWars2Accounts.Add(account);
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace Lieb.Data
|
|||
|
||||
private void RandomizeWithBoons(Raid raid)
|
||||
{
|
||||
Dictionary<int, GuildWars2Build> signedUpUsers= new Dictionary<int, GuildWars2Build>();
|
||||
Dictionary<ulong, GuildWars2Build> signedUpUsers= new Dictionary<ulong, GuildWars2Build>();
|
||||
foreach (RaidSignUp signUp in raid.SignUps)
|
||||
{
|
||||
if (signUp.GuildWars2Account.EquippedBuilds.Count > 0)
|
||||
|
@ -121,7 +121,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
private void BalanceRoles(Raid raid, Dictionary<int, GuildWars2Build> signedUpUsers, int recusrionDepth = 0)
|
||||
private void BalanceRoles(Raid raid, Dictionary<ulong, GuildWars2Build> signedUpUsers, int recusrionDepth = 0)
|
||||
{
|
||||
int Alac = 0;
|
||||
int Quick = 0;
|
||||
|
@ -180,7 +180,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
private void ReduceAlac(Raid raid, Dictionary<int, GuildWars2Build> signedUpUsers, int currentAlac)
|
||||
private void ReduceAlac(Raid raid, Dictionary<ulong, GuildWars2Build> signedUpUsers, int currentAlac)
|
||||
{
|
||||
foreach (var userBuild in signedUpUsers)
|
||||
{
|
||||
|
@ -198,7 +198,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
private void IncreaseAlac(Raid raid, Dictionary<int, GuildWars2Build> signedUpUsers, int currentAlac)
|
||||
private void IncreaseAlac(Raid raid, Dictionary<ulong, GuildWars2Build> signedUpUsers, int currentAlac)
|
||||
{
|
||||
foreach (var userBuild in signedUpUsers)
|
||||
{
|
||||
|
@ -216,7 +216,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
private void ReduceQuick(Raid raid, Dictionary<int, GuildWars2Build> signedUpUsers, int currentQuick)
|
||||
private void ReduceQuick(Raid raid, Dictionary<ulong, GuildWars2Build> signedUpUsers, int currentQuick)
|
||||
{
|
||||
foreach (var userBuild in signedUpUsers)
|
||||
{
|
||||
|
@ -234,7 +234,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
private void IncreaseQuick(Raid raid, Dictionary<int, GuildWars2Build> signedUpUsers, int currentQuick)
|
||||
private void IncreaseQuick(Raid raid, Dictionary<ulong, GuildWars2Build> signedUpUsers, int currentQuick)
|
||||
{
|
||||
foreach (var userBuild in signedUpUsers)
|
||||
{
|
||||
|
@ -252,7 +252,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
private void ReduceMight(Raid raid, Dictionary<int, GuildWars2Build> signedUpUsers, int currentMight)
|
||||
private void ReduceMight(Raid raid, Dictionary<ulong, GuildWars2Build> signedUpUsers, int currentMight)
|
||||
{
|
||||
foreach (var userBuild in signedUpUsers)
|
||||
{
|
||||
|
@ -270,7 +270,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
private void IncreaseMight(Raid raid, Dictionary<int, GuildWars2Build> signedUpUsers, int currentMight)
|
||||
private void IncreaseMight(Raid raid, Dictionary<ulong, GuildWars2Build> signedUpUsers, int currentMight)
|
||||
{
|
||||
foreach (var userBuild in signedUpUsers)
|
||||
{
|
||||
|
@ -288,7 +288,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
private void ReduceHeal(Raid raid, Dictionary<int, GuildWars2Build> signedUpUsers, int currentHeal)
|
||||
private void ReduceHeal(Raid raid, Dictionary<ulong, GuildWars2Build> signedUpUsers, int currentHeal)
|
||||
{
|
||||
foreach (var userBuild in signedUpUsers)
|
||||
{
|
||||
|
@ -306,7 +306,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
private void IncreaseHeal(Raid raid, Dictionary<int, GuildWars2Build> signedUpUsers, int currentHeal)
|
||||
private void IncreaseHeal(Raid raid, Dictionary<ulong, GuildWars2Build> signedUpUsers, int currentHeal)
|
||||
{
|
||||
foreach (var userBuild in signedUpUsers)
|
||||
{
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace Lieb.Data
|
|||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task SignUp(int raidId, int liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType)
|
||||
public async Task SignUp(int raidId, ulong liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType)
|
||||
{
|
||||
if (!IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true))
|
||||
{
|
||||
|
@ -117,7 +117,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
public async Task SignOff(int raidId, int liebUserId)
|
||||
public async Task SignOff(int raidId, ulong liebUserId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
//remove Flex Sign Ups
|
||||
|
@ -142,7 +142,7 @@ namespace Lieb.Data
|
|||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task ChangeAccount(int raidId, int liebUserId, int guildWars2AccountId)
|
||||
public async Task ChangeAccount(int raidId, ulong liebUserId, int guildWars2AccountId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
List<RaidSignUp> signUps = context.RaidSignUps.Where(x => x.RaidId == raidId && x.LiebUserId == liebUserId).ToList();
|
||||
|
@ -153,7 +153,7 @@ namespace Lieb.Data
|
|||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public void ChangeSignUpType(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType)
|
||||
public void ChangeSignUpType(int raidId, ulong liebUserId, int plannedRoleId, SignUpType signUpType)
|
||||
{
|
||||
if (!IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true))
|
||||
{
|
||||
|
@ -182,7 +182,7 @@ namespace Lieb.Data
|
|||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public bool IsRoleSignUpAllowed(int liebUserId, int plannedRoleId, SignUpType signUpType)
|
||||
public bool IsRoleSignUpAllowed(ulong liebUserId, int plannedRoleId, SignUpType signUpType)
|
||||
{
|
||||
if(signUpType == SignUpType.Backup || signUpType == SignUpType.Flex || signUpType == SignUpType.SignedOff)
|
||||
{
|
||||
|
@ -205,7 +205,7 @@ namespace Lieb.Data
|
|||
return signUps.Where(s => s.LiebUserId == liebUserId && s.SignUpType == SignUpType.SignedUp).Any();
|
||||
}
|
||||
|
||||
public bool IsRoleSignUpAllowed(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser)
|
||||
public bool IsRoleSignUpAllowed(int raidId, ulong liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
Raid? raid = context.Raids
|
||||
|
@ -243,7 +243,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<bool> IsRoleSignUpAllowed(Raid raid, int liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser, List<int> checkedRoleIds)
|
||||
private async Task<bool> IsRoleSignUpAllowed(Raid raid, ulong liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser, List<int> checkedRoleIds)
|
||||
{
|
||||
if (IsRoleSignUpAllowed(liebUserId, plannedRoleId, signUpType))
|
||||
return true;
|
||||
|
@ -257,7 +257,7 @@ namespace Lieb.Data
|
|||
return false;
|
||||
}
|
||||
|
||||
foreach (int userId in raid.SignUps.Where(s => s.RaidRoleId == plannedRoleId && s.SignUpType == SignUpType.SignedUp).Select(s => s.LiebUserId))
|
||||
foreach (ulong userId in raid.SignUps.Where(s => s.RaidRoleId == plannedRoleId && s.SignUpType == SignUpType.SignedUp).Select(s => s.LiebUserId))
|
||||
{
|
||||
foreach (RaidSignUp signUp in raid.SignUps.Where(s => s.LiebUserId == userId && s.SignUpType == SignUpType.Flex))
|
||||
{
|
||||
|
@ -275,7 +275,7 @@ namespace Lieb.Data
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool IsRaidSignUpAllowed(int liebUserId, int raidId, out string errorMessage)
|
||||
public bool IsRaidSignUpAllowed(ulong liebUserId, int raidId, out string errorMessage)
|
||||
{
|
||||
errorMessage = string.Empty;
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
|
@ -293,7 +293,7 @@ namespace Lieb.Data
|
|||
.Include(u => u.GuildWars2Accounts)
|
||||
.ThenInclude(a => a.EquippedBuilds)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(r => r.LiebUserId == liebUserId);
|
||||
.FirstOrDefault(r => r.Id == liebUserId);
|
||||
if (user == null)
|
||||
{
|
||||
errorMessage = "User not found.";
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace Lieb.Data
|
|||
.ToList();
|
||||
}
|
||||
|
||||
public LiebUser GetLiebUser(ulong discordId)
|
||||
public LiebUser GetLiebUser(ulong userId)
|
||||
{
|
||||
if (discordId > 0)
|
||||
if (userId > 0)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
return context.LiebUsers
|
||||
|
@ -36,56 +36,48 @@ namespace Lieb.Data
|
|||
.ThenInclude(b => b.GuildWars2Build)
|
||||
.Include(u => u.RoleAssignments)
|
||||
.ThenInclude(r => r.LiebRole)
|
||||
.FirstOrDefault(u => u.DiscordUserId == discordId);
|
||||
.FirstOrDefault(u => u.Id == userId);
|
||||
}
|
||||
else
|
||||
return new LiebUser();
|
||||
}
|
||||
|
||||
public LiebUser GetLiebUser(int userId)
|
||||
public LiebUser GetLiebUserGW2AccountOnly(ulong userId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
return context.LiebUsers
|
||||
.Include(u => u.GuildWars2Accounts)
|
||||
.ThenInclude(a => a.EquippedBuilds)
|
||||
.ThenInclude(b => b.GuildWars2Build)
|
||||
.Include(u => u.RoleAssignments)
|
||||
.ThenInclude(r => r.LiebRole)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(u => u.LiebUserId == userId);
|
||||
}
|
||||
|
||||
public LiebUser GetLiebUserGW2AccountOnly(ulong discordId)
|
||||
{
|
||||
if (discordId > 0)
|
||||
if (userId > 0)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
return context.LiebUsers
|
||||
.Include(u => u.GuildWars2Accounts)
|
||||
.ThenInclude(a => a.EquippedBuilds)
|
||||
.FirstOrDefault(u => u.DiscordUserId == discordId);
|
||||
.FirstOrDefault(u => u.Id == userId);
|
||||
}
|
||||
else
|
||||
return new LiebUser();
|
||||
}
|
||||
|
||||
public LiebUser GetLiebGW2AccountOnly(int userId)
|
||||
public async Task CreateUser(ulong discordId, string userName)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
return context.LiebUsers
|
||||
.Include(u => u.GuildWars2Accounts)
|
||||
.FirstOrDefault(u => u.LiebUserId == userId);
|
||||
}
|
||||
|
||||
public async Task<int> GetLiebUserId(ulong discordId)
|
||||
{
|
||||
if (discordId > 0)
|
||||
LiebUser newUser = new LiebUser()
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
return (await context.LiebUsers.FirstOrDefaultAsync(u => u.DiscordUserId == discordId)).LiebUserId;
|
||||
Id = discordId,
|
||||
Name = userName
|
||||
};
|
||||
context.LiebUsers.Add(newUser);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
LiebRole standardRole = await context.LiebRoles.FirstOrDefaultAsync(m => m.RoleName == Constants.Roles.User.Name);
|
||||
if (standardRole != null)
|
||||
{
|
||||
RoleAssignment roleAssignment = new RoleAssignment()
|
||||
{
|
||||
LiebRoleId = standardRole.LiebRoleId,
|
||||
LiebUserId = newUser.Id
|
||||
};
|
||||
context.RoleAssignments.Add(roleAssignment);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
public async Task EditUser(LiebUser user)
|
||||
|
@ -93,7 +85,7 @@ namespace Lieb.Data
|
|||
using var context = _contextFactory.CreateDbContext();
|
||||
LiebUser? userToChange = context.LiebUsers
|
||||
.Include(u => u.GuildWars2Accounts)
|
||||
.FirstOrDefault(u => u.LiebUserId == user.LiebUserId);
|
||||
.FirstOrDefault(u => u.Id == user.Id);
|
||||
|
||||
if(userToChange != null)
|
||||
{
|
||||
|
@ -104,10 +96,10 @@ namespace Lieb.Data
|
|||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task UpdateBannedUntil(int userId, DateTime? date)
|
||||
public async Task UpdateBannedUntil(ulong userId, DateTime? date)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
LiebUser? user = await context.LiebUsers.FirstOrDefaultAsync(u => u.LiebUserId == userId);
|
||||
LiebUser? user = await context.LiebUsers.FirstOrDefaultAsync(u => u.Id == userId);
|
||||
|
||||
if (user == null)
|
||||
return;
|
||||
|
@ -117,12 +109,12 @@ namespace Lieb.Data
|
|||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task AddRoleToUser(int userId, int roleId)
|
||||
public async Task AddRoleToUser(ulong userId, int roleId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
LiebUser? user = await context.LiebUsers
|
||||
.Include(u => u.RoleAssignments)
|
||||
.FirstOrDefaultAsync(u => u.LiebUserId == userId);
|
||||
.FirstOrDefaultAsync(u => u.Id == userId);
|
||||
user.RoleAssignments.Add(new RoleAssignment()
|
||||
{
|
||||
LiebUserId = userId,
|
||||
|
@ -131,12 +123,12 @@ namespace Lieb.Data
|
|||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task RemoveRoleFromUser(int userId, int roleId)
|
||||
public async Task RemoveRoleFromUser(ulong userId, int roleId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
LiebUser? user = await context.LiebUsers
|
||||
.Include(u => u.RoleAssignments)
|
||||
.FirstOrDefaultAsync(u => u.LiebUserId == userId);
|
||||
.FirstOrDefaultAsync(u => u.Id == userId);
|
||||
RoleAssignment assignmentToRemove = user.RoleAssignments.FirstOrDefault(r => r.LiebRoleId == roleId);
|
||||
if(assignmentToRemove != null)
|
||||
{
|
||||
|
@ -145,29 +137,14 @@ namespace Lieb.Data
|
|||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public int GetPowerLevel(int userId)
|
||||
public int GetPowerLevel(ulong userId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
LiebUser? user = context.LiebUsers
|
||||
.Include(u => u.RoleAssignments)
|
||||
.ThenInclude(r => r.LiebRole)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(u => u.LiebUserId == userId);
|
||||
if (user != null)
|
||||
{
|
||||
return user.RoleAssignments.Max(a => a.LiebRole.Level);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int GetPowerLevel(ulong discordId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
LiebUser? user = context.LiebUsers
|
||||
.Include(u => u.RoleAssignments)
|
||||
.ThenInclude(r => r.LiebRole)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(u => u.DiscordUserId == discordId);
|
||||
.FirstOrDefault(u => u.Id == userId);
|
||||
if (user != null)
|
||||
{
|
||||
return user.RoleAssignments.Max(a => a.LiebRole.Level);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue