public async Task <User> AddUserAsync(User user)
        {
            var userEntity = user.ToEntity();

            _identityDbContext.Users.Add(userEntity);
            await _identityDbContext.SaveChangesAsync();

            return(user);
        }
        public async Task UpdateUserAsync(User user)
        {
            var existingUser = await _identityDbContext.Users
                               .Where(u => u.SubjectId.Equals(user.SubjectId, StringComparison.OrdinalIgnoreCase) &&
                                      u.ProviderName.Equals(user.ProviderName, StringComparison.OrdinalIgnoreCase))
                               .Include(u => u.UserLogins)
                               .Include(u => u.Claims)
                               .FirstOrDefaultAsync();

            user.ToEntity(existingUser);

            _identityDbContext.Users.Update(existingUser);
            await _identityDbContext.SaveChangesAsync();
        }
        public async Task <User> AddUserAsync(User user)
        {
            var userEntity = user.ToEntity();

            IdentityDbContext.Users.Add(userEntity);
            await IdentityDbContext.SaveChangesAsync();

            await EventService.RaiseAsync(
                new EntityCreatedAuditEvent <User>(
                    UserResolverService.Username,
                    UserResolverService.ClientId,
                    UserResolverService.Subject,
                    user.SubjectId,
                    user,
                    SerializationSettings));

            return(user);
        }
        public async Task UpdateUserAsync(User user)
        {
            var existingUser = await IdentityDbContext.Users
                               .Where(u => u.SubjectId == user.SubjectId &&
                                      u.ProviderName == user.ProviderName)
                               .Include(u => u.UserLogins)
                               .Include(u => u.Claims)
                               .FirstOrDefaultAsync();

            user.ToEntity(existingUser);

            IdentityDbContext.Users.Update(existingUser);
            await IdentityDbContext.SaveChangesAsync();

            await EventService.RaiseAsync(
                new EntityUpdatedAuditEvent <User>(
                    UserResolverService.Username,
                    UserResolverService.ClientId,
                    UserResolverService.Subject,
                    user.SubjectId,
                    user,
                    SerializationSettings));
        }