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() { 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(); } } } }