added support for External users

fixed potential errors
This commit is contained in:
Sarah Faey 2022-11-13 21:48:56 +01:00
parent a47bc3207d
commit 62dc3d1efa
10 changed files with 257 additions and 130 deletions

View file

@ -40,8 +40,8 @@ namespace Lieb.Data
GuildWars2Account bloodseeker = new GuildWars2Account() { AccountName = "Bloodseeker.2043" }; GuildWars2Account bloodseeker = new GuildWars2Account() { AccountName = "Bloodseeker.2043" };
var users = new LiebUser[] var users = new LiebUser[]
{ {
new LiebUser{Id=0, 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} }, new LiebUser{Id=194863625477816321, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
#if DEBUG #if DEBUG
new LiebUser{Id=194455125769715713, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}}, new LiebUser{Id=194455125769715713, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}},
new LiebUser{Id=2, Name="Simon", GuildWars2Accounts = new List<GuildWars2Account>(){ bloodseeker}} new LiebUser{Id=2, Name="Simon", GuildWars2Accounts = new List<GuildWars2Account>(){ bloodseeker}}

View file

@ -26,43 +26,44 @@ namespace Lieb.Data
public async Task PostRaidMessage(int raidId) public async Task PostRaidMessage(int raidId)
{ {
using var context = _contextFactory.CreateDbContext(); try
Raid raid = context.Raids
.Include(r => r.Roles)
.Include(r => r.SignUps)
.ThenInclude(s => s.LiebUser)
.Include(r => r.SignUps)
.ThenInclude(s => s.GuildWars2Account)
.Include(r => r.SignUps)
.ThenInclude(s => s.RaidRole)
.Include(r => r.DiscordRaidMessages)
.FirstOrDefault(r => r.RaidId == raidId);
await PostRaidMessage(raid);
}
public async Task PostRaidMessage(Raid raid)
{
var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName);
ApiRaid apiRaid = ConvertRaid(raid);
var raidItemJson = new StringContent(
JsonSerializer.Serialize(apiRaid),
Encoding.UTF8,
Application.Json);
string json = JsonSerializer.Serialize(apiRaid);
var httpResponseMessage = await httpClient.PostAsync("raid/PostRaidMessage", raidItemJson);
if (httpResponseMessage.IsSuccessStatusCode)
{ {
using var contentStream = using var context = _contextFactory.CreateDbContext();
await httpResponseMessage.Content.ReadAsStreamAsync(); Raid raid = context.Raids
.Include(r => r.Roles)
.Include(r => r.SignUps)
.ThenInclude(s => s.LiebUser)
.Include(r => r.SignUps)
.ThenInclude(s => s.GuildWars2Account)
.Include(r => r.SignUps)
.ThenInclude(s => s.RaidRole)
.Include(r => r.DiscordRaidMessages)
.ToList()
.FirstOrDefault(r => r.RaidId == raidId, new Raid());
ApiRaid returnedRaid = await JsonSerializer.DeserializeAsync<ApiRaid>(contentStream, _serializerOptions); var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName);
await UpdateDiscordMessages(returnedRaid.DisocrdMessages, raid);
ApiRaid apiRaid = ConvertRaid(raid);
var raidItemJson = new StringContent(
JsonSerializer.Serialize(apiRaid),
Encoding.UTF8,
Application.Json);
string json = JsonSerializer.Serialize(apiRaid);
var httpResponseMessage = await httpClient.PostAsync("raid/PostRaidMessage", raidItemJson);
if (httpResponseMessage.IsSuccessStatusCode)
{
using var contentStream =
await httpResponseMessage.Content.ReadAsStreamAsync();
ApiRaid returnedRaid = await JsonSerializer.DeserializeAsync<ApiRaid>(contentStream, _serializerOptions);
await UpdateDiscordMessages(returnedRaid.DisocrdMessages, raid);
}
} }
catch {}
} }
public async Task DeleteRaidMessages(Raid raid) public async Task DeleteRaidMessages(Raid raid)
@ -72,18 +73,22 @@ namespace Lieb.Data
public async Task DeleteRaidMessages(IEnumerable<DiscordRaidMessage> messages) public async Task DeleteRaidMessages(IEnumerable<DiscordRaidMessage> messages)
{ {
var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName); try
{
var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName);
IEnumerable<ApiRaid.DiscordMessage> apiMessages = ConvertMessages(messages); IEnumerable<ApiRaid.DiscordMessage> apiMessages = ConvertMessages(messages);
var messageItemJson = new StringContent( var messageItemJson = new StringContent(
JsonSerializer.Serialize(apiMessages), JsonSerializer.Serialize(apiMessages),
Encoding.UTF8, Encoding.UTF8,
Application.Json); Application.Json);
var httpResponseMessage = await httpClient.PostAsync("raid/DeleteRaidMessage", messageItemJson); var httpResponseMessage = await httpClient.PostAsync("raid/DeleteRaidMessage", messageItemJson);
httpResponseMessage.EnsureSuccessStatusCode(); httpResponseMessage.EnsureSuccessStatusCode();
}
catch {}
} }
public async Task<List<DiscordServer>> GetServers() public async Task<List<DiscordServer>> GetServers()
@ -102,62 +107,67 @@ namespace Lieb.Data
return await JsonSerializer.DeserializeAsync<List<DiscordServer>>(contentStream, _serializerOptions); return await JsonSerializer.DeserializeAsync<List<DiscordServer>>(contentStream, _serializerOptions);
} }
} }
catch(Exception e) catch {}
{
}
return new List<DiscordServer>(); return new List<DiscordServer>();
} }
public async Task SendUserReminder(RaidReminder reminder) public async Task SendUserReminder(RaidReminder reminder)
{ {
using var context = _contextFactory.CreateDbContext(); try
var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName);
Raid raid = context.Raids
.Include(r => r.SignUps)
.ThenInclude(s => s.LiebUser)
.FirstOrDefault(r => r.RaidId == reminder.RaidId);
if(raid == null) return;
ApiUserReminder apiReminder = ConvertUserReminder(reminder, raid);
var raidItemJson = new StringContent(
JsonSerializer.Serialize(apiReminder),
Encoding.UTF8,
Application.Json);
var httpResponseMessage = await httpClient.PostAsync("raid/SendUserReminder", raidItemJson);
if (httpResponseMessage.IsSuccessStatusCode)
{ {
reminder.Sent = true; using var context = _contextFactory.CreateDbContext();
context.Update(reminder); var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName);
await context.SaveChangesAsync();
Raid raid = context.Raids
.Include(r => r.SignUps)
.ThenInclude(s => s.LiebUser)
.FirstOrDefault(r => r.RaidId == reminder.RaidId);
if(raid == null) return;
ApiUserReminder apiReminder = ConvertUserReminder(reminder, raid);
var raidItemJson = new StringContent(
JsonSerializer.Serialize(apiReminder),
Encoding.UTF8,
Application.Json);
var httpResponseMessage = await httpClient.PostAsync("raid/SendUserReminder", raidItemJson);
if (httpResponseMessage.IsSuccessStatusCode)
{
reminder.Sent = true;
context.Update(reminder);
await context.SaveChangesAsync();
}
} }
catch {}
} }
public async Task SendChannelReminder(RaidReminder reminder) public async Task SendChannelReminder(RaidReminder reminder)
{ {
var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName); try
ApiChannelReminder apiReminder = ConvertChannelReminder(reminder);
var raidItemJson = new StringContent(
JsonSerializer.Serialize(apiReminder),
Encoding.UTF8,
Application.Json);
var httpResponseMessage = await httpClient.PostAsync("raid/SendChannelReminder", raidItemJson);
if (httpResponseMessage.IsSuccessStatusCode)
{ {
reminder.Sent = true; var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName);
using var context = _contextFactory.CreateDbContext();
context.Update(reminder); ApiChannelReminder apiReminder = ConvertChannelReminder(reminder);
await context.SaveChangesAsync();
var raidItemJson = new StringContent(
JsonSerializer.Serialize(apiReminder),
Encoding.UTF8,
Application.Json);
var httpResponseMessage = await httpClient.PostAsync("raid/SendChannelReminder", raidItemJson);
if (httpResponseMessage.IsSuccessStatusCode)
{
reminder.Sent = true;
using var context = _contextFactory.CreateDbContext();
context.Update(reminder);
await context.SaveChangesAsync();
}
} }
catch {}
} }
private async Task UpdateDiscordMessages(IEnumerable<ApiRaid.DiscordMessage> messages, Raid raid) private async Task UpdateDiscordMessages(IEnumerable<ApiRaid.DiscordMessage> messages, Raid raid)
@ -206,12 +216,24 @@ namespace Lieb.Data
{ {
if(signUp.SignUpType != SignUpType.SignedOff) if(signUp.SignUpType != SignUpType.SignedOff)
{ {
string status = signUp.SignUpType != SignUpType.SignedUp ? signUp.SignUpType.ToString() : string.Empty; if(signUp.IsExternalUser)
apiRole.Users.Add(new ApiRaid.Role.User(){ {
AccountName = signUp.GuildWars2Account.AccountName, string status = signUp.SignUpType != SignUpType.SignedUp ? signUp.SignUpType.ToString() : string.Empty;
Status = status, apiRole.Users.Add(new ApiRaid.Role.User(){
UserName = signUp.LiebUser.Name AccountName = string.Empty,
}); Status = status,
UserName = signUp.ExternalUserName
});
}
else
{
string status = signUp.SignUpType != SignUpType.SignedUp ? signUp.SignUpType.ToString() : string.Empty;
apiRole.Users.Add(new ApiRaid.Role.User(){
AccountName = signUp.GuildWars2Account.AccountName,
Status = status,
UserName = signUp.LiebUser.Name
});
}
} }
} }
apiRaid.Roles.Add(apiRole); apiRaid.Roles.Add(apiRole);

View file

@ -46,7 +46,8 @@ namespace Lieb.Data
.Include(r => r.SignUps) .Include(r => r.SignUps)
.ThenInclude(s => s.RaidRole) .ThenInclude(s => s.RaidRole)
.Include(r => r.DiscordRaidMessages) .Include(r => r.DiscordRaidMessages)
.FirstOrDefault(r => r.RaidId == raidId); .ToList()
.FirstOrDefault(r => r.RaidId == raidId, new Raid());
} }
public async Task AddOrEditRaid(Raid raid, List<RaidRole> rolesToDelete, List<RaidReminder> remindersToDelete, List<DiscordRaidMessage> messagesToDelete) public async Task AddOrEditRaid(Raid raid, List<RaidRole> rolesToDelete, List<RaidReminder> remindersToDelete, List<DiscordRaidMessage> messagesToDelete)
@ -69,7 +70,7 @@ namespace Lieb.Data
//move users back to "Random" role //move users back to "Random" role
if (raid.RaidType != RaidType.Planned) if (raid.RaidType != RaidType.Planned)
{ {
RaidRole randomRole = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole); RaidRole randomRole = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole, CreateRandomSignUpRole(raid.RaidType));
foreach (RaidSignUp signUp in raid.SignUps) foreach (RaidSignUp signUp in raid.SignUps)
{ {
signUp.RaidRole = randomRole; signUp.RaidRole = randomRole;
@ -79,7 +80,7 @@ namespace Lieb.Data
await context.SaveChangesAsync(); await context.SaveChangesAsync();
} }
_discordService.PostRaidMessage(raid.RaidId); await _discordService.PostRaidMessage(raid.RaidId);
} }
} }
@ -94,7 +95,7 @@ namespace Lieb.Data
await context.SaveChangesAsync(); await context.SaveChangesAsync();
context.Raids.Remove(raid); context.Raids.Remove(raid);
await context.SaveChangesAsync(); await context.SaveChangesAsync();
_discordService.DeleteRaidMessages(raid); await _discordService.DeleteRaidMessages(raid);
} }
public async Task SignUp(int raidId, ulong liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType) public async Task SignUp(int raidId, ulong liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType)
@ -108,24 +109,48 @@ namespace Lieb.Data
List<RaidSignUp> signUps = context.RaidSignUps.Where(r => r.RaidId == raidId && r.LiebUserId == liebUserId).ToList(); List<RaidSignUp> signUps = context.RaidSignUps.Where(r => r.RaidId == raidId && r.LiebUserId == liebUserId).ToList();
if (signUpType != SignUpType.Flex && signUps.Where(r => r.SignUpType != SignUpType.Flex).Any()) if (signUpType != SignUpType.Flex && signUps.Where(r => r.SignUpType != SignUpType.Flex).Any())
{ {
ChangeSignUpType(raidId, liebUserId, plannedRoleId, signUpType); await ChangeSignUpType(raidId, liebUserId, plannedRoleId, signUpType);
} }
else if (!signUps.Where(r => r.RaidRoleId == plannedRoleId).Any()) else if (!signUps.Where(r => r.RaidRoleId == plannedRoleId).Any())
{ {
context.RaidSignUps.Add(new RaidSignUp() RaidSignUp signUp = new RaidSignUp()
{ {
GuildWars2AccountId = guildWars2AccountId, GuildWars2AccountId = guildWars2AccountId,
RaidId = raidId, RaidId = raidId,
LiebUserId = liebUserId, LiebUserId = liebUserId,
RaidRoleId = plannedRoleId, RaidRoleId = plannedRoleId,
SignUpType = signUpType SignUpType = signUpType
}); };
context.RaidSignUps.Add(signUp);
await context.SaveChangesAsync(); await context.SaveChangesAsync();
await LogSignUp(signUp);
} }
_discordService.PostRaidMessage(raidId); await _discordService.PostRaidMessage(raidId);
} }
public async Task SignOff(int raidId, ulong liebUserId) public async Task SignUpExternalUser(int raidId, string userName, int plannedRoleId, SignUpType signUpType, ulong signedUpByUserId)
{
if (!IsRoleSignUpAllowed(raidId, ulong.MaxValue, plannedRoleId, signUpType, true))
{
return;
}
using var context = _contextFactory.CreateDbContext();
RaidSignUp signUp = new RaidSignUp()
{
RaidId = raidId,
ExternalUserName = userName,
RaidRoleId = plannedRoleId,
SignUpType = signUpType
};
context.RaidSignUps.Add(signUp);
await context.SaveChangesAsync();
await LogSignUp(signUp, signedUpByUserId);
await _discordService.PostRaidMessage(raidId);
}
public async Task SignOff(int raidId, ulong liebUserId, ulong signedOffByUserId = 0)
{ {
using var context = _contextFactory.CreateDbContext(); using var context = _contextFactory.CreateDbContext();
//remove Flex Sign Ups //remove Flex Sign Ups
@ -143,11 +168,29 @@ namespace Lieb.Data
if(raid != null && raid.RaidType != RaidType.Planned && !signUp.RaidRole.IsRandomSignUpRole) if(raid != null && raid.RaidType != RaidType.Planned && !signUp.RaidRole.IsRandomSignUpRole)
{ {
context.RaidRoles.Remove(signUp.RaidRole); context.RaidRoles.Remove(signUp.RaidRole);
signUp.RaidRole = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole); signUp.RaidRole = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole, CreateRandomSignUpRole(raid.RaidType));
} }
await LogSignUp(signUp, signedOffByUserId);
} }
await context.SaveChangesAsync(); await context.SaveChangesAsync();
_discordService.PostRaidMessage(raidId); await _discordService.PostRaidMessage(raidId);
}
public async Task SignOffExternalUser(int raidId, string userName, ulong signedOffByUserId)
{
using var context = _contextFactory.CreateDbContext();
List<RaidSignUp> signUps = context.RaidSignUps.Where(x => x.RaidId == raidId && x.ExternalUserName == userName).ToList();
context.RaidSignUps.RemoveRange(signUps);
await context.SaveChangesAsync();
RaidSignUp signUp = signUps.FirstOrDefault();
if(signUp != null)
{
signUp.SignUpType = SignUpType.SignedOff;
await LogSignUp(signUp, signedOffByUserId);
}
await _discordService.PostRaidMessage(raidId);
} }
public async Task ChangeAccount(int raidId, ulong liebUserId, int guildWars2AccountId) public async Task ChangeAccount(int raidId, ulong liebUserId, int guildWars2AccountId)
@ -159,10 +202,10 @@ namespace Lieb.Data
signUp.GuildWars2AccountId = guildWars2AccountId; signUp.GuildWars2AccountId = guildWars2AccountId;
} }
await context.SaveChangesAsync(); await context.SaveChangesAsync();
_discordService.PostRaidMessage(raidId); await _discordService.PostRaidMessage(raidId);
} }
public void ChangeSignUpType(int raidId, ulong liebUserId, int plannedRoleId, SignUpType signUpType) public async Task ChangeSignUpType(int raidId, ulong liebUserId, int plannedRoleId, SignUpType signUpType, bool postChanges = true)
{ {
if (!IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true)) if (!IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true))
{ {
@ -187,9 +230,13 @@ namespace Lieb.Data
{ {
signUp.RaidRoleId = plannedRoleId; signUp.RaidRoleId = plannedRoleId;
signUp.SignUpType = signUpType; signUp.SignUpType = signUpType;
await LogSignUp(signUp);
} }
context.SaveChanges(); context.SaveChanges();
_discordService.PostRaidMessage(raidId); if(postChanges)
{
await _discordService.PostRaidMessage(raidId);
}
} }
public bool IsRoleSignUpAllowed(ulong liebUserId, int plannedRoleId, SignUpType signUpType) public bool IsRoleSignUpAllowed(ulong liebUserId, int plannedRoleId, SignUpType signUpType)
@ -276,7 +323,7 @@ namespace Lieb.Data
{ {
if (moveFlexUser) if (moveFlexUser)
{ {
ChangeSignUpType(raid.RaidId, userId, signUp.RaidRoleId, SignUpType.SignedUp); await ChangeSignUpType(raid.RaidId, userId, signUp.RaidRoleId, SignUpType.SignedUp, false);
} }
return true; return true;
} }
@ -340,20 +387,60 @@ namespace Lieb.Data
return true; return true;
} }
public void SendReminders() private async Task LogSignUp(RaidSignUp signUp, ulong signedUpBy = 0)
{
RaidSignUpHistory history = new RaidSignUpHistory()
{
RaidId = signUp.RaidId,
UserId = signUp.LiebUserId,
SignUpType = signUp.SignUpType,
Time = DateTimeOffset.UtcNow,
UserName = signUp.ExternalUserName,
GuildWars2AccountId = signUp.GuildWars2AccountId
};
if(signedUpBy != 0)
{
history.UserId = signedUpBy;
}
using var context = _contextFactory.CreateDbContext();
await context.RaidSignUpHistories.AddAsync(history);
await context.SaveChangesAsync();
}
public async Task SendReminders()
{ {
using var context = _contextFactory.CreateDbContext(); using var context = _contextFactory.CreateDbContext();
DateTimeOffset now = DateTimeOffset.UtcNow;
List<Raid> raids = context.Raids List<Raid> raids = context.Raids
.Include(r => r.Reminders) .Include(r => r.Reminders)
.ToList(); .ToList();
foreach(Raid raid in raids) foreach(Raid raid in raids.Where(r => r.StartTimeUTC > now))
{ {
foreach(RaidReminder reminder in raid.Reminders.Where(reminder => !reminder.Sent && raid.StartTimeUTC.AddHours(-reminder.HoursBeforeRaid) < DateTime.UtcNow)) foreach(RaidReminder reminder in raid.Reminders.Where(reminder => !reminder.Sent && raid.StartTimeUTC.AddHours(-reminder.HoursBeforeRaid) < DateTime.UtcNow))
{ {
//TODO send reminders -> this is a Discord Problem... switch(reminder.Type)
{
case RaidReminder.ReminderType.User:
await _discordService.SendUserReminder(reminder);
break;
case RaidReminder.ReminderType.Channel:
await _discordService.SendChannelReminder(reminder);
break;
}
} }
} }
} }
public RaidRole CreateRandomSignUpRole(RaidType raidType)
{
return new RaidRole()
{
Spots = 10,
Name = "Random",
Description = raidType.ToString(),
IsRandomSignUpRole = true
};
}
} }
} }

View file

@ -20,7 +20,7 @@ namespace Lieb.Data
return Task.CompletedTask; return Task.CompletedTask;
} }
private void CheckRaids(object? state) private async void CheckRaids(object? state)
{ {
using (var scope = _services.CreateScope()) using (var scope = _services.CreateScope())
{ {
@ -41,7 +41,7 @@ namespace Lieb.Data
var raidService = var raidService =
scope.ServiceProvider scope.ServiceProvider
.GetRequiredService<RaidService>(); .GetRequiredService<RaidService>();
raidService.SendReminders(); await raidService.SendReminders();
} }
} }

View file

@ -12,11 +12,12 @@
public class RaidSignUp public class RaidSignUp
{ {
public int RaidSignUpId { get; set; } public int RaidSignUpId { get; set; }
public bool IsExternalUser {get { return LiebUserId == 0;}}
public int RaidId { get; set; } public int RaidId { get; set; }
public ulong LiebUserId { get; set; } public ulong LiebUserId { get; set; }
public int GuildWars2AccountId { get; set; } public int GuildWars2AccountId { get; set; }
public int RaidRoleId { get; set; } public int RaidRoleId { get; set; }
public string ExternalUserName {get; set;} = string.Empty;
public SignUpType SignUpType { get; set; } public SignUpType SignUpType { get; set; }

View file

@ -4,12 +4,25 @@
{ {
public int RaidSignUpHistoryId { get; set; } public int RaidSignUpHistoryId { get; set; }
public string UserName { get; set; } = string.Empty; public int RaidId { get; set; }
public ulong UserId {get; set;}
public int GuildWars2AccountId { get; set; }
//public ulong SignedUpByUserId {get; set;}
public string UserName {get; set;} = string.Empty;
public DateTimeOffset Time { get; set; } = DateTimeOffset.Now; public DateTimeOffset Time { get; set; } = DateTimeOffset.Now;
public SignUpType SignUpType { get; set; } public SignUpType SignUpType { get; set; }
public LiebUser User {get; set;}
//public LiebUser SignedUpByUser {get; set;}
public Raid Raid { get; set; } public Raid Raid { get; set; }
public GuildWars2Account GuildWars2Account { get; set; }
} }
} }

View file

@ -17,7 +17,7 @@
@if (_user != null && _isRaidSignUpAllowed) @if (_user != null && _isRaidSignUpAllowed)
{ {
<div class="signUpStatusTooltip"> <div class="signUpStatusTooltip">
@if(_raid.SignUps.Where(s => s.LiebUserId == _user.Id && s.SignUpType != SignUpType.SignedOff).Any()) @if(_raid.SignUps.Where(s => s.LiebUserId == _user.Id && s.SignUpType != SignUpType.SignedOff && s.LiebUserId > 0).Any())
{ {
<span class="oi oi-badge" style="color:green"></span> <span class="oi oi-badge" style="color:green"></span>
<span class="tooltiptext">You are signed up</span> <span class="tooltiptext">You are signed up</span>

View file

@ -234,8 +234,8 @@
{ {
_raid = RaidService.GetRaid(parsedId); _raid = RaidService.GetRaid(parsedId);
if (_raid != null && (_raid.RaidOwnerId == _user.Id if (_raid.RaidOwnerId == _user.Id
|| _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel)) || _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel)
{ {
_startTime = await TimeZoneService.GetLocalDateTime(_raid.StartTimeUTC); _startTime = await TimeZoneService.GetLocalDateTime(_raid.StartTimeUTC);
_endTime = await TimeZoneService.GetLocalDateTime(_raid.EndTimeUTC); _endTime = await TimeZoneService.GetLocalDateTime(_raid.EndTimeUTC);
@ -301,13 +301,7 @@
{ {
if(!_raid.Roles.Where(r => r.IsRandomSignUpRole).Any()) if(!_raid.Roles.Where(r => r.IsRandomSignUpRole).Any())
{ {
_raid.Roles.Add(new RaidRole() _raid.Roles.Add(RaidService.CreateRandomSignUpRole(_raid.RaidType));
{
Spots = 10,
Name = "Random",
Description = _raid.RaidType.ToString(),
IsRandomSignUpRole = true
});
} }
foreach(RaidRole role in _raid.Roles.Where(r => !r.IsRandomSignUpRole)) foreach(RaidRole role in _raid.Roles.Where(r => !r.IsRandomSignUpRole))

View file

@ -31,7 +31,7 @@
</thead> </thead>
<tbody> <tbody>
@{ @{
bool isSignedUp = _raid.SignUps.Where(s => s.LiebUserId == _liebUserId && s.SignUpType != SignUpType.SignedOff).Any(); bool isSignedUp = _raid.SignUps.Where(s => s.LiebUserId == _liebUserId && s.SignUpType != SignUpType.SignedOff && s.LiebUserId > 0).Any();
} }
@foreach (ExpandableRole role in _expandableRoles.OrderBy(r => r.Role.RaidRoleId)) @foreach (ExpandableRole role in _expandableRoles.OrderBy(r => r.Role.RaidRoleId))
{ {
@ -141,7 +141,7 @@
{ {
if(_raid.SignUps.Where(s => s.LiebUserId == _liebUserId).Any() && signUpType != SignUpType.Flex) if(_raid.SignUps.Where(s => s.LiebUserId == _liebUserId).Any() && signUpType != SignUpType.Flex)
{ {
RaidService.ChangeSignUpType(_raid.RaidId, _liebUserId, role.RaidRoleId, signUpType); await RaidService.ChangeSignUpType(_raid.RaidId, _liebUserId, role.RaidRoleId, signUpType);
} }
else else
{ {

View file

@ -13,12 +13,12 @@
{ {
<tr> <tr>
@{ @{
bool isUser = signUp.LiebUserId == _liebUserId; bool isLoggedInUser = signUp.LiebUserId == _liebUserId;
string signUpStatus = string.Empty; string signUpStatus = string.Empty;
@if (signUp.SignUpType != SignUpType.SignedUp && _signUpTypes.Count > 1) signUpStatus = $" - {signUp.SignUpType}"; @if (signUp.SignUpType != SignUpType.SignedUp && _signUpTypes.Count > 1) signUpStatus = $" - {signUp.SignUpType}";
} }
@if (isUser && _usableAccounts.Count > 1 && signUp.SignUpType != SignUpType.Flex) @if (isLoggedInUser && _usableAccounts.Count > 1 && signUp.SignUpType != SignUpType.Flex)
{ {
<td> <td>
<select class="accountselect" value=@signUp.GuildWars2AccountId @onchange="args => _Parent.ChangeAccount(args)"> <select class="accountselect" value=@signUp.GuildWars2AccountId @onchange="args => _Parent.ChangeAccount(args)">
@ -29,7 +29,7 @@
</select> @signUpStatus </select> @signUpStatus
</td> </td>
} }
else if(isUser && _showUserColor) else if(isLoggedInUser && _showUserColor)
{ {
<td class="nametooltip username"> <td class="nametooltip username">
@signUp.GuildWars2Account.AccountName @signUpStatus @signUp.GuildWars2Account.AccountName @signUpStatus
@ -39,13 +39,23 @@
} }
</td> </td>
} }
else if(!signUp.IsExternalUser)
{
<td class="nametooltip">
@signUp.GuildWars2Account.AccountName @signUpStatus
@if(_showToolTip)
{
<span class="tooltiptext">@signUp.LiebUser.Name</span>
}
</td>
}
else else
{ {
<td class="nametooltip"> <td class="nametooltip">
@signUp.GuildWars2Account.AccountName @signUpStatus @signUp.ExternalUserName @signUpStatus
@if(_showToolTip) @if(_showToolTip)
{ {
<span class="tooltiptext">@signUp.LiebUser.Name</span> <span class="tooltiptext">external user</span>
} }
</td> </td>
} }