Added TimeZone Functionality
This commit is contained in:
parent
c298f4d20e
commit
c215ed058f
9 changed files with 129 additions and 48 deletions
|
@ -40,6 +40,7 @@ namespace Lieb.Data
|
|||
GuildWars2Account bloodseeker = new GuildWars2Account() { AccountName = "Bloodseeker.2043" };
|
||||
var users = new LiebUser[]
|
||||
{
|
||||
//new LiebUser{DiscordUserId=0, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
||||
new LiebUser{DiscordUserId=194863625477816321, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
||||
#if DEBUG
|
||||
new LiebUser{DiscordUserId=1, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}},
|
||||
|
@ -96,9 +97,9 @@ namespace Lieb.Data
|
|||
Guild = "LIEB",
|
||||
Organizer = "Sarah",
|
||||
RaidType = RaidType.RandomWithBoons,
|
||||
Date = DateTime.Now.Date,
|
||||
StartTime = DateTime.Now,
|
||||
EndTime = DateTime.Now.AddHours(2),
|
||||
StartTimeUTC = DateTime.UtcNow,
|
||||
EndTimeUTC = DateTime.UtcNow.AddHours(2),
|
||||
FreeForAllTimeUTC = DateTime.UtcNow.AddHours(-2),
|
||||
VoiceChat = "ts.lieb.games",
|
||||
Roles = new [] { ele, scourge}
|
||||
};
|
||||
|
@ -115,7 +116,7 @@ namespace Lieb.Data
|
|||
context.RaidSignUps.AddRange(signUps);
|
||||
context.SaveChanges();
|
||||
|
||||
GuildWars2Build healTempest = new GuildWars2Build() { BuildName = "HealTempest", Class = GuildWars2Class.Elementalist, EliteSpecialization = EliteSpecialization.Tempest, Heal = 5, Might = 10 };
|
||||
GuildWars2Build healTempest = new GuildWars2Build() { BuildName = "HealTempest", Class = GuildWars2Class.Elementalist, EliteSpecialization = EliteSpecialization.Tempest, Heal = 5, Might = 5 };
|
||||
GuildWars2Build condiScourge = new GuildWars2Build() { BuildName = "CondiScourge", Class = GuildWars2Class.Necromancer, EliteSpecialization = EliteSpecialization.Scourge };
|
||||
GuildWars2Build quickBrand = new GuildWars2Build() { BuildName = "QuickBrand", Class = GuildWars2Class.Guard, EliteSpecialization = EliteSpecialization.Firebrand, Heal = 5, Quickness = 5 };
|
||||
GuildWars2Build alacregate = new GuildWars2Build() { BuildName = "Alacregate", Class = GuildWars2Class.Revenant, EliteSpecialization = EliteSpecialization.Renegade, Alacrity = 5 };
|
||||
|
|
|
@ -65,14 +65,16 @@ namespace Lieb.Data
|
|||
.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.StartTimeUTC = raid.StartTimeUTC;
|
||||
raidToChange.EndTimeUTC = raid.EndTimeUTC;
|
||||
raidToChange.TimeZone = raid.TimeZone;
|
||||
raidToChange.Organizer = raid.Organizer;
|
||||
raidToChange.Guild = raid.Guild;
|
||||
raidToChange.VoiceChat = raid.VoiceChat;
|
||||
raidToChange.RaidType = raid.RaidType;
|
||||
raidToChange.Frequency = raid.Frequency;
|
||||
raidToChange.RequiredRole = raid.RequiredRole;
|
||||
raidToChange.FreeForAllTimeUTC = raid.FreeForAllTimeUTC;
|
||||
raidToChange.DiscordMessageId = raid.DiscordMessageId;
|
||||
raidToChange.DiscordChannelId = raid.DiscordChannelId;
|
||||
raidToChange.DiscordGuildId = raid.DiscordGuildId;
|
||||
|
@ -315,13 +317,6 @@ namespace Lieb.Data
|
|||
return false;
|
||||
}
|
||||
|
||||
DateTime freeForAllTime = raid.FreeForAllDate.Date + raid.FreeForAllTime.TimeOfDay;
|
||||
if (!string.IsNullOrEmpty(raid.RequiredRole) && !user.RoleAssignments.Where(a => a.LiebRole.RoleName == raid.RequiredRole).Any() || freeForAllTime > DateTimeOffset.Now)
|
||||
{
|
||||
errorMessage = $"The raid is still locked for {raid.RequiredRole}.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (user.GuildWars2Accounts.Count == 0)
|
||||
{
|
||||
errorMessage = "No Guild Wars 2 account found.";
|
||||
|
@ -334,6 +329,12 @@ namespace Lieb.Data
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(raid.RequiredRole) && !user.RoleAssignments.Where(a => a.LiebRole.RoleName == raid.RequiredRole).Any() || raid.FreeForAllTimeUTC.UtcDateTime > DateTimeOffset.UtcNow)
|
||||
{
|
||||
errorMessage = $"The raid is still locked for {raid.RequiredRole}.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
44
Lieb/Data/TimeZoneService.cs
Normal file
44
Lieb/Data/TimeZoneService.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Lieb.Data
|
||||
{
|
||||
public class TimeZoneService
|
||||
{
|
||||
private readonly IJSRuntime _jsRuntime;
|
||||
|
||||
private TimeSpan? _userOffset;
|
||||
private int _offsetInMinutes;
|
||||
|
||||
public TimeZoneService(IJSRuntime jsRuntime)
|
||||
{
|
||||
_jsRuntime = jsRuntime;
|
||||
}
|
||||
|
||||
public async ValueTask<DateTimeOffset> GetLocalDateTime(DateTimeOffset dateTime)
|
||||
{
|
||||
if (_userOffset == null)
|
||||
{
|
||||
_offsetInMinutes = await _jsRuntime.InvokeAsync<int>("GetTimezoneValue");
|
||||
_userOffset = TimeSpan.FromMinutes(-_offsetInMinutes);
|
||||
}
|
||||
|
||||
return dateTime.ToOffset(_userOffset.Value);
|
||||
}
|
||||
|
||||
public async ValueTask<DateTimeOffset> GetUTCDateTime(DateTimeOffset dateTime)
|
||||
{
|
||||
if (_userOffset == null)
|
||||
{
|
||||
_offsetInMinutes = await _jsRuntime.InvokeAsync<int>("GetTimezoneValue");
|
||||
_userOffset = TimeSpan.FromMinutes(-_offsetInMinutes);
|
||||
}
|
||||
|
||||
return new DateTimeOffset(dateTime.DateTime.AddMinutes(_offsetInMinutes), new TimeSpan(0));
|
||||
}
|
||||
|
||||
public async ValueTask<string> GetUserTimeZone()
|
||||
{
|
||||
return await _jsRuntime.InvokeAsync<string>("GetTimezone");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue