added copy template function

This commit is contained in:
Sarah Faey 2022-12-08 22:01:54 +01:00
parent 1ac6cc64a6
commit 83f9b2d0b8
4 changed files with 41 additions and 4 deletions

View file

@ -18,7 +18,7 @@ namespace Lieb.Models.GuildWars2.Raid
public Raid() { }
public Raid(RaidTemplate template) : base(template, template.TimeZone)
public Raid(RaidTemplate template) : base(template, template.TimeZone, true)
{
TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(template.TimeZone);
StartTimeUTC = TimeZoneInfo.ConvertTimeToUtc(template.StartTime, timeZone);

View file

@ -61,7 +61,7 @@ namespace Lieb.Models.GuildWars2.Raid
public RaidBase() { }
public RaidBase(RaidBase template, string timeZoneString)
public RaidBase(RaidBase template, string timeZoneString, bool convertTimeForRaid)
{
this.Title = template.Title;
this.Description = template.Description;
@ -88,11 +88,17 @@ namespace Lieb.Models.GuildWars2.Raid
TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneString);
foreach (RaidReminder reminder in template.Reminders)
{
DateTimeOffset reminderTime = reminder.ReminderTimeUTC;
if(convertTimeForRaid)
{
reminderTime = TimeZoneInfo.ConvertTimeToUtc(reminder.ReminderTimeUTC.DateTime, timeZone);
}
this.Reminders.Add(new RaidReminder()
{
DiscordServerId = reminder.DiscordServerId,
DiscordChannelId = reminder.DiscordChannelId,
ReminderTimeUTC = TimeZoneInfo.ConvertTimeToUtc(reminder.ReminderTimeUTC.DateTime, timeZone),
ReminderTimeUTC = reminderTime,
Message = reminder.Message,
Sent = false,
Type = reminder.Type,

View file

@ -19,5 +19,17 @@ namespace Lieb.Models.GuildWars2.Raid
public int Interval { get; set; }
public int CreateDaysBefore { get; set; }
public RaidTemplate() { }
public RaidTemplate(RaidTemplate template) : base(template, template.TimeZone, false)
{
StartTime = template.StartTime;
EndTime = template.EndTime;
FreeForAllTime = template.FreeForAllTime;
TimeZone = template.TimeZone;
Interval = template.Interval;
CreateDaysBefore = template.CreateDaysBefore;
}
}
}

View file

@ -1,5 +1,6 @@
@page "/raidtemplateedit"
@page "/raidtemplateedit/{raidId}"
@page "/raidtemplateedit/{raidId}/{editType}"
@using Lieb.Data
@using Lieb.Models
@using Lieb.Models.GuildWars2.Raid
@ -39,7 +40,7 @@
<p>
<label>
Raid Type:
<InputSelect @bind-Value="_template.RaidType" disabled="@_isEdit">
<InputSelect @bind-Value="_template.RaidType" disabled="@(!_editType && _isEdit)">
<option value="@RaidType.Planned">Planned</option>
<option value="@RaidType.RandomWithBoons">Random with boons covered</option>
<option value="@RaidType.RandomClasses">Random classes</option>
@ -198,15 +199,20 @@
</EditForm>
<br/>
<button type="delete" @onclick="() => DeleteRaidClicked()">Delete Template</button>
<button type="copy" @onclick="() => CopyTemplate()">Copy Template</button>
</AuthorizeView>
@code {
[Parameter]
public string raidId { get; set; }
[Parameter]
public string editType { get; set; }
public RaidTemplate _template;
private LiebUser _user;
private bool _editType = false;
private string _errorMessage = string.Empty;
@ -241,6 +247,11 @@
NavigationManager.NavigateTo("");
}
if(!string.IsNullOrEmpty(editType) && bool.TryParse(editType, out bool allowEdit))
{
_editType = allowEdit;
}
if(!string.IsNullOrEmpty(raidId) && int.TryParse(raidId, out int parsedId))
{
_template = RaidTemplateService.GetTemplate(parsedId);
@ -372,4 +383,12 @@
await RaidTemplateService.AddOrEditTemplate(_template, _rolesToDelete, _remindersToDelete, _messagesToDelete, _user.Id);
NavigationManager.NavigateTo("raidtemplateoverview");
}
private async Task CopyTemplate()
{
RaidTemplate newTemplate = new RaidTemplate(_template);
await RaidTemplateService.AddOrEditTemplate(newTemplate, new List<RaidRole>(), new List<RaidReminder>(), new List<DiscordRaidMessage>(), _user.Id);
NavigationManager.NavigateTo($"/raidtemplateedit/{newTemplate.RaidTemplateId}/true", true);
}
}