added RaidDetails.razor + needed services
This commit is contained in:
parent
6da9b06e8a
commit
b18cc58665
15 changed files with 597 additions and 18 deletions
2
Lieb.sln
2
Lieb.sln
|
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.0.32126.317
|
VisualStudioVersion = 17.0.32126.317
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lieb", "Lieb\Lieb.csproj", "{48554958-F16E-466A-B9B7-F17511FDA415}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lieb", "Lieb\Lieb.csproj", "{48554958-F16E-466A-B9B7-F17511FDA415}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using Lieb.Models;
|
using Lieb.Models;
|
||||||
|
using Lieb.Models.GuildWars2;
|
||||||
|
using Lieb.Models.GuildWars2.Raid;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Lieb.Data
|
namespace Lieb.Data
|
||||||
|
@ -29,12 +31,16 @@ namespace Lieb.Data
|
||||||
return; // DB has been seeded
|
return; // DB has been seeded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GuildWars2Account linaith = new GuildWars2Account() { AccountName = "Linaith.2375" };
|
||||||
|
GuildWars2Account sarah = new GuildWars2Account() { AccountName = "Sarah.3984" };
|
||||||
|
GuildWars2Account hierpiepts = new GuildWars2Account() { AccountName = "hierpiepts.5241" };
|
||||||
|
GuildWars2Account bloodseeker = new GuildWars2Account() { AccountName = "Bloodseeker.2043" };
|
||||||
|
|
||||||
var users = new LiebUser[]
|
var users = new LiebUser[]
|
||||||
{
|
{
|
||||||
new LiebUser{DiscordUserId=194863625477816321, Name="Sarah", Birthday=DateTime.Parse("1992-01-15")},
|
new LiebUser{DiscordUserId=194863625477816321, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith} },
|
||||||
new LiebUser{DiscordUserId=1, Name="Lisa"},
|
new LiebUser{DiscordUserId=1, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}},
|
||||||
new LiebUser{DiscordUserId=2, Name="Simon"}
|
new LiebUser{DiscordUserId=2, Name="Simon", GuildWars2Accounts = new List<GuildWars2Account>(){ bloodseeker}}
|
||||||
};
|
};
|
||||||
|
|
||||||
context.LiebUsers.AddRange(users);
|
context.LiebUsers.AddRange(users);
|
||||||
|
@ -63,6 +69,45 @@ namespace Lieb.Data
|
||||||
|
|
||||||
context.RoleAssignments.AddRange(assignments);
|
context.RoleAssignments.AddRange(assignments);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
|
PlannedRaidRole ele = new PlannedRaidRole()
|
||||||
|
{
|
||||||
|
Description = "Beste",
|
||||||
|
Name = "Heal Ele",
|
||||||
|
Spots = 2
|
||||||
|
};
|
||||||
|
PlannedRaidRole scourge = new PlannedRaidRole()
|
||||||
|
{
|
||||||
|
Description = "WupWup",
|
||||||
|
Name = "Scourge",
|
||||||
|
Spots = 8
|
||||||
|
};
|
||||||
|
|
||||||
|
Raid raid = new Raid()
|
||||||
|
{
|
||||||
|
Title = "Testraid",
|
||||||
|
Description = "This is a test raid\nwith multiple lines?",
|
||||||
|
Guild = "LIEB",
|
||||||
|
Organizer = "Sarah",
|
||||||
|
RaidDuration = 2,
|
||||||
|
RaidType = RaidType.RandomClasses,
|
||||||
|
StartTime = DateTime.Now,
|
||||||
|
VoiceChat = "ts.lieb.games",
|
||||||
|
Roles = new [] { ele, scourge}
|
||||||
|
};
|
||||||
|
context.Raids.Add(raid);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
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 = hierpiepts.GuildWars2AccountId, LiebUserId = users[1].LiebUserId, PlannedRaidRoleId = scourge.PlannedRaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.SignedUp },
|
||||||
|
new RaidSignUp{GuildWars2AccountId = bloodseeker.GuildWars2AccountId, LiebUserId = users[2].LiebUserId, PlannedRaidRoleId = scourge.PlannedRaidRoleId, RaidId = raid.RaidId, SignUpType = SignUpType.Maybe }
|
||||||
|
};
|
||||||
|
|
||||||
|
context.RaidSignUps.AddRange(signUps);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
84
Lieb/Data/GuildWars2AccountService.cs
Normal file
84
Lieb/Data/GuildWars2AccountService.cs
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
using Lieb.Models;
|
||||||
|
using Lieb.Models.GuildWars2;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Lieb.Data
|
||||||
|
{
|
||||||
|
public class GuildWars2AccountService
|
||||||
|
{
|
||||||
|
private readonly IDbContextFactory<LiebContext> _contextFactory;
|
||||||
|
|
||||||
|
public GuildWars2AccountService(IDbContextFactory<LiebContext> contextFactory)
|
||||||
|
{
|
||||||
|
_contextFactory = contextFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AddAccount(GuildWars2Account guildWars2Account, ulong discordId)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
LiebUser liebUser = await context.LiebUsers.FirstOrDefaultAsync(u => u.DiscordUserId == discordId);
|
||||||
|
if (liebUser != null)
|
||||||
|
{
|
||||||
|
liebUser.GuildWars2Accounts.Add(guildWars2Account);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpdateAccount(int guildWars2AccountId, string accountName, string apiKey)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
GuildWars2Account account = await context.GuildWars2Accounts.FirstOrDefaultAsync(u => u.GuildWars2AccountId == guildWars2AccountId);
|
||||||
|
if (account != null)
|
||||||
|
{
|
||||||
|
account.ApiKey = apiKey;
|
||||||
|
if (!string.IsNullOrEmpty(accountName))
|
||||||
|
{
|
||||||
|
account.AccountName = accountName;
|
||||||
|
}
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RemoveAccount()
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AddBuildToAccount()
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RemoveBuildFromAccount()
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<GuildWars2Build>> GetBuilds()
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
return context.GuildWars2Builds.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task CreateBuild()
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpdateBuild()
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteBuild()
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,9 +16,9 @@ namespace Lieb.Data
|
||||||
public DbSet<LiebUser> LiebUsers { get; set; }
|
public DbSet<LiebUser> LiebUsers { get; set; }
|
||||||
public DbSet<RoleAssignment> RoleAssignments { get; set; }
|
public DbSet<RoleAssignment> RoleAssignments { get; set; }
|
||||||
public DbSet<LiebRole> LiebRoles { get; set; }
|
public DbSet<LiebRole> LiebRoles { get; set; }
|
||||||
public DbSet<GuildWars2Account> GuildWars2Account { get; set; }
|
public DbSet<GuildWars2Account> GuildWars2Accounts { get; set; }
|
||||||
public DbSet<Equipped> Equipped { get; set; }
|
public DbSet<Equipped> Equipped { get; set; }
|
||||||
public DbSet<GuildWars2Build> RaidRoles { get; set; }
|
public DbSet<GuildWars2Build> GuildWars2Builds { get; set; }
|
||||||
public DbSet<PlannedRaidRole> PlannedRaidRoles { get; set; }
|
public DbSet<PlannedRaidRole> PlannedRaidRoles { get; set; }
|
||||||
public DbSet<Raid> Raids { get; set; }
|
public DbSet<Raid> Raids { get; set; }
|
||||||
public DbSet<RaidReminder> RaidReminders { get; set; }
|
public DbSet<RaidReminder> RaidReminders { get; set; }
|
||||||
|
|
143
Lieb/Data/RaidService.cs
Normal file
143
Lieb/Data/RaidService.cs
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
using Lieb.Models.GuildWars2.Raid;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Lieb.Data
|
||||||
|
{
|
||||||
|
public class RaidService
|
||||||
|
{
|
||||||
|
private readonly IDbContextFactory<LiebContext> _contextFactory;
|
||||||
|
|
||||||
|
public RaidService(IDbContextFactory<LiebContext> contextFactory)
|
||||||
|
{
|
||||||
|
_contextFactory = contextFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Raid> GetRaids()
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
return context.Raids
|
||||||
|
.Include(r => r.Roles)
|
||||||
|
.Include(r => r.SignUpHistory)
|
||||||
|
.Include(r => r.Reminders)
|
||||||
|
.Include(r => r.SignUps)
|
||||||
|
.ThenInclude(s => s.LiebUser)
|
||||||
|
.Include(r => r.SignUps)
|
||||||
|
.ThenInclude(s => s.GuildWars2Account)
|
||||||
|
.Include(r => r.SignUps)
|
||||||
|
.ThenInclude(s => s.PlannedRaidRole)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Raid GetRaid(int raidId)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
return context.Raids
|
||||||
|
.Include(r => r.Roles)
|
||||||
|
.Include(r => r.SignUpHistory)
|
||||||
|
.Include(r => r.Reminders)
|
||||||
|
.Include(r => r.SignUps)
|
||||||
|
.ThenInclude(s => s.LiebUser)
|
||||||
|
.Include(r => r.SignUps)
|
||||||
|
.ThenInclude(s => s.GuildWars2Account)
|
||||||
|
.Include(r => r.SignUps)
|
||||||
|
.ThenInclude(s => s.PlannedRaidRole)
|
||||||
|
.FirstOrDefault(r => r.RaidId == raidId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task CreateRaid(Raid raid)
|
||||||
|
{
|
||||||
|
if (raid == null)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
context.Raids.Add(raid);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<PlannedRaidRole>> GetFreeRoles(int raidId)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
Raid? raid = await context.Raids
|
||||||
|
.Include(r => r.Roles)
|
||||||
|
.Include(r => r.SignUps)
|
||||||
|
.FirstOrDefaultAsync(r => r.RaidId == raidId);
|
||||||
|
|
||||||
|
List<PlannedRaidRole> freeRoles = new List<PlannedRaidRole>();
|
||||||
|
if (raid != null)
|
||||||
|
{
|
||||||
|
List<int> plannedRolesIds = raid.SignUps.Select(s => s.PlannedRaidRoleId).ToList();
|
||||||
|
Dictionary<int, int> addedIds = new Dictionary<int, int>();
|
||||||
|
|
||||||
|
foreach (RaidSignUp signUp in raid.SignUps)
|
||||||
|
{
|
||||||
|
if (signUp.SignUpType == SignUpType.SignedUp || signUp.SignUpType == SignUpType.Maybe)
|
||||||
|
{
|
||||||
|
int id = signUp.PlannedRaidRoleId;
|
||||||
|
if (addedIds.ContainsKey(id))
|
||||||
|
{
|
||||||
|
addedIds[id] += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addedIds.Add(id, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach(PlannedRaidRole role in raid.Roles)
|
||||||
|
{
|
||||||
|
if(!addedIds.ContainsKey(role.PlannedRaidRoleId) || role.Spots > addedIds[role.PlannedRaidRoleId])
|
||||||
|
{
|
||||||
|
freeRoles.Add(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return freeRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SignUp(int raidId, int liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType)
|
||||||
|
{
|
||||||
|
if ((await GetFreeRoles(raidId)).Where(r => r.PlannedRaidRoleId == plannedRoleId).Any())
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
context.RaidSignUps.Add(new RaidSignUp()
|
||||||
|
{
|
||||||
|
GuildWars2AccountId = guildWars2AccountId,
|
||||||
|
RaidId = raidId,
|
||||||
|
LiebUserId = liebUserId,
|
||||||
|
PlannedRaidRoleId = plannedRoleId,
|
||||||
|
SignUpType = signUpType
|
||||||
|
});
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SignOff(int raidId, int liebUserId)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
List<RaidSignUp> signUps = context.RaidSignUps.Where(x => x.RaidId == raidId && x.LiebUserId == liebUserId).ToList();
|
||||||
|
context.RaidSignUps.RemoveRange(signUps);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ChangeAccount(int raidId, int liebUserId, int guildWars2AccountId)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
List<RaidSignUp> signUps = context.RaidSignUps.Where(x => x.RaidId == raidId && x.LiebUserId == liebUserId).ToList();
|
||||||
|
foreach(RaidSignUp signUp in signUps)
|
||||||
|
{
|
||||||
|
signUp.GuildWars2AccountId = guildWars2AccountId;
|
||||||
|
}
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ChangeSignUpType(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
RaidSignUp signUp = await context.RaidSignUps.FirstOrDefaultAsync(x => x.RaidId == raidId && x.LiebUserId == liebUserId && x.SignUpType != SignUpType.SignedOff && x.SignUpType != SignUpType.Flex);
|
||||||
|
signUp.PlannedRaidRoleId = plannedRoleId;
|
||||||
|
signUp.SignUpType = signUpType;
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
56
Lieb/Data/UserService.cs
Normal file
56
Lieb/Data/UserService.cs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
using Lieb.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Lieb.Data
|
||||||
|
{
|
||||||
|
public class UserService
|
||||||
|
{
|
||||||
|
private readonly IDbContextFactory<LiebContext> _contextFactory;
|
||||||
|
|
||||||
|
public UserService(IDbContextFactory<LiebContext> contextFactory)
|
||||||
|
{
|
||||||
|
_contextFactory = contextFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<LiebUser> GetLiebUser(ulong discordId)
|
||||||
|
{
|
||||||
|
if (discordId > 0)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
return await context.LiebUsers
|
||||||
|
.Include(u => u.GuildWars2Accounts)
|
||||||
|
.ThenInclude(a => a.EquippedBuilds)
|
||||||
|
.ThenInclude(b => b.GuildWars2Build)
|
||||||
|
.Include(u => u.RoleAssignments)
|
||||||
|
.ThenInclude(r => r.LiebRole)
|
||||||
|
.FirstOrDefaultAsync(u => u.DiscordUserId == discordId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return new LiebUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiebUser GetLiebUserSmall(ulong discordId)
|
||||||
|
{
|
||||||
|
if (discordId > 0)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
return context.LiebUsers
|
||||||
|
.Include(u => u.GuildWars2Accounts)
|
||||||
|
.FirstOrDefault(u => u.DiscordUserId == discordId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return new LiebUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> GetLiebUserId(ulong discordId)
|
||||||
|
{
|
||||||
|
if (discordId > 0)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
return (await context.LiebUsers.FirstOrDefaultAsync(u => u.DiscordUserId == discordId)).LiebUserId;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,10 +6,6 @@
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Pages\Raids\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.2" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.2" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.2" />
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
public int GuildWars2AccountId { get; set; }
|
public int GuildWars2AccountId { get; set; }
|
||||||
public string ApiKey { get; set; } = string.Empty;
|
public string ApiKey { get; set; } = string.Empty;
|
||||||
public string AccountName { get; set; } = string.Empty;
|
public string AccountName { get; set; } = string.Empty;
|
||||||
public ICollection<Equipped> EquippedRoles { get; set; } = new List<Equipped>();
|
public ICollection<Equipped> EquippedBuilds { get; set; } = new List<Equipped>();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
{
|
{
|
||||||
public int PlannedRaidRoleId { get; set; }
|
public int PlannedRaidRoleId { get; set; }
|
||||||
public string Name { get; set; } = String.Empty;
|
public string Name { get; set; } = String.Empty;
|
||||||
public int Spots { get; }
|
public int Spots { get; set; }
|
||||||
public string Description { get; set; } = String.Empty;
|
public string Description { get; set; } = String.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
public string Description { get; set; } = String.Empty;
|
public string Description { get; set; } = String.Empty;
|
||||||
|
|
||||||
public DateTimeOffset StartTime { get; set; }
|
public DateTime StartTime { get; set; }
|
||||||
|
|
||||||
public double RaidDuration { get; set; }
|
public double RaidDuration { get; set; }
|
||||||
|
|
||||||
public string Organisator { get; set; } = String.Empty;
|
public string Organizer { get; set; } = String.Empty;
|
||||||
|
|
||||||
public string Guild { get; set; } = String.Empty;
|
public string Guild { get; set; } = String.Empty;
|
||||||
|
|
||||||
|
|
188
Lieb/Pages/Raids/RaidDetails.razor
Normal file
188
Lieb/Pages/Raids/RaidDetails.razor
Normal file
|
@ -0,0 +1,188 @@
|
||||||
|
@using System.Security.Claims
|
||||||
|
@using Lieb.Data
|
||||||
|
@using Lieb.Models
|
||||||
|
@using Lieb.Models.GuildWars2.Raid
|
||||||
|
@inject UserService UserService
|
||||||
|
@inject RaidService RaidService
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h5>@Raid.Title</h5>
|
||||||
|
|
||||||
|
<div>@Raid.Description</div>
|
||||||
|
|
||||||
|
<div >
|
||||||
|
<div class="times">
|
||||||
|
<h5>Date</h5>
|
||||||
|
<p>@Raid.StartTime.ToLongDateString()</p>
|
||||||
|
</div>
|
||||||
|
<div class="times">
|
||||||
|
<h5>Time</h5>
|
||||||
|
<p>from: @Raid.StartTime.ToShortTimeString() to: @Raid.StartTime.AddHours(@Raid.RaidDuration).ToShortTimeString()</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="details">
|
||||||
|
<h5>Organizer</h5>
|
||||||
|
<p>@Raid.Organizer</p>
|
||||||
|
</div>
|
||||||
|
<div class="details">
|
||||||
|
<h5>Guild</h5>
|
||||||
|
<p>@Raid.Guild</p>
|
||||||
|
</div>
|
||||||
|
<div class="details">
|
||||||
|
<h5>Voice chat</h5>
|
||||||
|
<p>@Raid.VoiceChat</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<AuthorizeView>
|
||||||
|
<Authorized>
|
||||||
|
@{
|
||||||
|
ulong discordId = ulong.Parse(@context.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
||||||
|
LiebUser user = UserService.GetLiebUserSmall(discordId);
|
||||||
|
RaidSignUp userRole = Raid.SignUps.Where(s => s.LiebUserId == user.LiebUserId).FirstOrDefault();
|
||||||
|
bool isSignedUp = userRole != null;
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<tbody>
|
||||||
|
@foreach (var role in Raid.Roles)
|
||||||
|
{
|
||||||
|
Models.GuildWars2.Raid.RaidSignUp[] signUps = Raid.SignUps.Where(s => s.PlannedRaidRoleId == role.PlannedRaidRoleId).ToArray();
|
||||||
|
int usedSpots = signUps.Where(s => s.SignUpType == SignUpType.SignedUp).Count();
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
@if (@usedSpots < @role.Spots)
|
||||||
|
{
|
||||||
|
<td><button @onclick="() => SignUpClicked(role, user, isSignedUp)">Sign Up</button></td>
|
||||||
|
<td><button @onclick="() => MaybeClicked(role, user, isSignedUp)">Maybe</button></td>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
}
|
||||||
|
<td><button @onclick="() => BackupClicked(role, user, isSignedUp)">Backup</button></td>
|
||||||
|
<td><h5>@role.Name: @role.Description (@usedSpots /@role.Spots)</h5></td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
@foreach (var signUp in signUps)
|
||||||
|
{
|
||||||
|
@if(signUp.SignUpType != SignUpType.SignedOff)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
@{bool isUser = isSignedUp && userRole.PlannedRaidRole.PlannedRaidRoleId == role.PlannedRaidRoleId && signUp.LiebUserId == user.LiebUserId;}
|
||||||
|
@if(isUser)
|
||||||
|
{
|
||||||
|
<td><button @onclick="() => SignOffClicked(role, user)">Sign Off</button></td>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<td></td>
|
||||||
|
}
|
||||||
|
@{string signUpStatus = string.Empty;}
|
||||||
|
@if (signUp.SignUpType != SignUpType.SignedUp) signUpStatus = $" - {signUp.SignUpType}";
|
||||||
|
|
||||||
|
@if (isUser)
|
||||||
|
{
|
||||||
|
<td>@signUp.LiebUser.Name
|
||||||
|
<select value=@signUp.GuildWars2AccountId @onchange="args => ChangeAccount(user, args)">
|
||||||
|
@foreach (var account in user.GuildWars2Accounts)
|
||||||
|
{
|
||||||
|
<option value=@account.GuildWars2AccountId>@account.AccountName</option>
|
||||||
|
}
|
||||||
|
</select> @signUpStatus </td>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<td>@signUp.LiebUser.Name (@signUp.GuildWars2Account.AccountName) @signUpStatus</td>
|
||||||
|
}
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
}
|
||||||
|
</Authorized>
|
||||||
|
<NotAuthorized>
|
||||||
|
@foreach (var role in Raid.Roles)
|
||||||
|
{
|
||||||
|
Models.GuildWars2.Raid.RaidSignUp[] signUps = Raid.SignUps.Where(s => s.PlannedRaidRoleId == role.PlannedRaidRoleId).ToArray();
|
||||||
|
int usedSpots = signUps.Where(s => s.SignUpType == SignUpType.SignedUp).Count();
|
||||||
|
|
||||||
|
<h5>@role.Name: @role.Description (@usedSpots /@role.Spots)</h5>
|
||||||
|
@foreach (var signUp in signUps)
|
||||||
|
{
|
||||||
|
if(signUp.SignUpType != SignUpType.SignedOff)
|
||||||
|
{
|
||||||
|
string signUpStatus = string.Empty;
|
||||||
|
if (signUp.SignUpType != SignUpType.SignedUp) signUpStatus = $" - {signUp.SignUpType}";
|
||||||
|
<div>@signUp.LiebUser.Name (@signUp.GuildWars2Account.AccountName) @signUpStatus</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</NotAuthorized>
|
||||||
|
</AuthorizeView>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public Raid Raid { get; set; }
|
||||||
|
|
||||||
|
async Task SignUpClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp)
|
||||||
|
{
|
||||||
|
if(isSignedUp)
|
||||||
|
{
|
||||||
|
await RaidService.ChangeSignUpType(Raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, SignUpType.SignedUp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await RaidService.SignUp(Raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, SignUpType.SignedUp);
|
||||||
|
}
|
||||||
|
Raid = RaidService.GetRaid(Raid.RaidId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task BackupClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp)
|
||||||
|
{
|
||||||
|
if(isSignedUp)
|
||||||
|
{
|
||||||
|
await RaidService.ChangeSignUpType(Raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, SignUpType.Backup);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await RaidService.SignUp(Raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, SignUpType.Backup);
|
||||||
|
}
|
||||||
|
Raid = RaidService.GetRaid(Raid.RaidId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task MaybeClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp)
|
||||||
|
{
|
||||||
|
if(isSignedUp)
|
||||||
|
{
|
||||||
|
await RaidService.ChangeSignUpType(Raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, SignUpType.Maybe);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await RaidService.SignUp(Raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, SignUpType.Maybe);
|
||||||
|
}
|
||||||
|
Raid = RaidService.GetRaid(Raid.RaidId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task SignOffClicked(PlannedRaidRole role, LiebUser liebUser)
|
||||||
|
{
|
||||||
|
await RaidService.SignOff(Raid.RaidId, liebUser.LiebUserId);
|
||||||
|
Raid = RaidService.GetRaid(Raid.RaidId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task ChangeAccount(LiebUser liebUser, ChangeEventArgs e)
|
||||||
|
{
|
||||||
|
int accountId = int.Parse(e.Value.ToString());
|
||||||
|
await RaidService.ChangeAccount(Raid.RaidId, liebUser.LiebUserId, accountId);
|
||||||
|
Raid = RaidService.GetRaid(Raid.RaidId);
|
||||||
|
}
|
||||||
|
}
|
31
Lieb/Pages/Raids/RaidDetails.razor.css
Normal file
31
Lieb/Pages/Raids/RaidDetails.razor.css
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
body {
|
||||||
|
background-color: rgb(38 38 38);
|
||||||
|
border-radius: 25px;
|
||||||
|
padding: 25px;
|
||||||
|
width: fit-content;
|
||||||
|
color: lightgray;
|
||||||
|
}
|
||||||
|
|
||||||
|
h5 {
|
||||||
|
color: lightgrey;
|
||||||
|
}
|
||||||
|
|
||||||
|
.times {
|
||||||
|
float: left;
|
||||||
|
display: inline;
|
||||||
|
width: 49%;
|
||||||
|
padding-top: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.details {
|
||||||
|
float: left;
|
||||||
|
display: inline;
|
||||||
|
width: 33%;
|
||||||
|
padding-top: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
column-width: auto;
|
||||||
|
color: lightgray;
|
||||||
|
}
|
22
Lieb/Pages/Raids/RaidOverview.razor
Normal file
22
Lieb/Pages/Raids/RaidOverview.razor
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
@page "/raidoverview"
|
||||||
|
@using Lieb.Data
|
||||||
|
@inject RaidService RaidService
|
||||||
|
|
||||||
|
|
||||||
|
<h3>RaidOverview</h3>
|
||||||
|
|
||||||
|
@foreach (var raid in raids) {
|
||||||
|
<p>wupwup</p>
|
||||||
|
<RaidDetails Raid=@raid />
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private List<Models.GuildWars2.Raid.Raid> raids;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
raids = RaidService.GetRaids();
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,12 +8,26 @@ var builder = WebApplication.CreateBuilder(args);
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddRazorPages();
|
builder.Services.AddRazorPages();
|
||||||
|
|
||||||
builder.Services.AddDbContext<LiebContext>(options =>
|
//builder.Services.AddDbContext<LiebContext>(options =>
|
||||||
options.UseSqlServer(builder.Configuration.GetConnectionString("LiebContext")));
|
// options.UseSqlServer(builder.Configuration.GetConnectionString("LiebContext")), ServiceLifetime.Transient);
|
||||||
|
builder.Services.AddDbContextFactory<LiebContext>(opt =>
|
||||||
|
opt.UseSqlServer(builder.Configuration.GetConnectionString("LiebContext")), ServiceLifetime.Transient);
|
||||||
|
|
||||||
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
||||||
|
|
||||||
builder.Services.AddServerSideBlazor();
|
builder.Services.AddServerSideBlazor();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<RaidService>();
|
||||||
|
builder.Services.AddScoped<UserService>();
|
||||||
|
builder.Services.AddScoped<GuildWars2AccountService>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//builder.Services.AddTransient<RaidService>();
|
||||||
|
//builder.Services.AddTransient<UserService>();
|
||||||
|
//builder.Services.AddTransient<GuildWars2AccountService>();
|
||||||
|
|
||||||
builder.Services.AddAuthentication(opt =>
|
builder.Services.AddAuthentication(opt =>
|
||||||
{
|
{
|
||||||
opt.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
opt.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="counter">
|
<NavLink class="nav-link" href="raidoverview">
|
||||||
<span class="oi oi-plus" aria-hidden="true"></span> Counter
|
<span class="oi oi-plus" aria-hidden="true"></span> Raid Overview
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue