Userverwaltung improved

This commit is contained in:
Wieland, Marc
2026-06-08 15:45:27 +02:00
parent ee4d6cb5b1
commit dd2d47e57d
8 changed files with 164 additions and 2 deletions
+5 -1
View File
@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
namespace timetracker.Data;
public class AuthService(IDbContextFactory<TimetrackerDbContext> factory)
public class AuthService(IDbContextFactory<TimetrackerDbContext> factory, UserNotificationService notifier)
{
public async Task<User?> LoginAsync(string username, string password)
{
@@ -31,6 +31,8 @@ public class AuthService(IDbContextFactory<TimetrackerDbContext> factory)
{
db.Users.Remove(user);
await db.SaveChangesAsync();
await notifier.NotifyUserDeletedAsync(userId);
await notifier.NotifyUsersChangedAsync();
}
}
@@ -48,6 +50,7 @@ public class AuthService(IDbContextFactory<TimetrackerDbContext> factory)
user.Username = newUsername;
await db.SaveChangesAsync();
await notifier.NotifyUsersChangedAsync();
return null;
}
@@ -65,6 +68,7 @@ public class AuthService(IDbContextFactory<TimetrackerDbContext> factory)
var user = new User { Username = username, PasswordHash = hash, PasswordSalt = salt };
db.Users.Add(user);
await db.SaveChangesAsync();
await notifier.NotifyUsersChangedAsync();
return (user, null);
}
+19
View File
@@ -0,0 +1,19 @@
namespace timetracker.Data;
public class UserNotificationService
{
public event Func<Task>? OnUsersChanged;
public event Func<int, Task>? OnUserDeleted;
public async Task NotifyUsersChangedAsync()
{
if (OnUsersChanged != null)
await OnUsersChanged.Invoke();
}
public async Task NotifyUserDeletedAsync(int userId)
{
if (OnUserDeleted != null)
await OnUserDeleted.Invoke(userId);
}
}