diff --git a/Lieb/Data/DbInitializer.cs b/Lieb/Data/DbInitializer.cs index 2ee24a9..693943a 100644 --- a/Lieb/Data/DbInitializer.cs +++ b/Lieb/Data/DbInitializer.cs @@ -196,16 +196,6 @@ namespace Lieb.Data context.Equipped.AddRange(equippedBuilds); context.SaveChanges(); - var discordMessage = new DiscordRaidMessage() - { - DiscordChannelId = 666954070388637697, - DiscordGuildId = 666953424734257182, - DiscordMessageId = 1040355092630614087, - RaidId = raid.RaidId - }; - context.DiscordRaidMessages.Add(discordMessage); - context.SaveChanges(); - #endif } } diff --git a/Lieb/Data/RaidService.cs b/Lieb/Data/RaidService.cs index f170083..d8a4cd7 100644 --- a/Lieb/Data/RaidService.cs +++ b/Lieb/Data/RaidService.cs @@ -95,6 +95,11 @@ namespace Lieb.Data context.RaidReminders.RemoveRange(raid.Reminders); context.DiscordRaidMessages.RemoveRange(raid.DiscordRaidMessages); await context.SaveChangesAsync(); + raid.SignUps.Clear(); + raid.Roles.Clear(); + raid.RaidLogs.Clear(); + raid.Reminders.Clear(); + raid.DiscordRaidMessages.Clear(); context.Raids.Remove(raid); await context.SaveChangesAsync(); @@ -487,8 +492,6 @@ namespace Lieb.Data { using var context = _contextFactory.CreateDbContext(); List reminders = context.RaidReminders - .Include(r => r.Raid) - .ThenInclude(r => r.SignUps) .Where(r => !r.Sent) .ToList(); @@ -498,7 +501,11 @@ namespace Lieb.Data switch(reminder.Type) { case RaidReminder.ReminderType.User: - await _discordService.SendUserReminder(reminder, reminder.Raid); + Raid raid = context.Raids + .Include(r => r.SignUps) + .Include(r => r.Reminders) + .First(r => r.Reminders.Where(re => re.RaidReminderId == reminder.RaidReminderId).Any()); + await _discordService.SendUserReminder(reminder, raid); break; case RaidReminder.ReminderType.Channel: await _discordService.SendChannelReminder(reminder); diff --git a/Lieb/Data/RaidTemplateService.cs b/Lieb/Data/RaidTemplateService.cs index 9bed87c..552345d 100644 --- a/Lieb/Data/RaidTemplateService.cs +++ b/Lieb/Data/RaidTemplateService.cs @@ -28,6 +28,8 @@ namespace Lieb.Data return context.RaidTemplates .Include(r => r.Roles) .Include(r => r.Reminders) + .Include(r => r.DiscordRaidMessages) + .Include(r => r.TemplateLogs) .FirstOrDefault(t => t.RaidTemplateId == raidTemplateId); } @@ -61,7 +63,12 @@ namespace Lieb.Data context.RaidRoles.RemoveRange(template.Roles); context.RaidReminders.RemoveRange(template.Reminders); context.DiscordRaidMessages.RemoveRange(template.DiscordRaidMessages); + context.RaidLogs.RemoveRange(template.TemplateLogs); await context.SaveChangesAsync(); + template.Roles.Clear(); + template.Reminders.Clear(); + template.DiscordRaidMessages.Clear(); + template.TemplateLogs.Clear(); context.RaidTemplates.Remove(template); await context.SaveChangesAsync(); } diff --git a/Lieb/Migrations/20221129223320_RemovedRaidFromDiscordMessage.Designer.cs b/Lieb/Migrations/20221129223320_RemovedRaidFromDiscordMessage.Designer.cs new file mode 100644 index 0000000..0a2ca78 --- /dev/null +++ b/Lieb/Migrations/20221129223320_RemovedRaidFromDiscordMessage.Designer.cs @@ -0,0 +1,690 @@ +// +using System; +using Lieb.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Lieb.Migrations +{ + [DbContext(typeof(LiebContext))] + [Migration("20221129223320_RemovedRaidFromDiscordMessage")] + partial class RemovedRaidFromDiscordMessage + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.10"); + + modelBuilder.Entity("Lieb.Models.DiscordSettings", b => + { + b.Property("DiscordSettingsId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ChangeUserNames") + .HasColumnType("INTEGER"); + + b.Property("DiscordLogChannel") + .HasColumnType("INTEGER"); + + b.HasKey("DiscordSettingsId"); + + b.ToTable("DiscordSettings", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Equipped", b => + { + b.Property("EquippedId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CanTank") + .HasColumnType("INTEGER"); + + b.Property("GuildWars2AccountId") + .HasColumnType("INTEGER"); + + b.Property("GuildWars2BuildId") + .HasColumnType("INTEGER"); + + b.HasKey("EquippedId"); + + b.HasIndex("GuildWars2AccountId"); + + b.HasIndex("GuildWars2BuildId"); + + b.ToTable("Equipped", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Account", b => + { + b.Property("GuildWars2AccountId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AccountName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ApiKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LiebUserId") + .HasColumnType("INTEGER"); + + b.HasKey("GuildWars2AccountId"); + + b.HasIndex("LiebUserId"); + + b.ToTable("GuildWars2Account", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Build", b => + { + b.Property("GuildWars2BuildId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Alacrity") + .HasColumnType("INTEGER"); + + b.Property("BuildName") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("EliteSpecialization") + .HasColumnType("INTEGER"); + + b.Property("Heal") + .HasColumnType("INTEGER"); + + b.Property("Might") + .HasColumnType("INTEGER"); + + b.Property("Quickness") + .HasColumnType("INTEGER"); + + b.HasKey("GuildWars2BuildId"); + + b.ToTable("GuildWars2Build", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.DiscordRaidMessage", b => + { + b.Property("DiscordRaidMessageId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiscordChannelId") + .HasColumnType("INTEGER"); + + b.Property("DiscordGuildId") + .HasColumnType("INTEGER"); + + b.Property("DiscordMessageId") + .HasColumnType("INTEGER"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidTemplateId") + .HasColumnType("INTEGER"); + + b.HasKey("DiscordRaidMessageId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidTemplateId"); + + b.ToTable("DiscordRaidMessage", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.Raid", b => + { + b.Property("RaidId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("TEXT"); + + b.Property("EndTimeUTC") + .HasColumnType("TEXT"); + + b.Property("FreeForAllTimeUTC") + .HasColumnType("TEXT"); + + b.Property("Guild") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("MoveFlexUsers") + .HasColumnType("INTEGER"); + + b.Property("Organizer") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("RaidOwnerId") + .HasColumnType("INTEGER"); + + b.Property("RaidType") + .HasColumnType("INTEGER"); + + b.Property("RequiredRole") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("StartTimeUTC") + .HasColumnType("TEXT"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("VoiceChat") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("RaidId"); + + b.ToTable("Raid", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidLog", b => + { + b.Property("RaidLogId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("LogEntry") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidTemplateId") + .HasColumnType("INTEGER"); + + b.Property("Time") + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("RaidLogId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidTemplateId"); + + b.HasIndex("UserId"); + + b.ToTable("RaidLog", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidReminder", b => + { + b.Property("RaidReminderId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiscordChannelId") + .HasColumnType("INTEGER"); + + b.Property("DiscordServerId") + .HasColumnType("INTEGER"); + + b.Property("Message") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("TEXT"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidTemplateId") + .HasColumnType("INTEGER"); + + b.Property("ReminderTimeUTC") + .HasColumnType("TEXT"); + + b.Property("Sent") + .HasColumnType("INTEGER"); + + b.Property("TimeType") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("RaidReminderId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidTemplateId"); + + b.ToTable("RaidReminder", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidRole", b => + { + b.Property("RaidRoleId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsRandomSignUpRole") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidTemplateId") + .HasColumnType("INTEGER"); + + b.Property("Spots") + .HasColumnType("INTEGER"); + + b.HasKey("RaidRoleId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidTemplateId"); + + b.ToTable("RaidRole", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidSignUp", b => + { + b.Property("RaidSignUpId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ExternalUserName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("GuildWars2AccountId") + .HasColumnType("INTEGER"); + + b.Property("LiebUserId") + .HasColumnType("INTEGER"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidRoleId") + .HasColumnType("INTEGER"); + + b.Property("SignUpType") + .HasColumnType("INTEGER"); + + b.HasKey("RaidSignUpId"); + + b.HasIndex("GuildWars2AccountId"); + + b.HasIndex("LiebUserId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidRoleId"); + + b.ToTable("RaidSignUp", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidTemplate", b => + { + b.Property("RaidTemplateId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreateDaysBefore") + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("TEXT"); + + b.Property("EndTime") + .HasColumnType("TEXT"); + + b.Property("FreeForAllTime") + .HasColumnType("TEXT"); + + b.Property("Guild") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Interval") + .HasColumnType("INTEGER"); + + b.Property("MoveFlexUsers") + .HasColumnType("INTEGER"); + + b.Property("Organizer") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("RaidOwnerId") + .HasColumnType("INTEGER"); + + b.Property("RaidType") + .HasColumnType("INTEGER"); + + b.Property("RequiredRole") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("StartTime") + .HasColumnType("TEXT"); + + b.Property("TimeZone") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("VoiceChat") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("RaidTemplateId"); + + b.ToTable("RaidTemplate", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.LiebRole", b => + { + b.Property("LiebRoleId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Level") + .HasColumnType("INTEGER"); + + b.Property("LevelToAssign") + .HasColumnType("INTEGER"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("LiebRoleId"); + + b.ToTable("LiebRole", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.LiebUser", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("AlwaysSignUpWithMainAccount") + .HasColumnType("INTEGER"); + + b.Property("BannedUntil") + .HasColumnType("TEXT"); + + b.Property("Birthday") + .HasColumnType("TEXT"); + + b.Property("MainGW2Account") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Pronouns") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("LiebUser", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.RoleAssignment", b => + { + b.Property("RoleAssignmentId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("LiebRoleId") + .HasColumnType("INTEGER"); + + b.Property("LiebUserId") + .HasColumnType("INTEGER"); + + b.HasKey("RoleAssignmentId"); + + b.HasIndex("LiebRoleId"); + + b.HasIndex("LiebUserId"); + + b.ToTable("RoleAssignment", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Equipped", b => + { + b.HasOne("Lieb.Models.GuildWars2.GuildWars2Account", "GuildWars2Account") + .WithMany("EquippedBuilds") + .HasForeignKey("GuildWars2AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lieb.Models.GuildWars2.GuildWars2Build", "GuildWars2Build") + .WithMany("EquippedRoles") + .HasForeignKey("GuildWars2BuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("GuildWars2Account"); + + b.Navigation("GuildWars2Build"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Account", b => + { + b.HasOne("Lieb.Models.LiebUser", null) + .WithMany("GuildWars2Accounts") + .HasForeignKey("LiebUserId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.DiscordRaidMessage", b => + { + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) + .WithMany("DiscordRaidMessages") + .HasForeignKey("RaidId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", null) + .WithMany("DiscordRaidMessages") + .HasForeignKey("RaidTemplateId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidLog", b => + { + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", "Raid") + .WithMany("RaidLogs") + .HasForeignKey("RaidId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", "RaidTemplate") + .WithMany("TemplateLogs") + .HasForeignKey("RaidTemplateId"); + + b.HasOne("Lieb.Models.LiebUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Raid"); + + b.Navigation("RaidTemplate"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidReminder", b => + { + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) + .WithMany("Reminders") + .HasForeignKey("RaidId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", null) + .WithMany("Reminders") + .HasForeignKey("RaidTemplateId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidRole", b => + { + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) + .WithMany("Roles") + .HasForeignKey("RaidId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", null) + .WithMany("Roles") + .HasForeignKey("RaidTemplateId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidSignUp", b => + { + b.HasOne("Lieb.Models.GuildWars2.GuildWars2Account", "GuildWars2Account") + .WithMany() + .HasForeignKey("GuildWars2AccountId"); + + b.HasOne("Lieb.Models.LiebUser", "LiebUser") + .WithMany() + .HasForeignKey("LiebUserId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", "Raid") + .WithMany("SignUps") + .HasForeignKey("RaidId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidRole", "RaidRole") + .WithMany() + .HasForeignKey("RaidRoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("GuildWars2Account"); + + b.Navigation("LiebUser"); + + b.Navigation("Raid"); + + b.Navigation("RaidRole"); + }); + + modelBuilder.Entity("Lieb.Models.RoleAssignment", b => + { + b.HasOne("Lieb.Models.LiebRole", "LiebRole") + .WithMany("RoleAssignments") + .HasForeignKey("LiebRoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lieb.Models.LiebUser", "LiebUser") + .WithMany("RoleAssignments") + .HasForeignKey("LiebUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("LiebRole"); + + b.Navigation("LiebUser"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Account", b => + { + b.Navigation("EquippedBuilds"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Build", b => + { + b.Navigation("EquippedRoles"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.Raid", b => + { + b.Navigation("DiscordRaidMessages"); + + b.Navigation("RaidLogs"); + + b.Navigation("Reminders"); + + b.Navigation("Roles"); + + b.Navigation("SignUps"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidTemplate", b => + { + b.Navigation("DiscordRaidMessages"); + + b.Navigation("Reminders"); + + b.Navigation("Roles"); + + b.Navigation("TemplateLogs"); + }); + + modelBuilder.Entity("Lieb.Models.LiebRole", b => + { + b.Navigation("RoleAssignments"); + }); + + modelBuilder.Entity("Lieb.Models.LiebUser", b => + { + b.Navigation("GuildWars2Accounts"); + + b.Navigation("RoleAssignments"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Lieb/Migrations/20221129223320_RemovedRaidFromDiscordMessage.cs b/Lieb/Migrations/20221129223320_RemovedRaidFromDiscordMessage.cs new file mode 100644 index 0000000..7ff5450 --- /dev/null +++ b/Lieb/Migrations/20221129223320_RemovedRaidFromDiscordMessage.cs @@ -0,0 +1,97 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Lieb.Migrations +{ + public partial class RemovedRaidFromDiscordMessage : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_DiscordRaidMessage_Raid_RaidId", + table: "DiscordRaidMessage"); + + migrationBuilder.DropForeignKey( + name: "FK_RaidReminder_Raid_RaidId", + table: "RaidReminder"); + + migrationBuilder.AlterColumn( + name: "RaidId", + table: "RaidReminder", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "RaidId", + table: "DiscordRaidMessage", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AddForeignKey( + name: "FK_DiscordRaidMessage_Raid_RaidId", + table: "DiscordRaidMessage", + column: "RaidId", + principalTable: "Raid", + principalColumn: "RaidId"); + + migrationBuilder.AddForeignKey( + name: "FK_RaidReminder_Raid_RaidId", + table: "RaidReminder", + column: "RaidId", + principalTable: "Raid", + principalColumn: "RaidId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_DiscordRaidMessage_Raid_RaidId", + table: "DiscordRaidMessage"); + + migrationBuilder.DropForeignKey( + name: "FK_RaidReminder_Raid_RaidId", + table: "RaidReminder"); + + migrationBuilder.AlterColumn( + name: "RaidId", + table: "RaidReminder", + type: "INTEGER", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "RaidId", + table: "DiscordRaidMessage", + type: "INTEGER", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_DiscordRaidMessage_Raid_RaidId", + table: "DiscordRaidMessage", + column: "RaidId", + principalTable: "Raid", + principalColumn: "RaidId", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_RaidReminder_Raid_RaidId", + table: "RaidReminder", + column: "RaidId", + principalTable: "Raid", + principalColumn: "RaidId", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/Lieb/Migrations/LiebContextModelSnapshot.cs b/Lieb/Migrations/LiebContextModelSnapshot.cs index 4c2446f..9bf1521 100644 --- a/Lieb/Migrations/LiebContextModelSnapshot.cs +++ b/Lieb/Migrations/LiebContextModelSnapshot.cs @@ -131,7 +131,7 @@ namespace Lieb.Migrations b.Property("DiscordMessageId") .HasColumnType("INTEGER"); - b.Property("RaidId") + b.Property("RaidId") .HasColumnType("INTEGER"); b.Property("RaidTemplateId") @@ -257,7 +257,7 @@ namespace Lieb.Migrations .HasMaxLength(1000) .HasColumnType("TEXT"); - b.Property("RaidId") + b.Property("RaidId") .HasColumnType("INTEGER"); b.Property("RaidTemplateId") @@ -533,17 +533,13 @@ namespace Lieb.Migrations modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.DiscordRaidMessage", b => { - b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", "Raid") + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) .WithMany("DiscordRaidMessages") - .HasForeignKey("RaidId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("RaidId"); b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", null) .WithMany("DiscordRaidMessages") .HasForeignKey("RaidTemplateId"); - - b.Navigation("Raid"); }); modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidLog", b => @@ -571,17 +567,13 @@ namespace Lieb.Migrations modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidReminder", b => { - b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", "Raid") + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) .WithMany("Reminders") - .HasForeignKey("RaidId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("RaidId"); b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", null) .WithMany("Reminders") .HasForeignKey("RaidTemplateId"); - - b.Navigation("Raid"); }); modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidRole", b => diff --git a/Lieb/Models/GuildWars2/Raid/DiscordRaidMessage.cs b/Lieb/Models/GuildWars2/Raid/DiscordRaidMessage.cs index f85c3ac..ac6dd06 100644 --- a/Lieb/Models/GuildWars2/Raid/DiscordRaidMessage.cs +++ b/Lieb/Models/GuildWars2/Raid/DiscordRaidMessage.cs @@ -6,11 +6,6 @@ namespace Lieb.Models.GuildWars2.Raid { public int DiscordRaidMessageId { get; set; } - public int RaidId { get; set; } - - [JsonIgnore(Condition = JsonIgnoreCondition.Always)] - public Raid Raid { get; set; } - public ulong DiscordMessageId { get; set; } public ulong DiscordChannelId { get; set; } diff --git a/Lieb/Models/GuildWars2/Raid/RaidBase.cs b/Lieb/Models/GuildWars2/Raid/RaidBase.cs index 35772d7..1ad0ffc 100644 --- a/Lieb/Models/GuildWars2/Raid/RaidBase.cs +++ b/Lieb/Models/GuildWars2/Raid/RaidBase.cs @@ -72,16 +72,15 @@ namespace Lieb.Models.GuildWars2.Raid DiscordChannelId = reminder.DiscordChannelId, ReminderTimeUTC = reminder.ReminderTimeUTC, Message = reminder.Message, - Sent = reminder.Sent, + Sent = false, Type = reminder.Type, - RaidId = reminder.RaidId + TimeType = reminder.TimeType }); } foreach (DiscordRaidMessage message in template.DiscordRaidMessages) { this.DiscordRaidMessages.Add(new DiscordRaidMessage() { - RaidId = message.RaidId, DiscordChannelId = message.DiscordChannelId, DiscordGuildId = message.DiscordGuildId }); diff --git a/Lieb/Models/GuildWars2/Raid/RaidLog.cs b/Lieb/Models/GuildWars2/Raid/RaidLog.cs index b25db87..d6a1f0e 100644 --- a/Lieb/Models/GuildWars2/Raid/RaidLog.cs +++ b/Lieb/Models/GuildWars2/Raid/RaidLog.cs @@ -32,6 +32,7 @@ namespace Lieb.Models.GuildWars2.Raid [JsonIgnore(Condition = JsonIgnoreCondition.Always)] public Raid? Raid { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.Always)] public RaidTemplate? RaidTemplate { get; set; } public static RaidLog CreateRaidLog(ulong userId, Raid raid) diff --git a/Lieb/Models/GuildWars2/Raid/RaidReminder.cs b/Lieb/Models/GuildWars2/Raid/RaidReminder.cs index 1fab409..f1d3568 100644 --- a/Lieb/Models/GuildWars2/Raid/RaidReminder.cs +++ b/Lieb/Models/GuildWars2/Raid/RaidReminder.cs @@ -39,11 +39,6 @@ namespace Lieb.Models.GuildWars2.Raid public ulong DiscordChannelId { get; set; } public bool Sent { get; set; } = false; - - public int RaidId { get; set; } - - [JsonIgnore(Condition = JsonIgnoreCondition.Always)] - public Raid Raid { get; set; } } public class StaticRaidReminder : RaidReminder diff --git a/Lieb/Pages/Raids/RaidEdit/RaidTemplateEdit.razor b/Lieb/Pages/Raids/RaidEdit/RaidTemplateEdit.razor index d0935eb..14e59f1 100644 --- a/Lieb/Pages/Raids/RaidEdit/RaidTemplateEdit.razor +++ b/Lieb/Pages/Raids/RaidEdit/RaidTemplateEdit.razor @@ -7,6 +7,7 @@ @using System.Security.Claims @using SharedClasses.SharedModels @inject RaidTemplateService RaidTemplateService +@inject RaidService RaidService @inject UserService UserService @inject DiscordService DiscordService @inject TimeZoneService TimeZoneService @@ -289,13 +290,15 @@ { if(_template.RaidType != RaidType.Planned) { - _template.Roles.Clear(); - _template.Roles.Add(new RaidRole() - { - Spots = 10, - Name = "Random", - Description = _template.RaidType.ToString() - }); + if(!_template.Roles.Where(r => r.IsRandomSignUpRole).Any()) + { + _template.Roles.Add(RaidService.CreateRandomSignUpRole(_template.RaidType)); + } + + foreach(RaidRole role in _template.Roles.Where(r => !r.IsRandomSignUpRole)) + { + _rolesToDelete.Add(role); + } } if(_template.Roles.Count == 0) @@ -326,11 +329,13 @@ foreach(DynamicRaidReminder reminder in _dynamicReminders) { reminder.ReminderTimeUTC = _template.StartTime - new TimeSpan(reminder.DaysBeforeRaid, reminder.HoursBeforeRaid, reminder.MinutesBeforeRaid, 0); + reminder.Sent = true; _template.Reminders.Add(reminder); } foreach(StaticRaidReminder reminder in _staticReminders) { reminder.ReminderTimeUTC = await TimeZoneService.GetUTCDateTime(reminder.ReminderDate.Date + reminder.ReminderTime.TimeOfDay); + reminder.Sent = true; _template.Reminders.Add(reminder); }