Added minUsers and Polls
This commit is contained in:
parent
cb1dbfbf98
commit
1d999e89bf
8 changed files with 45 additions and 10 deletions
|
@ -97,7 +97,7 @@ namespace Lieb.Data
|
||||||
await context.SaveChangesAsync();
|
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();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
Poll? poll = context.Polls
|
Poll? poll = context.Polls
|
||||||
|
@ -106,8 +106,10 @@ namespace Lieb.Data
|
||||||
|
|
||||||
if (poll == null) return;
|
if (poll == null) return;
|
||||||
|
|
||||||
PollAnswer answer = poll.Answers.First(a => a.UserId == userId);
|
PollAnswer pollAnswer = poll.Answers.First(a => a.UserId == userId);
|
||||||
answer.PollOptionId = pollOptionId;
|
pollAnswer.Answer = answer;
|
||||||
|
pollAnswer.PollOptionId = pollOptionId;
|
||||||
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddUser(int pollId, ulong userId)
|
public async Task AddUser(int pollId, ulong userId)
|
||||||
|
|
|
@ -469,7 +469,7 @@ namespace Lieb.Data
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raid.SignUps.Count < raid.MinUsers
|
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.";
|
errorMessage = $"The raid was canceled because of not enough sign ups.";
|
||||||
return false;
|
return false;
|
||||||
|
@ -722,10 +722,9 @@ namespace Lieb.Data
|
||||||
Poll poll = _pollService.GetPoll(raid.MinUserPollId.Value);
|
Poll poll = _pollService.GetPoll(raid.MinUserPollId.Value);
|
||||||
|
|
||||||
if (poll.Answers.Count == 0) continue;
|
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.Answer == Constants.Polls.NO).Any())
|
||||||
if(poll.Answers.Where(a => a.PollOptionId == noOptionId).Any())
|
|
||||||
{
|
{
|
||||||
await _discordService.SendMessageToRaidUsers("The raid is canceled.", raid);
|
await _discordService.SendMessageToRaidUsers("The raid is canceled.", raid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,16 @@ namespace Lieb.Data
|
||||||
|
|
||||||
public async ValueTask<DateTimeOffset> GetLocalDateTime(DateTimeOffset dateTime)
|
public async ValueTask<DateTimeOffset> GetLocalDateTime(DateTimeOffset dateTime)
|
||||||
{
|
{
|
||||||
int offsetInMinutes = await _jsRuntime.InvokeAsync<int>("GetTimezoneValue", dateTime);
|
if(dateTime == DateTimeOffset.MinValue) dateTime = DateTimeOffset.UtcNow;
|
||||||
TimeSpan userOffset = TimeSpan.FromMinutes(-offsetInMinutes);
|
int offsetInMinutes = await _jsRuntime.InvokeAsync<int>("GetTimezoneValue", dateTime);
|
||||||
|
TimeSpan userOffset = TimeSpan.FromMinutes(-offsetInMinutes);
|
||||||
|
|
||||||
return dateTime.ToOffset(userOffset);
|
return dateTime.ToOffset(userOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<DateTimeOffset> GetUTCDateTime(DateTimeOffset dateTime)
|
public async ValueTask<DateTimeOffset> GetUTCDateTime(DateTimeOffset dateTime)
|
||||||
{
|
{
|
||||||
|
if(dateTime == DateTimeOffset.MinValue) return DateTimeOffset.UtcNow;
|
||||||
int offsetInMinutes = await _jsRuntime.InvokeAsync<int>("GetTimezoneValue", dateTime);
|
int offsetInMinutes = await _jsRuntime.InvokeAsync<int>("GetTimezoneValue", dateTime);
|
||||||
TimeSpan userOffset = TimeSpan.FromMinutes(-offsetInMinutes);
|
TimeSpan userOffset = TimeSpan.FromMinutes(-offsetInMinutes);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
namespace Lieb.Migrations
|
namespace Lieb.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(LiebContext))]
|
[DbContext(typeof(LiebContext))]
|
||||||
[Migration("20230103181756_PollsAndMinUsers")]
|
[Migration("20230114125113_PollsAndMinUsers")]
|
||||||
partial class PollsAndMinUsers
|
partial class PollsAndMinUsers
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
@ -503,6 +503,12 @@ namespace Lieb.Migrations
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<bool>("AllowCustomAnswer")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("AnswerType")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Question")
|
b.Property<string>("Question")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
@ -521,6 +527,10 @@ namespace Lieb.Migrations
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Answer")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<int?>("PollId")
|
b.Property<int?>("PollId")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
|
@ -50,6 +50,8 @@ namespace Lieb.Migrations
|
||||||
PollId = table.Column<int>(type: "INTEGER", nullable: false)
|
PollId = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
.Annotation("Sqlite:Autoincrement", true),
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
Question = table.Column<string>(type: "TEXT", nullable: false),
|
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)
|
RaidId = table.Column<int>(type: "INTEGER", nullable: true)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
|
@ -64,6 +66,7 @@ namespace Lieb.Migrations
|
||||||
PollAnswerId = table.Column<int>(type: "INTEGER", nullable: false)
|
PollAnswerId = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
.Annotation("Sqlite:Autoincrement", true),
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
PollOptionId = table.Column<int>(type: "INTEGER", nullable: 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),
|
UserId = table.Column<ulong>(type: "INTEGER", nullable: false),
|
||||||
PollId = table.Column<int>(type: "INTEGER", nullable: true)
|
PollId = table.Column<int>(type: "INTEGER", nullable: true)
|
||||||
},
|
},
|
|
@ -501,6 +501,12 @@ namespace Lieb.Migrations
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<bool>("AllowCustomAnswer")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("AnswerType")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<string>("Question")
|
b.Property<string>("Question")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
@ -519,6 +525,10 @@ namespace Lieb.Migrations
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Answer")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<int?>("PollId")
|
b.Property<int?>("PollId")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
namespace Lieb.Models.Poll
|
namespace Lieb.Models.Poll
|
||||||
{
|
{
|
||||||
|
public enum AnswerType
|
||||||
|
{
|
||||||
|
Buttons = 1,
|
||||||
|
Dropdown = 2
|
||||||
|
}
|
||||||
public class Poll
|
public class Poll
|
||||||
{
|
{
|
||||||
public int PollId { get; set; }
|
public int PollId { get; set; }
|
||||||
public string Question { get; set; }
|
public string Question { get; set; }
|
||||||
public ICollection<PollOption> Options { get; set; } = new List<PollOption>();
|
public ICollection<PollOption> Options { get; set; } = new List<PollOption>();
|
||||||
public ICollection<PollAnswer> Answers { get; set; } = new List<PollAnswer>();
|
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; }
|
public int? RaidId { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
public int? PollOptionId { get; set; }
|
public int? PollOptionId { get; set; }
|
||||||
|
|
||||||
|
public string Answer { get; set; } = string.Empty;
|
||||||
|
|
||||||
public ulong UserId { get; set; }
|
public ulong UserId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue