Renamed RaidRole and RaidSignUpHistory

This commit is contained in:
t.ruspekhofer 2022-03-23 21:48:29 +01:00
parent 2bf630f3a1
commit bae69648d0
15 changed files with 144 additions and 121 deletions

View file

@ -77,38 +77,38 @@ namespace Lieb.Data
context.RoleAssignments.AddRange(assignments); context.RoleAssignments.AddRange(assignments);
context.SaveChanges(); context.SaveChanges();
#if DEBUG #if DEBUG
PlannedRaidRole ele = new PlannedRaidRole() RaidRole ele = new RaidRole()
{ {
Description = "Beste", Description = "Beste",
Name = "Heal Ele", Name = "Heal Ele",
Spots = 2 Spots = 2
}; };
PlannedRaidRole scourge = new PlannedRaidRole() RaidRole scourge = new RaidRole()
{ {
Description = "WupWup", Description = "WupWup",
Name = "Scourge", Name = "Scourge",
Spots = 8 Spots = 8
}; };
PlannedRaidRole randomRole = new PlannedRaidRole() RaidRole randomRole = new RaidRole()
{ {
Spots = 10, Spots = 10,
Name = "Random", Name = "Random",
Description = RaidType.RandomWithBoons.ToString(), Description = RaidType.RandomWithBoons.ToString(),
IsRandomSignUpRole = true IsRandomSignUpRole = true
}; };
PlannedRaidRole flexTest1 = new PlannedRaidRole() RaidRole flexTest1 = new RaidRole()
{ {
Description = "flexTest1", Description = "flexTest1",
Name = "flexTest1", Name = "flexTest1",
Spots = 1 Spots = 1
}; };
PlannedRaidRole flexTest2 = new PlannedRaidRole() RaidRole flexTest2 = new RaidRole()
{ {
Description = "flexTest2", Description = "flexTest2",
Name = "flexTest2", Name = "flexTest2",
Spots = 1 Spots = 1
}; };
PlannedRaidRole flexTest3 = new PlannedRaidRole() RaidRole flexTest3 = new RaidRole()
{ {
Description = "flexTest3", Description = "flexTest3",
Name = "flexTest3", Name = "flexTest3",
@ -146,7 +146,7 @@ namespace Lieb.Data
Interval = 7, Interval = 7,
CreateDaysBefore = 7, CreateDaysBefore = 7,
TimeZone = "Europe/Vienna", TimeZone = "Europe/Vienna",
Roles = new[] { new PlannedRaidRole(){ Roles = new[] { new RaidRole(){
Description = "WupWup", Description = "WupWup",
Name = "Ups", Name = "Ups",
Spots = 10 Spots = 10
@ -158,11 +158,11 @@ namespace Lieb.Data
var signUps = new RaidSignUp[] var signUps = new RaidSignUp[]
{ {
new RaidSignUp{GuildWars2AccountId = linaith.GuildWars2AccountId, LiebUserId = users[0].LiebUserId, PlannedRaidRoleId = ele.PlannedRaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp }, new RaidSignUp{GuildWars2AccountId = linaith.GuildWars2AccountId, LiebUserId = users[0].LiebUserId, PlannedRaidRoleId = ele.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp },
new RaidSignUp{GuildWars2AccountId = hierpiepts.GuildWars2AccountId, LiebUserId = users[1].LiebUserId, PlannedRaidRoleId = flexTest1.PlannedRaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp }, new RaidSignUp{GuildWars2AccountId = hierpiepts.GuildWars2AccountId, LiebUserId = users[1].LiebUserId, PlannedRaidRoleId = flexTest1.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp },
new RaidSignUp{GuildWars2AccountId = bloodseeker.GuildWars2AccountId, LiebUserId = users[2].LiebUserId, PlannedRaidRoleId = flexTest2.PlannedRaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp }, new RaidSignUp{GuildWars2AccountId = bloodseeker.GuildWars2AccountId, LiebUserId = users[2].LiebUserId, PlannedRaidRoleId = flexTest2.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp },
new RaidSignUp{GuildWars2AccountId = hierpiepts.GuildWars2AccountId, LiebUserId = users[1].LiebUserId, PlannedRaidRoleId = flexTest2.PlannedRaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.Flex }, new RaidSignUp{GuildWars2AccountId = hierpiepts.GuildWars2AccountId, LiebUserId = users[1].LiebUserId, PlannedRaidRoleId = flexTest2.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.Flex },
new RaidSignUp{GuildWars2AccountId = bloodseeker.GuildWars2AccountId, LiebUserId = users[2].LiebUserId, PlannedRaidRoleId = flexTest3.PlannedRaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.Flex } new RaidSignUp{GuildWars2AccountId = bloodseeker.GuildWars2AccountId, LiebUserId = users[2].LiebUserId, PlannedRaidRoleId = flexTest3.RaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.Flex }
}; };
context.RaidSignUps.AddRange(signUps); context.RaidSignUps.AddRange(signUps);

View file

@ -19,12 +19,12 @@ namespace Lieb.Data
public DbSet<GuildWars2Account> GuildWars2Accounts { get; set; } public DbSet<GuildWars2Account> GuildWars2Accounts { get; set; }
public DbSet<Equipped> Equipped { get; set; } public DbSet<Equipped> Equipped { get; set; }
public DbSet<GuildWars2Build> GuildWars2Builds { get; set; } public DbSet<GuildWars2Build> GuildWars2Builds { get; set; }
public DbSet<PlannedRaidRole> PlannedRaidRoles { get; set; } public DbSet<RaidRole> RaidRoles { get; set; }
public DbSet<Raid> Raids { get; set; } public DbSet<Raid> Raids { get; set; }
public DbSet<RaidTemplate> RaidTemplates { get; set; } public DbSet<RaidTemplate> RaidTemplates { get; set; }
public DbSet<RaidReminder> RaidReminders { get; set; } public DbSet<RaidReminder> RaidReminders { get; set; }
public DbSet<RaidSignUp> RaidSignUps { get; set; } public DbSet<RaidSignUp> RaidSignUps { get; set; }
public DbSet<SignUpHistory> SignUpHistories { get; set; } public DbSet<RaidSignUpHistory> RaidSignUpHistories { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
@ -35,12 +35,12 @@ namespace Lieb.Data
modelBuilder.Entity<GuildWars2Account>().ToTable("GuildWars2Account"); modelBuilder.Entity<GuildWars2Account>().ToTable("GuildWars2Account");
modelBuilder.Entity<Equipped>().ToTable("Equipped"); modelBuilder.Entity<Equipped>().ToTable("Equipped");
modelBuilder.Entity<GuildWars2Build>().ToTable("GuildWars2Build"); modelBuilder.Entity<GuildWars2Build>().ToTable("GuildWars2Build");
modelBuilder.Entity<PlannedRaidRole>().ToTable("PlannedRaidRole"); modelBuilder.Entity<RaidRole>().ToTable("RaidRole");
modelBuilder.Entity<Raid>().ToTable("Raid"); modelBuilder.Entity<Raid>().ToTable("Raid");
modelBuilder.Entity<RaidTemplate>().ToTable("RaidTemplate"); modelBuilder.Entity<RaidTemplate>().ToTable("RaidTemplate");
modelBuilder.Entity<RaidReminder>().ToTable("RaidReminder"); modelBuilder.Entity<RaidReminder>().ToTable("RaidReminder");
modelBuilder.Entity<RaidSignUp>().ToTable("RaidSignUp"); modelBuilder.Entity<RaidSignUp>().ToTable("RaidSignUp");
modelBuilder.Entity<SignUpHistory>().ToTable("SignUpHistory"); modelBuilder.Entity<RaidSignUpHistory>().ToTable("RaidSignUpHistory");
} }
} }
} }

View file

@ -60,7 +60,7 @@ namespace Lieb.Data
{ {
possibleClasses.Add(build.GuildWars2Build.Class); possibleClasses.Add(build.GuildWars2Build.Class);
} }
PlannedRaidRole role = new PlannedRaidRole(); RaidRole role = new RaidRole();
role.Spots = 0; role.Spots = 0;
if (possibleClasses.Count > 0) if (possibleClasses.Count > 0)
{ {
@ -84,7 +84,7 @@ namespace Lieb.Data
{ {
possibleEliteSpecs.Add(build.GuildWars2Build.EliteSpecialization); possibleEliteSpecs.Add(build.GuildWars2Build.EliteSpecialization);
} }
PlannedRaidRole role = new PlannedRaidRole(); RaidRole role = new RaidRole();
role.Spots = 0; role.Spots = 0;
if (possibleEliteSpecs.Count > 0) if (possibleEliteSpecs.Count > 0)
{ {
@ -112,7 +112,7 @@ namespace Lieb.Data
BalanceRoles(raid, signedUpUsers); BalanceRoles(raid, signedUpUsers);
foreach(var userBuild in signedUpUsers) foreach(var userBuild in signedUpUsers)
{ {
PlannedRaidRole role = new PlannedRaidRole(); RaidRole role = new RaidRole();
role.Spots = 0; role.Spots = 0;
role.Name = userBuild.Value.BuildName; role.Name = userBuild.Value.BuildName;
raid.Roles.Add(role); raid.Roles.Add(role);
@ -326,19 +326,19 @@ namespace Lieb.Data
private void CleanUpRoles(Raid raid, LiebContext context) private void CleanUpRoles(Raid raid, LiebContext context)
{ {
List<PlannedRaidRole> rolesToDelete = new List<PlannedRaidRole>(); List<RaidRole> rolesToDelete = new List<RaidRole>();
foreach (PlannedRaidRole role in raid.Roles) foreach (RaidRole role in raid.Roles)
{ {
if (!role.IsRandomSignUpRole && raid.SignUps.FirstOrDefault(s => s.PlannedRaidRoleId == role.PlannedRaidRoleId) == null) if (!role.IsRandomSignUpRole && raid.SignUps.FirstOrDefault(s => s.PlannedRaidRoleId == role.RaidRoleId) == null)
{ {
rolesToDelete.Add(role); rolesToDelete.Add(role);
} }
} }
foreach (PlannedRaidRole role in rolesToDelete) foreach (RaidRole role in rolesToDelete)
{ {
raid.Roles.Remove(role); raid.Roles.Remove(role);
} }
context.PlannedRaidRoles.RemoveRange(rolesToDelete); context.RaidRoles.RemoveRange(rolesToDelete);
} }
} }

View file

@ -45,7 +45,7 @@ namespace Lieb.Data
.FirstOrDefault(r => r.RaidId == raidId); .FirstOrDefault(r => r.RaidId == raidId);
} }
public async Task AddOrEditRaid(Raid raid, List<PlannedRaidRole> rolesToDelete, List<RaidReminder> remindersToDelete) public async Task AddOrEditRaid(Raid raid, List<RaidRole> rolesToDelete, List<RaidReminder> remindersToDelete)
{ {
if (raid != null) if (raid != null)
{ {
@ -58,25 +58,18 @@ namespace Lieb.Data
else else
{ {
context.Update(raid); context.Update(raid);
context.PlannedRaidRoles.RemoveRange(rolesToDelete); context.RaidRoles.RemoveRange(rolesToDelete);
context.RaidReminders.RemoveRange(remindersToDelete); context.RaidReminders.RemoveRange(remindersToDelete);
//move users back to "Random" role //move users back to "Random" role
if (raid.RaidType != RaidType.Planned) if (raid.RaidType != RaidType.Planned)
{ {
int randomRoleId = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole).PlannedRaidRoleId; RaidRole randomRole = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole);
foreach (RaidSignUp signUp in raid.SignUps) foreach (RaidSignUp signUp in raid.SignUps)
{ {
if (randomRoleId == 0) signUp.PlannedRaidRole = randomRole;
{
signUp.PlannedRaidRole = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole);
} }
else context.RaidRoles.RemoveRange(raid.Roles.Where(r => !r.IsRandomSignUpRole));
{
signUp.PlannedRaidRoleId = randomRoleId;
}
}
context.PlannedRaidRoles.RemoveRange(raid.Roles.Where(r => !r.IsRandomSignUpRole));
} }
await context.SaveChangesAsync(); await context.SaveChangesAsync();
@ -89,8 +82,8 @@ namespace Lieb.Data
using var context = _contextFactory.CreateDbContext(); using var context = _contextFactory.CreateDbContext();
Raid raid = GetRaid(raidId); Raid raid = GetRaid(raidId);
context.RaidSignUps.RemoveRange(raid.SignUps); context.RaidSignUps.RemoveRange(raid.SignUps);
context.PlannedRaidRoles.RemoveRange(raid.Roles); context.RaidRoles.RemoveRange(raid.Roles);
context.SignUpHistories.RemoveRange(raid.SignUpHistory); context.RaidSignUpHistories.RemoveRange(raid.SignUpHistory);
context.RaidReminders.RemoveRange(raid.Reminders); context.RaidReminders.RemoveRange(raid.Reminders);
await context.SaveChangesAsync(); await context.SaveChangesAsync();
context.Raids.Remove(raid); context.Raids.Remove(raid);
@ -141,7 +134,7 @@ namespace Lieb.Data
Raid? raid = context.Raids.Include(r => r.Roles).FirstOrDefault(r => r.RaidId == raidId); Raid? raid = context.Raids.Include(r => r.Roles).FirstOrDefault(r => r.RaidId == raidId);
if(raid != null && raid.RaidType != RaidType.Planned && !signUp.PlannedRaidRole.IsRandomSignUpRole) if(raid != null && raid.RaidType != RaidType.Planned && !signUp.PlannedRaidRole.IsRandomSignUpRole)
{ {
context.PlannedRaidRoles.Remove(signUp.PlannedRaidRole); context.RaidRoles.Remove(signUp.PlannedRaidRole);
signUp.PlannedRaidRole = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole); signUp.PlannedRaidRole = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole);
} }
} }
@ -200,8 +193,8 @@ namespace Lieb.Data
List<RaidSignUp> signUps = context.RaidSignUps.Where(s => s.PlannedRaidRoleId == plannedRoleId).ToList(); List<RaidSignUp> signUps = context.RaidSignUps.Where(s => s.PlannedRaidRoleId == plannedRoleId).ToList();
PlannedRaidRole? role = context.PlannedRaidRoles RaidRole? role = context.RaidRoles
.FirstOrDefault(r => r.PlannedRaidRoleId == plannedRoleId); .FirstOrDefault(r => r.RaidRoleId == plannedRoleId);
if (role == null) if (role == null)
return false; return false;
@ -235,9 +228,9 @@ namespace Lieb.Data
} }
else else
{ {
PlannedRaidRole? role = context.PlannedRaidRoles RaidRole? role = context.RaidRoles
.AsNoTracking() .AsNoTracking()
.FirstOrDefault(r => r.PlannedRaidRoleId == plannedRoleId); .FirstOrDefault(r => r.RaidRoleId == plannedRoleId);
if(role == null) return false; if(role == null) return false;
if (role.IsRandomSignUpRole) if (role.IsRandomSignUpRole)
{ {

View file

@ -31,7 +31,7 @@ namespace Lieb.Data
.FirstOrDefault(t => t.RaidTemplateId == raidTemplateId); .FirstOrDefault(t => t.RaidTemplateId == raidTemplateId);
} }
public async Task AddOrEditTemplate(RaidTemplate template, List<PlannedRaidRole> rolesToDelete, List<RaidReminder> remindersToDelete) public async Task AddOrEditTemplate(RaidTemplate template, List<RaidRole> rolesToDelete, List<RaidReminder> remindersToDelete)
{ {
if (template != null) if (template != null)
{ {
@ -43,7 +43,7 @@ namespace Lieb.Data
else else
{ {
context.Update(template); context.Update(template);
context.PlannedRaidRoles.RemoveRange(rolesToDelete); context.RaidRoles.RemoveRange(rolesToDelete);
context.RaidReminders.RemoveRange(remindersToDelete); context.RaidReminders.RemoveRange(remindersToDelete);
} }
await context.SaveChangesAsync(); await context.SaveChangesAsync();
@ -54,7 +54,7 @@ namespace Lieb.Data
{ {
using var context = _contextFactory.CreateDbContext(); using var context = _contextFactory.CreateDbContext();
RaidTemplate template = GetTemplate(raidTemplateId); RaidTemplate template = GetTemplate(raidTemplateId);
context.PlannedRaidRoles.RemoveRange(template.Roles); context.RaidRoles.RemoveRange(template.Roles);
context.RaidReminders.RemoveRange(template.Reminders); context.RaidReminders.RemoveRange(template.Reminders);
await context.SaveChangesAsync(); await context.SaveChangesAsync();
context.RaidTemplates.Remove(template); context.RaidTemplates.Remove(template);

View file

@ -0,0 +1,17 @@
namespace Lieb.Models.GuildWars2.Raid
{
public class DiscordRaidMessage
{
public int DiscordRaidMessageId { get; set; }
public int RaidId { get; set; }
public Raid Raid { get; set; }
public ulong DiscordMessageId { get; set; }
public ulong DiscordChannelId { get; set; }
public ulong DiscordGuildId { get; set; }
}
}

View file

@ -24,46 +24,12 @@ namespace Lieb.Models.GuildWars2.Raid
public ICollection<RaidSignUp> SignUps { get; set; } = new HashSet<RaidSignUp>(); public ICollection<RaidSignUp> SignUps { get; set; } = new HashSet<RaidSignUp>();
public ICollection<SignUpHistory> SignUpHistory { get; set; } = new HashSet<SignUpHistory>(); public ICollection<RaidSignUpHistory> SignUpHistory { get; set; } = new HashSet<RaidSignUpHistory>();
//used to edit the Discord message
public ulong DiscordMessageId { get; set; }
public Raid() { } public Raid() { }
public Raid(RaidTemplate template) public Raid(RaidTemplate template) : base(template)
{ {
this.Title = template.Title;
this.Description = template.Description;
this.Organizer = template.Organizer;
this.Guild = template.Guild;
this.VoiceChat = template.VoiceChat;
this.RaidType = template.RaidType;
this.RequiredRole = template.RequiredRole;
this.DiscordChannelId = template.DiscordChannelId;
this.DiscordGuildId = template.DiscordGuildId;
foreach(PlannedRaidRole role in template.Roles)
{
this.Roles.Add(new PlannedRaidRole()
{
Description = role.Description,
Name = role.Name,
Spots = role.Spots
});
}
foreach(RaidReminder reminder in template.Reminders)
{
this.Reminders.Add(new RaidReminder()
{
ChannelId = reminder.ChannelId,
HoursBeforeRaid = reminder.HoursBeforeRaid,
Message = reminder.Message,
Sent = reminder.Sent,
Type = reminder.Type
});
}
TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(template.TimeZone); TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(template.TimeZone);
StartTimeUTC = TimeZoneInfo.ConvertTimeToUtc(template.StartTime, timeZone); StartTimeUTC = TimeZoneInfo.ConvertTimeToUtc(template.StartTime, timeZone);
EndTimeUTC = TimeZoneInfo.ConvertTimeToUtc(template.EndTime, timeZone); EndTimeUTC = TimeZoneInfo.ConvertTimeToUtc(template.EndTime, timeZone);

View file

@ -2,7 +2,7 @@
namespace Lieb.Models.GuildWars2.Raid namespace Lieb.Models.GuildWars2.Raid
{ {
public class RaidBase public abstract class RaidBase
{ {
[Required] [Required]
[StringLength(100, ErrorMessage = "Title too long (100 character limit).")] [StringLength(100, ErrorMessage = "Title too long (100 character limit).")]
@ -34,13 +34,56 @@ namespace Lieb.Models.GuildWars2.Raid
public int RaidOwnerId { get; set; } public int RaidOwnerId { get; set; }
//role name, number of spots //role name, number of spots
public ICollection<PlannedRaidRole> Roles { get; set; } = new HashSet<PlannedRaidRole>(); public ICollection<RaidRole> Roles { get; set; } = new HashSet<RaidRole>();
public ICollection<RaidReminder> Reminders { get; set; } = new List<RaidReminder>(); public ICollection<RaidReminder> Reminders { get; set; } = new List<RaidReminder>();
//used to edit the Discord message public ICollection<DiscordRaidMessage> DiscordRaidMessages { get; set; } = new HashSet<DiscordRaidMessage>();
public ulong DiscordChannelId { get; set; }
public ulong DiscordGuildId { get; set; } public RaidBase() { }
public RaidBase(RaidBase template)
{
this.Title = template.Title;
this.Description = template.Description;
this.Organizer = template.Organizer;
this.Guild = template.Guild;
this.VoiceChat = template.VoiceChat;
this.RaidType = template.RaidType;
this.RequiredRole = template.RequiredRole;
this.MoveFlexUsers = template.MoveFlexUsers;
this.RaidOwnerId = template.RaidOwnerId;
foreach (RaidRole role in template.Roles)
{
this.Roles.Add(new RaidRole()
{
Description = role.Description,
Name = role.Name,
Spots = role.Spots
});
}
foreach (RaidReminder reminder in template.Reminders)
{
this.Reminders.Add(new RaidReminder()
{
ChannelId = reminder.ChannelId,
HoursBeforeRaid = reminder.HoursBeforeRaid,
Message = reminder.Message,
Sent = reminder.Sent,
Type = reminder.Type
});
}
foreach (DiscordRaidMessage message in template.DiscordRaidMessages)
{
this.DiscordRaidMessages.Add(new DiscordRaidMessage()
{
RaidId = message.RaidId,
DiscordMessageId = message.DiscordMessageId,
DiscordChannelId = message.DiscordChannelId,
DiscordGuildId = message.DiscordGuildId
});
}
}
} }
} }

View file

@ -2,9 +2,9 @@
namespace Lieb.Models.GuildWars2.Raid namespace Lieb.Models.GuildWars2.Raid
{ {
public class PlannedRaidRole public class RaidRole
{ {
public int PlannedRaidRoleId { get; set; } public int RaidRoleId { get; set; }
public int Spots { get; set; } public int Spots { get; set; }
[Required] [Required]

View file

@ -23,6 +23,6 @@
public Raid Raid { get; set; } public Raid Raid { get; set; }
public LiebUser LiebUser { get; set; } public LiebUser LiebUser { get; set; }
public GuildWars2Account GuildWars2Account { get; set; } public GuildWars2Account GuildWars2Account { get; set; }
public PlannedRaidRole PlannedRaidRole { get; set; } public RaidRole PlannedRaidRole { get; set; }
} }
} }

View file

@ -1,8 +1,8 @@
namespace Lieb.Models.GuildWars2.Raid namespace Lieb.Models.GuildWars2.Raid
{ {
public class SignUpHistory public class RaidSignUpHistory
{ {
public int SignUpHistoryId { get; set; } public int RaidSignUpHistoryId { get; set; }
public string UserName { get; set; } = string.Empty; public string UserName { get; set; } = string.Empty;

View file

@ -126,9 +126,9 @@
<th>Role name</th> <th>Role name</th>
<th>Description</th> <th>Description</th>
</tr> </tr>
@foreach( PlannedRaidRole role in _raid.Roles) @foreach( RaidRole role in _raid.Roles)
{ {
bool disableEdit = _raid.SignUps.Where(s => s.PlannedRaidRoleId == role.PlannedRaidRoleId).Any(); bool disableEdit = _raid.SignUps.Where(s => s.PlannedRaidRoleId == role.RaidRoleId).Any();
<tr> <tr>
<td><InputNumber @bind-Value="role.Spots" disabled="@disableEdit" /></td> <td><InputNumber @bind-Value="role.Spots" disabled="@disableEdit" /></td>
<td><InputText @bind-Value="role.Name" disabled="@disableEdit" /></td> <td><InputText @bind-Value="role.Name" disabled="@disableEdit" /></td>
@ -167,7 +167,7 @@
private DateTimeOffset _freeForAllDate = DateTime.Now.Date; private DateTimeOffset _freeForAllDate = DateTime.Now.Date;
private DateTimeOffset _freeForAllTime; private DateTimeOffset _freeForAllTime;
private List<PlannedRaidRole> _rolesToDelete = new List<PlannedRaidRole>(); private List<RaidRole> _rolesToDelete = new List<RaidRole>();
@ -210,13 +210,13 @@
async Task AddRoleClicked() async Task AddRoleClicked()
{ {
_raid.Roles.Add(new PlannedRaidRole()); _raid.Roles.Add(new RaidRole());
} }
async Task DeleteRoleClicked(PlannedRaidRole role) async Task DeleteRoleClicked(RaidRole role)
{ {
if(role.PlannedRaidRoleId != 0) if(role.RaidRoleId != 0)
{ {
_rolesToDelete.Add(role); _rolesToDelete.Add(role);
} }
@ -237,19 +237,23 @@
{ {
if(_raid.RaidType != RaidType.Planned) if(_raid.RaidType != RaidType.Planned)
{ {
PlannedRaidRole? role = _raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole); if(!_raid.Roles.Where(r => r.IsRandomSignUpRole).Any())
int randomRoleId = role != null ? role.PlannedRaidRoleId : 0; {
_raid.Roles.Clear(); _raid.Roles.Add(new RaidRole()
_raid.Roles.Add(new PlannedRaidRole()
{ {
Spots = 10, Spots = 10,
Name = "Random", Name = "Random",
Description = _raid.RaidType.ToString(), Description = _raid.RaidType.ToString(),
IsRandomSignUpRole = true, IsRandomSignUpRole = true
PlannedRaidRoleId = randomRoleId
}); });
} }
foreach(RaidRole role in _raid.Roles.Where(r => !r.IsRandomSignUpRole))
{
_rolesToDelete.Add(role);
}
}
if(_raid.Roles.Count == 0) if(_raid.Roles.Count == 0)
{ {
_errorMessage = "Roles are needed for a raid."; _errorMessage = "Roles are needed for a raid.";

View file

@ -33,7 +33,7 @@
@{ @{
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).Any();
} }
@foreach (ExpandableRole role in _expandableRoles.OrderBy(r => r.Role.PlannedRaidRoleId)) @foreach (ExpandableRole role in _expandableRoles.OrderBy(r => r.Role.RaidRoleId))
{ {
<tr> <tr>
@{ @{
@ -46,7 +46,7 @@
{ {
<span class="oi oi-chevron-bottom" style="margin-right:7px"> </span> <span class="oi oi-chevron-bottom" style="margin-right:7px"> </span>
} }
<b>@role.Role.Name</b> (@_raid.SignUps.Where(s => s.PlannedRaidRoleId == role.Role.PlannedRaidRoleId && s.SignUpType == SignUpType.SignedUp).Count() / @role.Role.Spots) <b>@role.Role.Name</b> (@_raid.SignUps.Where(s => s.PlannedRaidRoleId == role.Role.RaidRoleId && s.SignUpType == SignUpType.SignedUp).Count() / @role.Role.Spots)
@if (@role.IsRowExpanded) @if (@role.IsRowExpanded)
{ {
<br> @role.Role.Description <br> @role.Role.Description
@ -56,7 +56,7 @@
<td class="tdSignUp"> <td class="tdSignUp">
@{List<SignUpType> signUpTypes =new List<SignUpType>(){SignUpType.SignedUp, SignUpType.Maybe, SignUpType.Backup};} @{List<SignUpType> signUpTypes =new List<SignUpType>(){SignUpType.SignedUp, SignUpType.Maybe, SignUpType.Backup};}
<CascadingValue Value="this"> <CascadingValue Value="this">
<SignedUpUsers _raid=@_raid _usableAccounts=@_usableAccounts _liebUserId=@_liebUserId _currentRoleId=@role.Role.PlannedRaidRoleId _signUpTypes=@signUpTypes _showToolTip=@true _showUserColor=@true></SignedUpUsers> <SignedUpUsers _raid=@_raid _usableAccounts=@_usableAccounts _liebUserId=@_liebUserId _currentRoleId=@role.Role.RaidRoleId _signUpTypes=@signUpTypes _showToolTip=@true _showUserColor=@true></SignedUpUsers>
</CascadingValue> </CascadingValue>
</td> </td>
@if (flexExists) @if (flexExists)
@ -64,13 +64,13 @@
List<SignUpType> flexSignUpTypes =new List<SignUpType>(){SignUpType.Flex}; List<SignUpType> flexSignUpTypes =new List<SignUpType>(){SignUpType.Flex};
<td class="tdSignUp"> <td class="tdSignUp">
<CascadingValue Value="this"> <CascadingValue Value="this">
<SignedUpUsers _raid=@_raid _usableAccounts=@_usableAccounts _liebUserId=@_liebUserId _currentRoleId=@role.Role.PlannedRaidRoleId _signUpTypes=@flexSignUpTypes></SignedUpUsers> <SignedUpUsers _raid=@_raid _usableAccounts=@_usableAccounts _liebUserId=@_liebUserId _currentRoleId=@role.Role.RaidRoleId _signUpTypes=@flexSignUpTypes></SignedUpUsers>
</CascadingValue> </CascadingValue>
</td> </td>
} }
@if(_liebUserId > 0 && _isRaidSignUpAllowed) @if(_liebUserId > 0 && _isRaidSignUpAllowed)
{ {
bool notIsRoleSignUpAllowed = !RaidService.IsRoleSignUpAllowed(_raid.RaidId, _liebUserId, role.Role.PlannedRaidRoleId, SignUpType.SignedUp, false); bool notIsRoleSignUpAllowed = !RaidService.IsRoleSignUpAllowed(_raid.RaidId, _liebUserId, role.Role.RaidRoleId, SignUpType.SignedUp, false);
bool notIsBackupAllowed = _raid.RaidType != RaidType.Planned && notIsRoleSignUpAllowed; bool notIsBackupAllowed = _raid.RaidType != RaidType.Planned && notIsRoleSignUpAllowed;
<td><button class="raidButton" @onclick="() => SignUpClicked(role.Role, SignUpType.SignedUp)" disabled="@notIsRoleSignUpAllowed">Sign Up</button></td> <td><button class="raidButton" @onclick="() => SignUpClicked(role.Role, SignUpType.SignedUp)" disabled="@notIsRoleSignUpAllowed">Sign Up</button></td>
<td><button class="raidButton" @onclick="() => SignUpClicked(role.Role, SignUpType.Maybe)" disabled="@notIsRoleSignUpAllowed">Maybe</button></td> <td><button class="raidButton" @onclick="() => SignUpClicked(role.Role, SignUpType.Maybe)" disabled="@notIsRoleSignUpAllowed">Maybe</button></td>
@ -109,7 +109,7 @@
private class ExpandableRole private class ExpandableRole
{ {
public PlannedRaidRole Role; public RaidRole Role;
public bool IsRowExpanded = false; public bool IsRowExpanded = false;
} }
@ -128,7 +128,7 @@
_liebUserId = _user.LiebUserId; _liebUserId = _user.LiebUserId;
} }
_expandableRoles = new List<ExpandableRole>(); _expandableRoles = new List<ExpandableRole>();
foreach(PlannedRaidRole role in _raid.Roles) foreach(RaidRole role in _raid.Roles)
{ {
_expandableRoles.Add(new ExpandableRole() _expandableRoles.Add(new ExpandableRole()
{ {
@ -137,15 +137,15 @@
} }
} }
async Task SignUpClicked(PlannedRaidRole role, SignUpType signUpType) async Task SignUpClicked(RaidRole role, SignUpType signUpType)
{ {
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.PlannedRaidRoleId, signUpType); RaidService.ChangeSignUpType(_raid.RaidId, _liebUserId, role.RaidRoleId, signUpType);
} }
else else
{ {
await RaidService.SignUp(_raid.RaidId, _liebUserId, _usableAccounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, signUpType); await RaidService.SignUp(_raid.RaidId, _liebUserId, _usableAccounts.FirstOrDefault().GuildWars2AccountId, role.RaidRoleId, signUpType);
} }
_Parent.HasChanged(); _Parent.HasChanged();
} }

View file

@ -48,7 +48,7 @@
<div> <div>
<table class="table"> <table class="table">
<tbody> <tbody>
@foreach (var role in _template.Roles.OrderBy(r => r.PlannedRaidRoleId)) @foreach (var role in _template.Roles.OrderBy(r => r.RaidRoleId))
{ {
<tr> <tr>
<td><Label> <b>@role.Name</b> (@role.Spots) <br> @role.Description </Label></td> <td><Label> <b>@role.Name</b> (@role.Spots) <br> @role.Description </Label></td>

View file

@ -151,7 +151,7 @@
<th>Role name</th> <th>Role name</th>
<th>Description</th> <th>Description</th>
</tr> </tr>
@foreach( PlannedRaidRole role in _template.Roles) @foreach( RaidRole role in _template.Roles)
{ {
<tr> <tr>
<td><InputNumber @bind-Value="role.Spots" /></td> <td><InputNumber @bind-Value="role.Spots" /></td>
@ -190,7 +190,7 @@
private DateTimeOffset _freeForAllTime; private DateTimeOffset _freeForAllTime;
private string _userTimeZone = string.Empty; private string _userTimeZone = string.Empty;
private List<PlannedRaidRole> _rolesToDelete = new List<PlannedRaidRole>(); private List<RaidRole> _rolesToDelete = new List<RaidRole>();
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
@ -233,13 +233,13 @@
async Task AddRoleClicked() async Task AddRoleClicked()
{ {
_template.Roles.Add(new PlannedRaidRole()); _template.Roles.Add(new RaidRole());
} }
async Task DeleteRoleClicked(PlannedRaidRole role) async Task DeleteRoleClicked(RaidRole role)
{ {
if(role.PlannedRaidRoleId != 0) if(role.RaidRoleId != 0)
{ {
_rolesToDelete.Add(role); _rolesToDelete.Add(role);
} }
@ -261,7 +261,7 @@
if(_template.RaidType != RaidType.Planned) if(_template.RaidType != RaidType.Planned)
{ {
_template.Roles.Clear(); _template.Roles.Clear();
_template.Roles.Add(new PlannedRaidRole() _template.Roles.Add(new RaidRole()
{ {
Spots = 10, Spots = 10,
Name = "Random", Name = "Random",