DeutschLernen/GermanApp/Domain/Entities/Level.cs
Lasse Rune Hansen ba81359afa fix(backend): update Lesson entity and related code to use LevelId foreign key
- Updated Lesson entity to use LevelId (int) instead of Level (int)
- Added navigation property Level (Level entity)
- Added Order, Topic, and IsActive properties to Lesson
- Updated Lesson.Create() factory method signature to accept levelId, title, order, topic, description
- Split Update method into individual property update methods
- Updated LessonDto to use LevelId, LevelName, LevelCode instead of Level int
- Added CreateLessonDto and UpdateLessonDto with all required fields
- Added UpdateFromDto extension method for Lesson
- Updated CreateLessonCommand to validate LevelId instead of Level
- Updated SeedDataExtension to seed Level entities first, then use new Lesson.Create() signature
- Made SeedDatabaseAsync async and updated Program.cs to await it
- Updated LessonsEndpoints to use GetByLevelAsync for beginner/advanced queries
- Fixed missing using directive for Domain.Entities

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-07 21:25:46 +02:00

57 lines
1.5 KiB
C#

namespace GermanApp.Domain.Entities;
/// <summary>
/// Represents a CEFR level in the DeutschLernen system (A1, A2, B1, B2, C1).
/// </summary>
public class Level
{
public int Id { get; private set; }
public string Name { get; private set; } = string.Empty;
public string Code { get; private set; } = string.Empty;
public int Order { get; private set; }
/// <summary>
/// Constructor for EF Core deserialization.
/// </summary>
private Level() { }
/// <summary>
/// Factory method to create a new level.
/// </summary>
/// <param name="name">Display name of the level (e.g., "Beginner A1")</param>
/// <param name="code">Short code for the level (e.g., "A1")</param>
/// <param name="order">Sort order of the level</param>
public static Level Create(string name, string code, int order)
{
return new Level
{
Name = name,
Code = code.ToUpperInvariant(),
Order = order
};
}
/// <summary>
/// Updates the level's display name.
/// </summary>
public void UpdateName(string newName)
{
Name = newName;
}
/// <summary>
/// Updates the level's code.
/// </summary>
public void UpdateCode(string newCode)
{
Code = newCode.ToUpperInvariant();
}
/// <summary>
/// Updates the level's sort order.
/// </summary>
public void UpdateOrder(int newOrder)
{
Order = newOrder;
}
}