diff --git a/Controllers/Seed.cs b/Controllers/Seed.cs index e9fc2f8..46dff14 100644 --- a/Controllers/Seed.cs +++ b/Controllers/Seed.cs @@ -1,58 +1,60 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Authorization; -using QuotifyBE.Data; -using QuotifyBE.DTOs; -using QuotifyBE.Entities; -using QuotifyBE.Mapping; -using System.Security.Claims; -using Microsoft.EntityFrameworkCore; - -namespace QuotifyBE.Controllers -{ - public class Seed : Controller - { - private readonly ApplicationDbContext _db; - private readonly GeneralUseHelpers guhf; - - public Seed(ApplicationDbContext db, GeneralUseHelpers GUHF) - { - _db = db; - guhf = GUHF; - } - public async Task SeedAsync() - { - // Create a user account if no exist - var AccountNum = await _db.Users.CountAsync(); - if (AccountNum == 0) - { - var Admin = new User - { - Name="admin", - Email = "admin@mail.com", - // hashed twice, once by frontend, and second time by backend - PasswordHash = guhf.HashWithSHA512(guhf.HashWithSHA512("admin")), - Role = 0 // role 0 - greatest power, admin, role 0 > role 1 - }; - _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!"); - } - - } - } -} +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using QuotifyBE.Data; +using QuotifyBE.DTOs; +using QuotifyBE.Entities; +using QuotifyBE.Mapping; +using System.Security.Claims; +using Microsoft.EntityFrameworkCore; + +namespace QuotifyBE.Controllers +{ + public class Seed : Controller + { + private readonly ApplicationDbContext _db; + private readonly GeneralUseHelpers guhf; + + public Seed(ApplicationDbContext db, GeneralUseHelpers GUHF) + { + _db = db; + guhf = GUHF; + } + public async Task SeedAsync() + { + Console.WriteLine($"You're running QuotifyBE, commit {ThisAssembly.Git.Commit} of branch {ThisAssembly.Git.Branch} ({ThisAssembly.Git.CommitDate})\n"); + + // Create a user account if no exist + var AccountNum = await _db.Users.CountAsync(); + if (AccountNum == 0) + { + var Admin = new User + { + Name="admin", + Email = "admin@mail.com", + // hashed twice, once by frontend, and second time by backend + PasswordHash = guhf.HashWithSHA512(guhf.HashWithSHA512("admin")), + Role = 0 // role 0 - greatest power, admin, role 0 > role 1 + }; + _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!"); + } + + } + } +} diff --git a/Entities/Image.cs b/Entities/Image.cs index 206b648..7f60b7c 100644 --- a/Entities/Image.cs +++ b/Entities/Image.cs @@ -1,4 +1,4 @@ -namespace QuotifyBE.Entities +namespace QuotifyBE.Entities { public class Image { diff --git a/QuotifyBE.csproj b/QuotifyBE.csproj index b9e7634..4d09be2 100644 --- a/QuotifyBE.csproj +++ b/QuotifyBE.csproj @@ -7,12 +7,16 @@ b302b0ab-745f-4b53-b32a-12fbbc3e622d Linux . - true - $(NoWarn);1591 + true + $(NoWarn);1591 + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +