added RaidEdit page
This commit is contained in:
parent
bd47610371
commit
a3062165e1
9 changed files with 343 additions and 46 deletions
|
@ -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}
|
||||
};
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -1,35 +1,48 @@
|
|||
namespace Lieb.Models.GuildWars2.Raid
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Lieb.Models.GuildWars2.Raid
|
||||
{
|
||||
public enum RaidType
|
||||
{
|
||||
Planned = 1,
|
||||
RandomWithBoons = 2,
|
||||
RandomClasses = 3,
|
||||
RandomEliteSpecialization = 4,
|
||||
Planned = 0,
|
||||
RandomWithBoons = 1,
|
||||
RandomClasses = 2,
|
||||
RandomEliteSpecialization = 3,
|
||||
}
|
||||
|
||||
public class Raid
|
||||
{
|
||||
public int RaidId { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string Title { get; set; } = String.Empty;
|
||||
|
||||
[Required]
|
||||
public string Description { get; set; } = String.Empty;
|
||||
|
||||
public DateTime StartTime { get; set; }
|
||||
[Required]
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
|
||||
public double RaidDuration { get; set; }
|
||||
[Required]
|
||||
public DateTimeOffset StartTime { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTimeOffset EndTime { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Organizer { get; set; } = String.Empty;
|
||||
|
||||
[Required]
|
||||
public string Guild { get; set; } = String.Empty;
|
||||
|
||||
[Required]
|
||||
public string VoiceChat { get; set; } = String.Empty;
|
||||
|
||||
public int Frequency { get; set; }
|
||||
|
||||
[Required]
|
||||
public RaidType RaidType { get; set; }
|
||||
|
||||
public int Frequency { get; set; }
|
||||
|
||||
//role name, number of spots
|
||||
public ICollection<PlannedRaidRole> Roles { get; set; } = new HashSet<PlannedRaidRole>();
|
||||
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
<div >
|
||||
<div class="times">
|
||||
<h5>Date</h5>
|
||||
<p>@Raid.StartTime.ToLongDateString()</p>
|
||||
<p>@Raid.Date.ToLongDateString()</p>
|
||||
</div>
|
||||
<div class="times">
|
||||
<h5>Time</h5>
|
||||
<p>from: @Raid.StartTime.ToShortTimeString() to: @Raid.StartTime.AddHours(@Raid.RaidDuration).ToShortTimeString()</p>
|
||||
<p>from: @Raid.StartTime.LocalDateTime.ToShortTimeString() to: @Raid.EndTime.LocalDateTime.ToShortTimeString()</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -109,24 +109,42 @@
|
|||
}
|
||||
</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>
|
||||
}
|
||||
}
|
||||
}
|
||||
<div>
|
||||
<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>
|
||||
<td><h5>@role.Name: @role.Description (@usedSpots /@role.Spots)</h5></td>
|
||||
</tr>
|
||||
@foreach (var signUp in signUps)
|
||||
{
|
||||
if(signUp.SignUpType != SignUpType.SignedOff)
|
||||
{
|
||||
string signUpStatus = string.Empty;
|
||||
if (signUp.SignUpType != SignUpType.SignedUp) signUpStatus = $" - {signUp.SignUpType}";
|
||||
<tr>
|
||||
<td>@signUp.LiebUser.Name (@signUp.GuildWars2Account.AccountName) @signUpStatus</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
<AuthorizeView Policy="RaidLead">
|
||||
<div class="nav-item px-3">
|
||||
@{string navLink = $"raidedit/{@Raid.RaidId}";}
|
||||
<NavLink class="nav-link" href="@navLink">
|
||||
<span class="oi oi-plus" aria-hidden="true"></span> Edit
|
||||
</NavLink>
|
||||
</div>
|
||||
</AuthorizeView>
|
||||
</body>
|
||||
|
||||
@code {
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
background-color: rgb(38 38 38);
|
||||
border-radius: 25px;
|
||||
padding: 25px;
|
||||
width: fit-content;
|
||||
width: 700px;
|
||||
/*width: fit-content;*/
|
||||
color: lightgray;
|
||||
}
|
||||
|
||||
|
@ -21,7 +22,7 @@ h5 {
|
|||
.details {
|
||||
float: left;
|
||||
display: inline;
|
||||
width: 33%;
|
||||
width: 150px;
|
||||
padding-top: 15px;
|
||||
}
|
||||
|
||||
|
|
175
Lieb/Pages/Raids/RaidEdit.razor
Normal file
175
Lieb/Pages/Raids/RaidEdit.razor
Normal file
|
@ -0,0 +1,175 @@
|
|||
@page "/raidedit"
|
||||
@page "/raidedit/{raidId}"
|
||||
@using Lieb.Data
|
||||
@using Lieb.Models.GuildWars2.Raid
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@inject RaidService RaidService
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IJSRuntime JsRuntime
|
||||
|
||||
|
||||
<h3>CreateRaid</h3>
|
||||
|
||||
<AuthorizeView Policy="RaidLead" Context="authorizationContext">
|
||||
<EditForm Model="@_raid" OnValidSubmit="@HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
@{
|
||||
bool _isEdit = _raid.RaidId != 0;
|
||||
}
|
||||
<p>
|
||||
<label>
|
||||
Title:
|
||||
<InputText @bind-Value="_raid.Title" />
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
Description:
|
||||
<InputTextArea @bind-Value="_raid.Description" />
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
Raid Type:
|
||||
<InputSelect @bind-Value="_raid.RaidType" disabled="@_isEdit">
|
||||
<option value="@RaidType.Planned">Planned</option>
|
||||
<option value="@RaidType.RandomWithBoons">Random with boons covred</option>
|
||||
<option value="@RaidType.RandomClasses">Random classes</option>
|
||||
<option value="@RaidType.RandomEliteSpecialization">Random elite specializations</option>
|
||||
</InputSelect>
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label>
|
||||
Date:
|
||||
<InputDate @bind-Value="_raid.Date" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label>
|
||||
Start Time:
|
||||
<input type="time" @bind="@_raid.StartTime" />
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
End Time:
|
||||
<input type="time" @bind="@_raid.EndTime" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label>
|
||||
Organizer:
|
||||
<InputText @bind-Value="_raid.Organizer" />
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
Guild:
|
||||
<InputText @bind-Value="_raid.Guild" />
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
Voice chat:
|
||||
<InputText @bind-Value="_raid.VoiceChat" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
@if(_raid.RaidType == RaidType.Planned)
|
||||
{
|
||||
<p>
|
||||
<label>
|
||||
Roles:
|
||||
</label>
|
||||
<button type=button @onclick="() => AddRoleClicked()">Add role</button>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Spots</th>
|
||||
<th>Role name</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
@foreach( PlannedRaidRole role in _raid.Roles)
|
||||
{
|
||||
bool disableEdit = _raid.SignUps.Where(s => s.PlannedRaidRoleId == role.PlannedRaidRoleId).Any();
|
||||
<tr>
|
||||
<td><InputNumber @bind-Value="role.Spots" disabled="@disableEdit" /></td>
|
||||
<td><InputText @bind-Value="role.Name" disabled="@disableEdit" /></td>
|
||||
<td><InputText @bind-Value="role.Description" disabled="@disableEdit" /></td>
|
||||
@if(!disableEdit)
|
||||
{
|
||||
<td><button type=button @onclick="() => DeleteRoleClicked(role)">Delete</button></td>
|
||||
}
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
</p>
|
||||
}
|
||||
|
||||
<button type="submit">Submit</button>
|
||||
|
||||
</EditForm>
|
||||
<br/>
|
||||
<button type=button @onclick="() => DeleteRaidClicked()">Delete Raid</button>
|
||||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public string raidId { get; set; }
|
||||
|
||||
public Raid _raid;
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if(!string.IsNullOrEmpty(raidId) && int.TryParse(raidId, out int parsedId))
|
||||
{
|
||||
_raid = RaidService.GetRaid(parsedId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_raid = new Raid();
|
||||
}
|
||||
}
|
||||
|
||||
async Task AddRoleClicked()
|
||||
{
|
||||
_raid.Roles.Add(new PlannedRaidRole());
|
||||
}
|
||||
|
||||
|
||||
async Task DeleteRoleClicked(PlannedRaidRole role)
|
||||
{
|
||||
_raid.Roles.Remove(role);
|
||||
}
|
||||
|
||||
async Task DeleteRaidClicked()
|
||||
{
|
||||
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure?");
|
||||
if (confirmed)
|
||||
{
|
||||
await RaidService.DeleteRaid(_raid.RaidId);
|
||||
NavigationManager.NavigateTo("raidoverview");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleValidSubmit()
|
||||
{
|
||||
if(_raid.RaidType != RaidType.Planned && _raid.Roles.Count == 0)
|
||||
{
|
||||
_raid.Roles.Add(new PlannedRaidRole()
|
||||
{
|
||||
Spots = 10,
|
||||
Name = "Random",
|
||||
Description = _raid.RaidType.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
await RaidService.AddOrEditRaid(_raid);
|
||||
}
|
||||
}
|
|
@ -5,14 +5,25 @@
|
|||
|
||||
<h3>RaidOverview</h3>
|
||||
|
||||
|
||||
<AuthorizeView Policy="RaidLead">
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="raidedit">
|
||||
<span class="oi oi-plus" aria-hidden="true"></span> Add Raid
|
||||
</NavLink>
|
||||
</div>
|
||||
</AuthorizeView>
|
||||
|
||||
|
||||
@foreach (var raid in raids) {
|
||||
<p>wupwup</p>
|
||||
<br />
|
||||
<RaidDetails Raid=@raid />
|
||||
}
|
||||
|
||||
|
||||
|
||||
@code {
|
||||
@code
|
||||
{
|
||||
private List<Models.GuildWars2.Raid.Raid> raids;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
|
|
|
@ -8,10 +8,13 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
// Add services to the container.
|
||||
builder.Services.AddRazorPages();
|
||||
|
||||
//builder.Services.AddDbContext<LiebContext>(options =>
|
||||
// options.UseSqlServer(builder.Configuration.GetConnectionString("LiebContext")), ServiceLifetime.Transient);
|
||||
#if DEBUG
|
||||
builder.Services.AddDbContextFactory<LiebContext>(opt =>
|
||||
opt.UseSqlServer(builder.Configuration.GetConnectionString("LiebContext")).EnableSensitiveDataLogging(), ServiceLifetime.Transient);
|
||||
#else
|
||||
builder.Services.AddDbContextFactory<LiebContext>(opt =>
|
||||
opt.UseSqlServer(builder.Configuration.GetConnectionString("LiebContext")), ServiceLifetime.Transient);
|
||||
#endif
|
||||
|
||||
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
||||
|
||||
|
|
|
@ -23,13 +23,6 @@
|
|||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
<AuthorizeView>
|
||||
<p>You can only see this if you are loged in</p>
|
||||
</AuthorizeView>
|
||||
<AuthorizeView Policy="Admin">
|
||||
<p>You can only see this if you satisfy the "Admin" policy.</p>
|
||||
</AuthorizeView>
|
||||
|
||||
|
||||
<article class="content px-4">
|
||||
@Body
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue