public async Task<LessonDTO> CreateAsync(CreateLessonDTO input)
{
try
{
var lessonCount = await _lessonRepository.CountAsync(x => x.CreatorId == CurrentUser.Id);
var lesson = ObjectMapper.Map<CreateLessonDTO, Lesson>(input);
lesson.LessonNumber = lessonCount + 1;
lesson.CreatorId = CurrentUser.Id;
lesson.isServerGenerated = false;
lesson = await _lessonRepository.InsertAsync(lesson);
_activeLesson=lesson;
await UpdateLessonStateAsync(true);
UpdatePrivateFields(lesson);
return ObjectMapper.Map<Lesson, LessonDTO>(lesson);
}
catch (Exception ex)
{
// Handle the exception here, or re-throw it if appropriate
throw new Exception("An error occurred while creating the lesson.", ex);
}
}
public async Task<LessonDTO> CreateAsync(CreateLessonDTO input)
{
try
{
var lessonCount = await _lessonRepository.CountAsync(x => x.CreatorId == CurrentUser.Id);
var lesson = ObjectMapper.Map<CreateLessonDTO, Lesson>(input);
lesson.LessonNumber = lessonCount + 1;
lesson.CreatorId = CurrentUser.Id;
lesson.isServerGenerated = false;
lesson = await _lessonRepository.InsertAsync(lesson);
_activeLesson=lesson;
await UpdateLessonStateAsync(true);
UpdatePrivateFields(lesson);
return ObjectMapper.Map<Lesson, LessonDTO>(lesson);
}
catch (Exception ex)
{
// Handle the exception here, or re-throw it if appropriate
throw new Exception("An error occurred while creating the lesson.", ex);
}
}