private async Task LookUpWordAsync() { if (string.IsNullOrEmpty(txtLookUp.StringValue)) { return; } string word = txtLookUp.StringValue; LookUpWord command = new LookUpWord(); (bool isValid, string errorMessage) = command.CheckThatWordIsValid(word); if (!isValid) { AlertManager.ShowWarningAlert("Invalid search term", errorMessage); return; } WordViewModel wordViewModel = null; try { WordModel wordModel = await command.LookUpWordAsync(word); wordViewModel = WordViewModel.CreateFromModel(wordModel); log.Translations.Clear(); foreach (RussianTranslation translation in wordViewModel.Translations) { log.Translations.Add(new RussianTranslation(translation.DanishWord, translation.Translation)); } ActivityLog.ReloadData(); if (wordModel == null) { AlertManager.ShowInfoAlert("Cannot find word", $"Den Danske Ordbog doesn't have a page for '{word}'"); } } catch (Exception ex) { AlertManager.ShowWarningAlert("Error occurred while searching word", ex.Message); return; } if (wordViewModel != null) { _wordViewModel = wordViewModel; UpdateControls(); return; } AlertManager.ShowWarningAlert("Cannot find word", $"Cannot find word {word} in DDO."); }
private async Task GetWordVariationAsync(string url) { if (string.IsNullOrEmpty(url)) { AlertManager.ShowWarningAlert("URL is null or empty", "Cannot find a URL to lookup this word"); return; } LookUpWord command = new LookUpWord(); WordViewModel wordViewModel = null; try { WordModel wordModel = await command.GetWordVariationAsync(url); wordViewModel = WordViewModel.CreateFromModel(wordModel); log.Translations.Clear(); foreach (RussianTranslation translation in wordViewModel.Translations) { log.Translations.Add(new RussianTranslation(translation.DanishWord, translation.Translation)); } ActivityLog.ReloadData(); if (wordModel == null) { AlertManager.ShowInfoAlert("Cannot find word", $"Den Danske Ordbog doesn't have a page for url '{url}'"); } } catch (Exception ex) { AlertManager.ShowWarningAlert($"Error occurred while trying to load a page for url '{url}'", ex.Message); return; } if (wordViewModel != null) { _wordViewModel = wordViewModel; UpdateControls(); return; } AlertManager.ShowWarningAlert("Cannot find word", $"Cannot find a page with url '{url}' in DDO."); }