public async Task <Unit> Handle(CreateWordCommand request, CancellationToken cancellationToken) { var user = await _authorizationProvider.GetCurrentUser(); var entity = new Word(request.LanguageId, request.Text.ToLower(), request.Translation.ToLower(), user.Id, request.WordCategoryId); _context.Words.Add(entity); await _context.SaveChangesAsync(cancellationToken); await _textToSpeechService.GenerateSpeechFile(entity.Text, $"wwwroot/Assets/Mp3/{entity.Text}.mp3"); return(Unit.Value); }
public async Task <Unit> Handle(UpdateWordCommand request, CancellationToken cancellationToken) { var entity = await _context.Words.SingleOrDefaultAsync(w => w.Id == request.Id, cancellationToken); if (entity == null) { throw new NotFoundException(nameof(Word), request.Id); } if (entity.Text != request.Text) { File.Delete($"wwwroot/Assets/Mp3/{entity.Text}.mp3"); _textToSpeechService.GenerateSpeechFile(request.Text, $"wwwroot/Assets/Mp3/{request.Text}.mp3"); } entity.Update(request.Text.ToLower(), request.Translation.ToLower(), request.WordCategoryId); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }