added RaidEdit page

This commit is contained in:
t.ruspekhofer 2022-02-26 18:53:39 +01:00
parent bd47610371
commit a3062165e1
9 changed files with 343 additions and 46 deletions

View file

@ -38,7 +38,7 @@ namespace Lieb.Data
var users = new LiebUser[]
{
new LiebUser{DiscordUserId=194863625477816321, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith} },
new LiebUser{DiscordUserId=194863625477816321, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
new LiebUser{DiscordUserId=1, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}},
new LiebUser{DiscordUserId=2, Name="Simon", GuildWars2Accounts = new List<GuildWars2Account>(){ bloodseeker}}
};
@ -89,9 +89,10 @@ namespace Lieb.Data
Description = "This is a test raid\nwith multiple lines?",
Guild = "LIEB",
Organizer = "Sarah",
RaidDuration = 2,
RaidType = RaidType.RandomClasses,
Date = DateTime.Now.Date,
StartTime = DateTime.Now,
EndTime = DateTime.Now.AddHours(2),
VoiceChat = "ts.lieb.games",
Roles = new [] { ele, scourge}
};

View file

@ -44,16 +44,98 @@ namespace Lieb.Data
.FirstOrDefault(r => r.RaidId == raidId);
}
public async Task CreateRaid(Raid raid)
public async Task AddOrEditRaid(Raid raid)
{
if (raid == null)
if (raid != null)
{
using var context = _contextFactory.CreateDbContext();
context.Raids.Add(raid);
await context.SaveChangesAsync();
if (raid.RaidId == 0)
{
context.Raids.Add(raid);
await context.SaveChangesAsync();
}
else
{
Raid raidToChange = await context.Raids
.Include(r => r.Roles)
.Include(r => r.SignUpHistory)
.Include(r => r.Reminders)
.Include(r => r.SignUps)
.FirstOrDefaultAsync(r => r.RaidId == raid.RaidId);
raidToChange.Title = raid.Title;
raidToChange.Description = raid.Description;
raidToChange.Date = raid.Date;
raidToChange.StartTime = raid.StartTime;
raidToChange.EndTime = raid.EndTime;
raidToChange.Organizer = raid.Organizer;
raidToChange.Guild = raid.Guild;
raidToChange.VoiceChat = raid.VoiceChat;
raidToChange.RaidType = raid.RaidType;
raidToChange.Frequency = raid.Frequency;
raidToChange.DiscordMessageId = raid.DiscordMessageId;
raidToChange.DiscordChannelId = raid.DiscordChannelId;
raidToChange.DiscordGuildId = raid.DiscordGuildId;
foreach(PlannedRaidRole role in raidToChange.Roles)
{
PlannedRaidRole? newRole = raid.Roles.FirstOrDefault(r => r.PlannedRaidRoleId == role.PlannedRaidRoleId);
if(newRole != null)
{
role.Spots = newRole.Spots;
role.Name = newRole.Name;
role.Description = newRole.Description;
}
else
{
raidToChange.Roles.Remove(role);
context.PlannedRaidRoles.Remove(role);
}
}
foreach (PlannedRaidRole role in raid.Roles.Where(r => r.PlannedRaidRoleId == 0))
{
raidToChange.Roles.Add(role);
}
foreach (RaidReminder reminder in raidToChange.Reminders)
{
RaidReminder? newReminder = raid.Reminders.FirstOrDefault(r => r.RaidReminderId == reminder.RaidReminderId);
if (newReminder != null)
{
reminder.Type = newReminder.Type;
reminder.Message = newReminder.Message;
reminder.HoursBeforeRaid = newReminder.HoursBeforeRaid;
reminder.ChannelId = newReminder.ChannelId;
reminder.Sent = newReminder.Sent;
}
else
{
raidToChange.Reminders.Remove(reminder);
context.RaidReminders.Remove(reminder);
}
}
foreach (PlannedRaidRole role in raid.Roles.Where(r => r.PlannedRaidRoleId == 0))
{
raidToChange.Roles.Add(role);
}
await context.SaveChangesAsync();
}
}
}
public async Task DeleteRaid(int raidId)
{
using var context = _contextFactory.CreateDbContext();
Raid raid = GetRaid(raidId);
context.RaidSignUps.RemoveRange(raid.SignUps);
context.PlannedRaidRoles.RemoveRange(raid.Roles);
context.SignUpHistories.RemoveRange(raid.SignUpHistory);
context.RaidReminders.RemoveRange(raid.Reminders);
await context.SaveChangesAsync();
context.Raids.Remove(raid);
await context.SaveChangesAsync();
}
public async Task SignUp(int raidId, int liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType)
{
if (!IsSignUpAllowed(liebUserId, plannedRoleId, signUpType))