public async Task <Exercise> Handle(CreateExerciseCommand request, CancellationToken cancellationToken) { await EndUnfinishedExercises(); var phonemes = await _phonemizer.GetPhonemesAsync(request.TargetPhrase); var entity = new Exercise(request.PersonName, request.TargetPhrase, request.Language, phonemes); entity.Start(); _dbContext.Add(entity); await _dbContext.SaveChangesAsync(); return(entity); }
public async Task <bool> Handle(DeleteExerciseCommand request, CancellationToken cancellationToken) { var entity = await _dbContext.PhraseExercises .Include(e => e.Utterances) .FirstOrDefaultAsync(e => e.Id == request.Id); if (entity is null) { throw new InvalidOperationException($@"Phrase exercise not found! (id={request.Id})"); } _dbContext.Remove(entity); await _dbContext.SaveChangesAsync(); return(true); }
public async Task <Utterance> Handle(RegisterUtteranceCommand request, CancellationToken cancellationToken) { var entity = await _dbContext.PhraseExercises .Include(e => e.Utterances) .FirstOrDefaultAsync(e => e.Id == request.Id); if (entity is null) { throw new InvalidOperationException($@"Phrase exercise not found! (id={request.Id})"); } var phonemes = await _phonemizer.GetPhonemesAsync(request.RecognizedPhrase); var utterance = entity.RegisterUtterance(request.RecognizedPhrase, phonemes); _dbContext.Update(entity); await _dbContext.SaveChangesAsync(); return(utterance); }