using DrinkRateAPI.Contexts; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; namespace DrinkRateAPI.DbEntities; public class DbApplicationUser : IdentityUser { public virtual DbUserProfile UserProfile { get; set; } } public class UserWithProfileManager : UserManager { private readonly ApplicationDbContext _context; public UserWithProfileManager( IUserStore store, IOptions optionsAccessor, IPasswordHasher passwordHasher, IEnumerable> userValidators, IEnumerable> passwordValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, IServiceProvider services, ILogger> logger, ApplicationDbContext context) : base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger) { _context = context; } public override async Task CreateAsync(DbApplicationUser user, string password) { var result = await base.CreateAsync(user, password); if (!result.Succeeded) return result; var newProfile = new DbUserProfile { ApplicationUser = user, UserName = $"User_{user.Id}", IsAdmin = false, IsDeleted = false }; await _context.UserProfiles.AddAsync(newProfile); await _context.SaveChangesAsync(); return result; } }