From 05e6b9bc86ea1e61dbd56f22498a700a01923cb7 Mon Sep 17 00:00:00 2001 From: eee4 <41441600+eee4@users.noreply.github.com> Date: Mon, 21 Jul 2025 11:16:46 +0200 Subject: [PATCH] feat: ensure the number of draws is present in the db --- Controllers/Seed.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Controllers/Seed.cs b/Controllers/Seed.cs index 76e6250..e9fc2f8 100644 --- a/Controllers/Seed.cs +++ b/Controllers/Seed.cs @@ -21,6 +21,7 @@ namespace QuotifyBE.Controllers } public async Task SeedAsync() { + // Create a user account if no exist var AccountNum = await _db.Users.CountAsync(); if (AccountNum == 0) { @@ -34,8 +35,24 @@ namespace QuotifyBE.Controllers }; _db.Users.Add(Admin); await _db.SaveChangesAsync(); + Console.WriteLine("[QuotifyBE] Administrator user account added!\nDefault credentials are: admin@mail.com, password: admin"); } - + + // Create sitewide statistic - number of draws + Statistic? numOfDraws = await _db.Statistics + .FirstOrDefaultAsync(s => s.Label == "number_of_draws"); + if (numOfDraws == null) + { + Statistic newRow = new Statistic + { + Label = "number_of_draws", + IValue = 0 + }; + _db.Statistics.Add(newRow); + await _db.SaveChangesAsync(); + Console.WriteLine("[QuotifyBE] Sitewide statistic for number of draws added!"); + } + } } }