43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using Clarity.Server.Data;
|
|
using Clarity.Server.Entity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Clarity.Server.Services
|
|
{
|
|
public class ProfileService
|
|
{
|
|
private readonly ApplicationDbContext db;
|
|
private readonly IPIIVault piiVault;
|
|
|
|
public ProfileService(ApplicationDbContext db, IPIIVault piiVault)
|
|
{
|
|
this.db = db;
|
|
this.piiVault = piiVault;
|
|
}
|
|
|
|
public Task<Profile?> GetBySubjectAsync(string sub, CancellationToken ct = default) =>
|
|
db.Profiles.FirstOrDefaultAsync(p => p.KeycloakSubject == sub, ct);
|
|
|
|
|
|
|
|
public async Task<Profile> CreateAsync(string sub, string firstName, string? middleName, string lastName, string ssn, CancellationToken ct = default)
|
|
{
|
|
var profile = new Profile
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
KeycloakSubject = sub,
|
|
FirstName = firstName,
|
|
MiddleName = middleName ?? string.Empty,
|
|
LastName = lastName,
|
|
Ssn = ssn,
|
|
OnboardingComplete = true,
|
|
CreatedAt = DateTimeOffset.UtcNow,
|
|
};
|
|
|
|
db.Profiles.Add(profile);
|
|
await db.SaveChangesAsync(ct);
|
|
return profile;
|
|
}
|
|
}
|
|
}
|