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);
|
||||
|
|
|
@ -13,12 +13,14 @@ namespace Discord.OAuth2
|
|||
{
|
||||
internal class DiscordHandler : OAuthHandler<DiscordOptions>
|
||||
{
|
||||
private readonly Lieb.Data.LiebContext _LiebDbcontext;
|
||||
private readonly LiebContext _dbContext;
|
||||
private readonly UserService _userService;
|
||||
|
||||
public DiscordHandler(IOptionsMonitor<DiscordOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, Lieb.Data.LiebContext context)
|
||||
public DiscordHandler(IOptionsMonitor<DiscordOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, LiebContext context, UserService userService)
|
||||
: base(options, logger, encoder, clock)
|
||||
{
|
||||
_LiebDbcontext = context;
|
||||
_dbContext = context;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens)
|
||||
|
@ -48,7 +50,7 @@ namespace Discord.OAuth2
|
|||
private async Task<OAuthCreatingTicketContext> ManageUserRights(OAuthCreatingTicketContext context)
|
||||
{
|
||||
ulong discordId = ulong.Parse(context.Identity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value);
|
||||
LiebUser? user = await _LiebDbcontext.LiebUsers.Include(u => u.RoleAssignments).ThenInclude(r => r.LiebRole).FirstOrDefaultAsync(m => m.DiscordUserId == discordId);
|
||||
LiebUser? user = await _dbContext.LiebUsers.Include(u => u.RoleAssignments).ThenInclude(r => r.LiebRole).FirstOrDefaultAsync(m => m.Id == discordId);
|
||||
if (user != null)
|
||||
{
|
||||
if (user.BannedUntil == null || user.BannedUntil < DateTime.UtcNow)
|
||||
|
@ -61,22 +63,9 @@ namespace Discord.OAuth2
|
|||
}
|
||||
else
|
||||
{
|
||||
LiebRole standardRole = await _LiebDbcontext.LiebRoles.FirstOrDefaultAsync(m => m.RoleName == Constants.Roles.User.Name);
|
||||
string userName = context.Identity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Name).Value;
|
||||
LiebUser newUser = new LiebUser()
|
||||
{
|
||||
DiscordUserId = discordId,
|
||||
Name = userName
|
||||
};
|
||||
_LiebDbcontext.LiebUsers.Add(newUser);
|
||||
await _LiebDbcontext.SaveChangesAsync();
|
||||
RoleAssignment roleAssignment = new RoleAssignment()
|
||||
{
|
||||
LiebRoleId = standardRole.LiebRoleId,
|
||||
LiebUserId = newUser.LiebUserId
|
||||
};
|
||||
_LiebDbcontext.RoleAssignments.Add(roleAssignment);
|
||||
await _LiebDbcontext.SaveChangesAsync();
|
||||
|
||||
_userService.CreateUser(discordId, userName);
|
||||
|
||||
context.Identity.AddClaim(new Claim(Constants.ClaimType, Constants.Roles.User.Name));
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
@if (_user != null && _isRaidSignUpAllowed)
|
||||
{
|
||||
<div class="signUpStatusTooltip">
|
||||
@if(_raid.SignUps.Where(s => s.LiebUserId == _user.LiebUserId && s.SignUpType != SignUpType.SignedOff).Any())
|
||||
@if(_raid.SignUps.Where(s => s.LiebUserId == _user.Id && s.SignUpType != SignUpType.SignedOff).Any())
|
||||
{
|
||||
<span class="oi oi-badge" style="color:green"></span>
|
||||
<span class="tooltiptext">You are signed up</span>
|
||||
|
@ -76,7 +76,7 @@
|
|||
<AuthorizeView>
|
||||
<button class="controlButton raidButton" @onclick="() => SignOffClicked()">Sign Off</button>
|
||||
|
||||
@if (_raid.RaidOwnerId == _user.LiebUserId || _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel)
|
||||
@if (_raid.RaidOwnerId == _user.Id || _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel)
|
||||
{
|
||||
<button class="controlButton raidButton" @onclick="() => EditClicked()">Edit</button>
|
||||
@if (_raid.RaidType != RaidType.Planned)
|
||||
|
@ -108,7 +108,7 @@
|
|||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
_isRaidSignUpAllowed = _user != null && RaidService.IsRaidSignUpAllowed(_user.LiebUserId, _raid.RaidId, out _errorMessage);
|
||||
_isRaidSignUpAllowed = _user != null && RaidService.IsRaidSignUpAllowed(_user.Id, _raid.RaidId, out _errorMessage);
|
||||
|
||||
_startTime = await TimeZoneService.GetLocalDateTime(_raid.StartTimeUTC);
|
||||
_endTime = await TimeZoneService.GetLocalDateTime(_raid.EndTimeUTC);
|
||||
|
@ -117,7 +117,7 @@
|
|||
|
||||
async Task SignOffClicked()
|
||||
{
|
||||
await RaidService.SignOff(_raid.RaidId, _user.LiebUserId);
|
||||
await RaidService.SignOff(_raid.RaidId, _user.Id);
|
||||
_raid = RaidService.GetRaid(_raid.RaidId);
|
||||
}
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@
|
|||
{
|
||||
_raid = RaidService.GetRaid(parsedId);
|
||||
|
||||
if (_raid != null && (_raid.RaidOwnerId == _user.LiebUserId
|
||||
if (_raid != null && (_raid.RaidOwnerId == _user.Id
|
||||
|| _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel))
|
||||
{
|
||||
_startTime = await TimeZoneService.GetLocalDateTime(_raid.StartTimeUTC);
|
||||
|
@ -273,7 +273,7 @@
|
|||
|
||||
if (_raid.RaidOwnerId == 0)
|
||||
{
|
||||
_raid.RaidOwnerId = _user.LiebUserId;
|
||||
_raid.RaidOwnerId = _user.Id;
|
||||
}
|
||||
|
||||
await RaidService.AddOrEditRaid(_raid, _rolesToDelete, new List<RaidReminder>());
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
[Parameter]
|
||||
public bool _isRaidSignUpAllowed { get; set; }
|
||||
|
||||
private int _liebUserId { get; set; } = -1;
|
||||
private ulong _liebUserId { get; set; } = 0;
|
||||
|
||||
private List<GuildWars2Account> _usableAccounts;
|
||||
|
||||
|
@ -125,7 +125,7 @@
|
|||
{
|
||||
_usableAccounts = _user.GuildWars2Accounts.Where(a => a.EquippedBuilds.Count > 0).ToList();
|
||||
}
|
||||
_liebUserId = _user.LiebUserId;
|
||||
_liebUserId = _user.Id;
|
||||
}
|
||||
_expandableRoles = new List<ExpandableRole>();
|
||||
foreach(RaidRole role in _raid.Roles)
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
|
||||
|
||||
<AuthorizeView>
|
||||
@if (_template.RaidOwnerId == _user.LiebUserId || _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel)
|
||||
@if (_template.RaidOwnerId == _user.Id || _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel)
|
||||
{
|
||||
<button class="controlButton raidButton" @onclick="() => EditClicked()">Edit</button>
|
||||
}
|
||||
|
|
|
@ -210,7 +210,7 @@
|
|||
{
|
||||
_template = RaidTemplateService.GetTemplate(parsedId);
|
||||
|
||||
if (_template != null && (_template.RaidOwnerId == _user.LiebUserId
|
||||
if (_template != null && (_template.RaidOwnerId == _user.Id
|
||||
|| _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel))
|
||||
{
|
||||
_startTime = _template.StartTime;
|
||||
|
@ -290,7 +290,7 @@
|
|||
|
||||
if (_template.RaidOwnerId == 0)
|
||||
{
|
||||
_template.RaidOwnerId = _user.LiebUserId;
|
||||
_template.RaidOwnerId = _user.Id;
|
||||
}
|
||||
|
||||
await RaidTemplateService.AddOrEditTemplate(_template, _rolesToDelete, new List<RaidReminder>());
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
public Raid _raid { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public int _liebUserId { get; set; } = -1;
|
||||
public ulong _liebUserId { get; set; } = 0;
|
||||
|
||||
[Parameter]
|
||||
public List<GuildWars2Account> _usableAccounts { get; set; }
|
||||
|
|
|
@ -161,7 +161,7 @@
|
|||
|
||||
private async Task HandleValidSubmit()
|
||||
{
|
||||
await GuildWars2AccountService.AddOrEditAccount(_account, _user.LiebUserId);
|
||||
await GuildWars2AccountService.AddOrEditAccount(_account, _user.Id);
|
||||
_account = GuildWars2AccountService.GetAccount(_account.GuildWars2AccountId);
|
||||
_saveMessage = "changes saved successfully";
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
@code {
|
||||
|
||||
[Parameter]
|
||||
public string userId { get; set; }
|
||||
public string _userId { get; set; }
|
||||
|
||||
private LiebUser _user;
|
||||
private int _editingUserRights = 0;
|
||||
|
@ -85,7 +85,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
if(!string.IsNullOrEmpty(userId) && int.TryParse(userId, out int parsedId))
|
||||
if(!string.IsNullOrEmpty(_userId) && ulong.TryParse(_userId, out ulong parsedId))
|
||||
{
|
||||
_user = UserService.GetLiebUser(parsedId);
|
||||
_roles = UserService.GetLiebRoles();
|
||||
|
@ -105,21 +105,21 @@
|
|||
RoleAssignment roleAssignment = new RoleAssignment()
|
||||
{
|
||||
LiebRoleId = role.LiebRoleId,
|
||||
LiebUserId = _user.LiebUserId
|
||||
LiebUserId = _user.Id
|
||||
};
|
||||
await UserService.AddRoleToUser(_user.LiebUserId, role.LiebRoleId);
|
||||
await UserService.AddRoleToUser(_user.Id, role.LiebRoleId);
|
||||
_user.RoleAssignments.Add(roleAssignment);
|
||||
}
|
||||
else if(!isChecked && assignment != null)
|
||||
{
|
||||
await UserService.RemoveRoleFromUser(_user.LiebUserId, role.LiebRoleId);
|
||||
await UserService.RemoveRoleFromUser(_user.Id, role.LiebRoleId);
|
||||
_user.RoleAssignments.Remove(assignment);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleValidSubmit()
|
||||
{
|
||||
await UserService.UpdateBannedUntil(_user.LiebUserId, _user.BannedUntil);
|
||||
await UserService.UpdateBannedUntil(_user.Id, _user.BannedUntil);
|
||||
if(_user.BannedUntil >= DateTime.Now.Date)
|
||||
{
|
||||
_submitMessage = "user banned successfully";
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
{
|
||||
<tr>
|
||||
<td class="nav-item px-3">
|
||||
@{string navLink = $"useredit/{@user.LiebUserId}";}
|
||||
@{string navLink = $"useredit/{@user.Id}";}
|
||||
<NavLink class="nav-link" href="@navLink">@user.Name</NavLink>
|
||||
</td>
|
||||
<td>@foreach(var account in user.GuildWars2Accounts){<div>@account.AccountName </div> }</td>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue