Update repository, seed and service layers

This commit is contained in:
Aaron Po
2026-01-15 14:48:18 -05:00
parent b8cd855916
commit c5aaf8cd05
15 changed files with 322 additions and 412 deletions

View File

@@ -12,7 +12,6 @@ namespace DBSeed
internal class UserSeeder : ISeeder
{
private UserAccountRepository _userAccountRepository = new UserAccountRepository();
private static readonly IReadOnlyList<(
@@ -133,15 +132,17 @@ namespace DBSeed
foreach (var (firstName, lastName) in SeedNames)
{
// create the user in the database
var ua = new UserAccount
var userAccountId = Guid.NewGuid();
await AddUserAccountAsync(connection, new UserAccount
{
UserAccountId = userAccountId,
FirstName = firstName,
LastName = lastName,
Email = $"{firstName}.{lastName}@thebiergarten.app",
Username = $"{firstName[0]}.{lastName}",
DateOfBirth = GenerateDateOfBirth(rng)
};
});
createdUsers++;
// add user credentials
if (!await HasUserCredentialAsync(connection, userAccountId))
@@ -167,6 +168,21 @@ namespace DBSeed
Console.WriteLine($"Added {createdVerifications} user verifications.");
}
private static async Task AddUserAccountAsync(SqlConnection connection, UserAccount ua)
{
await using var command = new SqlCommand("usp_CreateUserAccount", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@UserAccountId", SqlDbType.UniqueIdentifier).Value = ua.UserAccountId;
command.Parameters.Add("@Username", SqlDbType.NVarChar, 100).Value = ua.Username;
command.Parameters.Add("@FirstName", SqlDbType.NVarChar, 100).Value = ua.FirstName;
command.Parameters.Add("@LastName", SqlDbType.NVarChar, 100).Value = ua.LastName;
command.Parameters.Add("@Email", SqlDbType.NVarChar, 256).Value = ua.Email;
command.Parameters.Add("@DateOfBirth", SqlDbType.Date).Value = ua.DateOfBirth;
await command.ExecuteNonQueryAsync();
}
private static string GeneratePasswordHash(string pwd)
{
byte[] salt = RandomNumberGenerator.GetBytes(16);