fixed Add external user command
This commit is contained in:
parent
a504925752
commit
f40903851e
9 changed files with 122 additions and 39 deletions
|
@ -159,11 +159,11 @@ namespace Lieb.Data
|
|||
|
||||
var signUps = new RaidSignUp[]
|
||||
{
|
||||
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 }
|
||||
new RaidSignUp(raid.RaidId, users[0].Id, linaith.GuildWars2AccountId, ele.RaidRoleId, SignUpType.SignedUp),
|
||||
new RaidSignUp(raid.RaidId, users[1].Id, hierpiepts.GuildWars2AccountId, flexTest1.RaidRoleId, SignUpType.SignedUp),
|
||||
new RaidSignUp(raid.RaidId, users[2].Id, bloodseeker.GuildWars2AccountId, flexTest2.RaidRoleId, SignUpType.SignedUp),
|
||||
new RaidSignUp(raid.RaidId, users[1].Id, hierpiepts.GuildWars2AccountId, flexTest2.RaidRoleId, SignUpType.Flex),
|
||||
new RaidSignUp(raid.RaidId, users[2].Id, bloodseeker.GuildWars2AccountId, flexTest3.RaidRoleId, SignUpType.Flex)
|
||||
};
|
||||
|
||||
context.RaidSignUps.AddRange(signUps);
|
||||
|
|
|
@ -240,7 +240,7 @@ namespace Lieb.Data
|
|||
AccountName = signUp.GuildWars2Account.AccountName,
|
||||
Status = status,
|
||||
UserName = signUp.LiebUser.Name,
|
||||
UserId = signUp.LiebUserId
|
||||
UserId = signUp.LiebUserId.Value
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -274,9 +274,9 @@ namespace Lieb.Data
|
|||
apiReminder.UserIds = new List<ulong>();
|
||||
foreach(RaidSignUp signUp in raid.SignUps)
|
||||
{
|
||||
if(signUp.LiebUserId > 0)
|
||||
if(signUp.LiebUserId.HasValue)
|
||||
{
|
||||
apiReminder.UserIds.Add(signUp.LiebUserId);
|
||||
apiReminder.UserIds.Add(signUp.LiebUserId.Value);
|
||||
}
|
||||
}
|
||||
return apiReminder;
|
||||
|
|
|
@ -104,9 +104,9 @@ namespace Lieb.Data
|
|||
Dictionary<ulong, GuildWars2Build> signedUpUsers= new Dictionary<ulong, GuildWars2Build>();
|
||||
foreach (RaidSignUp signUp in raid.SignUps)
|
||||
{
|
||||
if (signUp.GuildWars2Account.EquippedBuilds.Count > 0)
|
||||
if (!signUp.IsExternalUser && signUp.GuildWars2Account.EquippedBuilds.Count > 0)
|
||||
{
|
||||
signedUpUsers.Add(signUp.LiebUserId, signUp.GuildWars2Account.EquippedBuilds.ToList()[_random.Next(signUp.GuildWars2Account.EquippedBuilds.Count - 1)].GuildWars2Build);
|
||||
signedUpUsers.Add(signUp.LiebUserId.Value, signUp.GuildWars2Account.EquippedBuilds.ToList()[_random.Next(signUp.GuildWars2Account.EquippedBuilds.Count - 1)].GuildWars2Build);
|
||||
}
|
||||
}
|
||||
BalanceRoles(raid, signedUpUsers);
|
||||
|
|
|
@ -117,14 +117,7 @@ namespace Lieb.Data
|
|||
}
|
||||
else if (!signUps.Where(r => r.RaidRoleId == plannedRoleId).Any())
|
||||
{
|
||||
RaidSignUp signUp = new RaidSignUp()
|
||||
{
|
||||
GuildWars2AccountId = guildWars2AccountId,
|
||||
RaidId = raidId,
|
||||
LiebUserId = liebUserId,
|
||||
RaidRoleId = plannedRoleId,
|
||||
SignUpType = signUpType
|
||||
};
|
||||
RaidSignUp signUp = new RaidSignUp(raidId, liebUserId, guildWars2AccountId, plannedRoleId, signUpType);
|
||||
string userName = context.LiebUsers.FirstOrDefault(l => l.Id == liebUserId)?.Name;
|
||||
context.RaidSignUps.Add(signUp);
|
||||
await context.SaveChangesAsync();
|
||||
|
@ -142,13 +135,7 @@ namespace Lieb.Data
|
|||
using var context = _contextFactory.CreateDbContext();
|
||||
|
||||
|
||||
RaidSignUp signUp = new RaidSignUp()
|
||||
{
|
||||
RaidId = raidId,
|
||||
ExternalUserName = userName,
|
||||
RaidRoleId = plannedRoleId,
|
||||
SignUpType = signUpType
|
||||
};
|
||||
RaidSignUp signUp = new RaidSignUp(raidId, userName, plannedRoleId, signUpType);
|
||||
context.RaidSignUps.Add(signUp);
|
||||
await context.SaveChangesAsync();
|
||||
await LogSignUp(signUp, userName, signedUpByUserId);
|
||||
|
@ -235,7 +222,14 @@ namespace Lieb.Data
|
|||
{
|
||||
signUp.RaidRoleId = plannedRoleId;
|
||||
signUp.SignUpType = signUpType;
|
||||
await LogSignUp(signUp, signUp.LiebUser.Name);
|
||||
if(signUp.IsExternalUser)
|
||||
{
|
||||
await LogSignUp(signUp, signUp.ExternalUserName);
|
||||
}
|
||||
else
|
||||
{
|
||||
await LogSignUp(signUp, signUp.LiebUser.Name);
|
||||
}
|
||||
}
|
||||
context.SaveChanges();
|
||||
if(postChanges)
|
||||
|
@ -337,7 +331,7 @@ namespace Lieb.Data
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool IsRaidSignUpAllowed(ulong liebUserId, int raidId, out string errorMessage)
|
||||
public bool IsRaidSignUpAllowed(ulong liebUserId, int raidId, out string errorMessage, bool ignoreRole = false)
|
||||
{
|
||||
errorMessage = string.Empty;
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
|
@ -374,7 +368,7 @@ namespace Lieb.Data
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(raid.RequiredRole)
|
||||
if (!ignoreRole && !string.IsNullOrEmpty(raid.RequiredRole)
|
||||
&& !user.RoleAssignments.Where(a => a.LiebRole.RoleName == raid.RequiredRole).Any()
|
||||
&& raid.FreeForAllTimeUTC.UtcDateTime > DateTimeOffset.UtcNow)
|
||||
{
|
||||
|
@ -392,9 +386,37 @@ namespace Lieb.Data
|
|||
return true;
|
||||
}
|
||||
|
||||
public bool IsExternalSignUpAllowed(int raidId, out string errorMessage)
|
||||
{
|
||||
errorMessage = string.Empty;
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
Raid? raid = context.Raids
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(r => r.RaidId == raidId);
|
||||
if(raid == null)
|
||||
{
|
||||
errorMessage = "Raid not found.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (raid.RaidType != RaidType.Planned)
|
||||
{
|
||||
errorMessage = "Random raids need an Account with equipped builds.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if(raid.EndTimeUTC < DateTimeOffset.UtcNow)
|
||||
{
|
||||
errorMessage = $"The raid already ended.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task LogSignUp(RaidSignUp signUp, string userName, ulong signedUpBy = 0)
|
||||
{
|
||||
ulong userId = signedUpBy > 0 ? signedUpBy : signUp.LiebUserId;
|
||||
ulong userId = signedUpBy > 0 ? signedUpBy : signUp.LiebUserId.Value;
|
||||
RaidLog log = RaidLog.CreateSignUpLog(userId, signUp, userName);
|
||||
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue