mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 19:00:07 +01:00
feat: ensure the number of draws is present in the db
This commit is contained in:
@@ -21,6 +21,7 @@ namespace QuotifyBE.Controllers
|
|||||||
}
|
}
|
||||||
public async Task SeedAsync()
|
public async Task SeedAsync()
|
||||||
{
|
{
|
||||||
|
// Create a user account if no exist
|
||||||
var AccountNum = await _db.Users.CountAsync();
|
var AccountNum = await _db.Users.CountAsync();
|
||||||
if (AccountNum == 0)
|
if (AccountNum == 0)
|
||||||
{
|
{
|
||||||
@@ -34,8 +35,24 @@ namespace QuotifyBE.Controllers
|
|||||||
};
|
};
|
||||||
_db.Users.Add(Admin);
|
_db.Users.Add(Admin);
|
||||||
await _db.SaveChangesAsync();
|
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!");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user