- Create User entity with gamification fields (Level, Streak, Points) - Add User DbSet to AppDbContext with proper configuration - Create initial database migration with Users and Lessons tables - Add SeedData extension for initial admin user and sample lessons - Update Program.cs to use seed data method Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
namespace GermanApp.Domain.Entities;
|
|
|
|
/// <summary>
|
|
/// Represents a user in the DeutschLernen system.
|
|
/// </summary>
|
|
public class User
|
|
{
|
|
public int Id { get; private set; }
|
|
public string Username { get; private set; } = string.Empty;
|
|
public string Email { get; private set; } = string.Empty;
|
|
public string PasswordHash { get; private set; } = string.Empty;
|
|
public string CurrentLevel { get; private set; } = "A1";
|
|
public int Streak { get; private set; }
|
|
public int TotalPoints { get; private set; }
|
|
public DateTime CreatedAt { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Constructor for EF Core deserialization.
|
|
/// </summary>
|
|
private User() { }
|
|
|
|
/// <summary>
|
|
/// Factory method to create a new user.
|
|
/// </summary>
|
|
public static User Create(string username, string email, string passwordHash)
|
|
{
|
|
return new User
|
|
{
|
|
Username = username,
|
|
Email = email.ToLowerInvariant(),
|
|
PasswordHash = passwordHash,
|
|
CurrentLevel = "A1",
|
|
Streak = 0,
|
|
TotalPoints = 0,
|
|
CreatedAt = DateTime.UtcNow
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates user's gamification stats.
|
|
/// </summary>
|
|
public void AddPoints(int points)
|
|
{
|
|
TotalPoints += points;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates user's streak.
|
|
/// </summary>
|
|
public void UpdateStreak(int streak)
|
|
{
|
|
Streak = streak;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates user's current level.
|
|
/// </summary>
|
|
public void UpdateLevel(string level)
|
|
{
|
|
CurrentLevel = level;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Changes user's email.
|
|
/// </summary>
|
|
public void ChangeEmail(string newEmail)
|
|
{
|
|
Email = newEmail.ToLowerInvariant();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Changes user's password hash.
|
|
/// </summary>
|
|
public void ChangePassword(string newPasswordHash)
|
|
{
|
|
PasswordHash = newPasswordHash;
|
|
}
|
|
}
|