diff --git a/Lieb/Data/PollService.cs b/Lieb/Data/PollService.cs index 1f5d0ed..f561eb7 100644 --- a/Lieb/Data/PollService.cs +++ b/Lieb/Data/PollService.cs @@ -97,7 +97,7 @@ namespace Lieb.Data await context.SaveChangesAsync(); } - public async Task UpdateAnswer(int pollId, int pollOptionId, ulong userId) + public async Task UpdateAnswer(int pollId, int pollOptionId, string answer, ulong userId) { using var context = _contextFactory.CreateDbContext(); Poll? poll = context.Polls @@ -106,8 +106,10 @@ namespace Lieb.Data if (poll == null) return; - PollAnswer answer = poll.Answers.First(a => a.UserId == userId); - answer.PollOptionId = pollOptionId; + PollAnswer pollAnswer = poll.Answers.First(a => a.UserId == userId); + pollAnswer.Answer = answer; + pollAnswer.PollOptionId = pollOptionId; + await context.SaveChangesAsync(); } public async Task AddUser(int pollId, ulong userId) diff --git a/Lieb/Data/RaidService.cs b/Lieb/Data/RaidService.cs index c6e63b0..536c6f7 100644 --- a/Lieb/Data/RaidService.cs +++ b/Lieb/Data/RaidService.cs @@ -469,7 +469,7 @@ namespace Lieb.Data } if (raid.SignUps.Count < raid.MinUsers - && raid.MinUserDeadLineUTC.UtcDateTime > DateTimeOffset.UtcNow) + && raid.MinUserDeadLineUTC < DateTimeOffset.UtcNow) { errorMessage = $"The raid was canceled because of not enough sign ups."; return false; @@ -722,10 +722,9 @@ namespace Lieb.Data Poll poll = _pollService.GetPoll(raid.MinUserPollId.Value); if (poll.Answers.Count == 0) continue; - if (poll.Answers.Where(a => a.PollOptionId == null).Any()) continue; + if (poll.Answers.Where(a => string.IsNullOrEmpty(a.Answer)).Any()) continue; - int noOptionId = poll.Options.First(o => o.Name == Constants.Polls.NO).PollOptionId; - if(poll.Answers.Where(a => a.PollOptionId == noOptionId).Any()) + if(poll.Answers.Where(a => a.Answer == Constants.Polls.NO).Any()) { await _discordService.SendMessageToRaidUsers("The raid is canceled.", raid); } diff --git a/Lieb/Data/TimeZoneService.cs b/Lieb/Data/TimeZoneService.cs index 1344b84..3cbebb9 100644 --- a/Lieb/Data/TimeZoneService.cs +++ b/Lieb/Data/TimeZoneService.cs @@ -13,14 +13,16 @@ namespace Lieb.Data public async ValueTask GetLocalDateTime(DateTimeOffset dateTime) { - int offsetInMinutes = await _jsRuntime.InvokeAsync("GetTimezoneValue", dateTime); - TimeSpan userOffset = TimeSpan.FromMinutes(-offsetInMinutes); + if(dateTime == DateTimeOffset.MinValue) dateTime = DateTimeOffset.UtcNow; + int offsetInMinutes = await _jsRuntime.InvokeAsync("GetTimezoneValue", dateTime); + TimeSpan userOffset = TimeSpan.FromMinutes(-offsetInMinutes); return dateTime.ToOffset(userOffset); } public async ValueTask GetUTCDateTime(DateTimeOffset dateTime) { + if(dateTime == DateTimeOffset.MinValue) return DateTimeOffset.UtcNow; int offsetInMinutes = await _jsRuntime.InvokeAsync("GetTimezoneValue", dateTime); TimeSpan userOffset = TimeSpan.FromMinutes(-offsetInMinutes); diff --git a/Lieb/Migrations/20230103181756_PollsAndMinUsers.Designer.cs b/Lieb/Migrations/20230114125113_PollsAndMinUsers.Designer.cs similarity index 98% rename from Lieb/Migrations/20230103181756_PollsAndMinUsers.Designer.cs rename to Lieb/Migrations/20230114125113_PollsAndMinUsers.Designer.cs index 91bf1ee..fed05e2 100644 --- a/Lieb/Migrations/20230103181756_PollsAndMinUsers.Designer.cs +++ b/Lieb/Migrations/20230114125113_PollsAndMinUsers.Designer.cs @@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Lieb.Migrations { [DbContext(typeof(LiebContext))] - [Migration("20230103181756_PollsAndMinUsers")] + [Migration("20230114125113_PollsAndMinUsers")] partial class PollsAndMinUsers { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -503,6 +503,12 @@ namespace Lieb.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("AllowCustomAnswer") + .HasColumnType("INTEGER"); + + b.Property("AnswerType") + .HasColumnType("INTEGER"); + b.Property("Question") .IsRequired() .HasColumnType("TEXT"); @@ -521,6 +527,10 @@ namespace Lieb.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("Answer") + .IsRequired() + .HasColumnType("TEXT"); + b.Property("PollId") .HasColumnType("INTEGER"); diff --git a/Lieb/Migrations/20230103181756_PollsAndMinUsers.cs b/Lieb/Migrations/20230114125113_PollsAndMinUsers.cs similarity index 95% rename from Lieb/Migrations/20230103181756_PollsAndMinUsers.cs rename to Lieb/Migrations/20230114125113_PollsAndMinUsers.cs index 1ebbc16..d4d2924 100644 --- a/Lieb/Migrations/20230103181756_PollsAndMinUsers.cs +++ b/Lieb/Migrations/20230114125113_PollsAndMinUsers.cs @@ -50,6 +50,8 @@ namespace Lieb.Migrations PollId = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), Question = table.Column(type: "TEXT", nullable: false), + AnswerType = table.Column(type: "INTEGER", nullable: false), + AllowCustomAnswer = table.Column(type: "INTEGER", nullable: false), RaidId = table.Column(type: "INTEGER", nullable: true) }, constraints: table => @@ -64,6 +66,7 @@ namespace Lieb.Migrations PollAnswerId = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), PollOptionId = table.Column(type: "INTEGER", nullable: true), + Answer = table.Column(type: "TEXT", nullable: false), UserId = table.Column(type: "INTEGER", nullable: false), PollId = table.Column(type: "INTEGER", nullable: true) }, diff --git a/Lieb/Migrations/LiebContextModelSnapshot.cs b/Lieb/Migrations/LiebContextModelSnapshot.cs index 0304baa..1288a53 100644 --- a/Lieb/Migrations/LiebContextModelSnapshot.cs +++ b/Lieb/Migrations/LiebContextModelSnapshot.cs @@ -501,6 +501,12 @@ namespace Lieb.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("AllowCustomAnswer") + .HasColumnType("INTEGER"); + + b.Property("AnswerType") + .HasColumnType("INTEGER"); + b.Property("Question") .IsRequired() .HasColumnType("TEXT"); @@ -519,6 +525,10 @@ namespace Lieb.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("Answer") + .IsRequired() + .HasColumnType("TEXT"); + b.Property("PollId") .HasColumnType("INTEGER"); diff --git a/Lieb/Models/Poll/Poll.cs b/Lieb/Models/Poll/Poll.cs index c11eb4d..ae02e31 100644 --- a/Lieb/Models/Poll/Poll.cs +++ b/Lieb/Models/Poll/Poll.cs @@ -1,11 +1,18 @@ namespace Lieb.Models.Poll { + public enum AnswerType + { + Buttons = 1, + Dropdown = 2 + } public class Poll { public int PollId { get; set; } public string Question { get; set; } public ICollection Options { get; set; } = new List(); public ICollection Answers { get; set; } = new List(); + public AnswerType AnswerType {get; set;} + public bool AllowCustomAnswer {get; set;} = false; public int? RaidId { get; set; } } diff --git a/Lieb/Models/Poll/PollAnswer.cs b/Lieb/Models/Poll/PollAnswer.cs index 3f8be58..b7905e9 100644 --- a/Lieb/Models/Poll/PollAnswer.cs +++ b/Lieb/Models/Poll/PollAnswer.cs @@ -6,6 +6,8 @@ public int? PollOptionId { get; set; } + public string Answer { get; set; } = string.Empty; + public ulong UserId { get; set; } } }