Added minUsers and Polls

This commit is contained in:
Sarah Faey 2023-01-14 14:03:15 +01:00
parent cb1dbfbf98
commit 1d999e89bf
8 changed files with 45 additions and 10 deletions

View file

@ -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)

View file

@ -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);
}

View file

@ -13,6 +13,7 @@ namespace Lieb.Data
public async ValueTask<DateTimeOffset> GetLocalDateTime(DateTimeOffset dateTime)
{
if(dateTime == DateTimeOffset.MinValue) dateTime = DateTimeOffset.UtcNow;
int offsetInMinutes = await _jsRuntime.InvokeAsync<int>("GetTimezoneValue", dateTime);
TimeSpan userOffset = TimeSpan.FromMinutes(-offsetInMinutes);
@ -21,6 +22,7 @@ namespace Lieb.Data
public async ValueTask<DateTimeOffset> GetUTCDateTime(DateTimeOffset dateTime)
{
if(dateTime == DateTimeOffset.MinValue) return DateTimeOffset.UtcNow;
int offsetInMinutes = await _jsRuntime.InvokeAsync<int>("GetTimezoneValue", dateTime);
TimeSpan userOffset = TimeSpan.FromMinutes(-offsetInMinutes);

View file

@ -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<bool>("AllowCustomAnswer")
.HasColumnType("INTEGER");
b.Property<int>("AnswerType")
.HasColumnType("INTEGER");
b.Property<string>("Question")
.IsRequired()
.HasColumnType("TEXT");
@ -521,6 +527,10 @@ namespace Lieb.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Answer")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("PollId")
.HasColumnType("INTEGER");

View file

@ -50,6 +50,8 @@ namespace Lieb.Migrations
PollId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Question = table.Column<string>(type: "TEXT", nullable: false),
AnswerType = table.Column<int>(type: "INTEGER", nullable: false),
AllowCustomAnswer = table.Column<bool>(type: "INTEGER", nullable: false),
RaidId = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
@ -64,6 +66,7 @@ namespace Lieb.Migrations
PollAnswerId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
PollOptionId = table.Column<int>(type: "INTEGER", nullable: true),
Answer = table.Column<string>(type: "TEXT", nullable: false),
UserId = table.Column<ulong>(type: "INTEGER", nullable: false),
PollId = table.Column<int>(type: "INTEGER", nullable: true)
},

View file

@ -501,6 +501,12 @@ namespace Lieb.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("AllowCustomAnswer")
.HasColumnType("INTEGER");
b.Property<int>("AnswerType")
.HasColumnType("INTEGER");
b.Property<string>("Question")
.IsRequired()
.HasColumnType("TEXT");
@ -519,6 +525,10 @@ namespace Lieb.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Answer")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("PollId")
.HasColumnType("INTEGER");

View file

@ -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<PollOption> Options { get; set; } = new List<PollOption>();
public ICollection<PollAnswer> Answers { get; set; } = new List<PollAnswer>();
public AnswerType AnswerType {get; set;}
public bool AllowCustomAnswer {get; set;} = false;
public int? RaidId { get; set; }
}

View file

@ -6,6 +6,8 @@
public int? PollOptionId { get; set; }
public string Answer { get; set; } = string.Empty;
public ulong UserId { get; set; }
}
}