public IActionResult FinishNewTranslation(NewWordModel model) { var word = WordsService.Get(model.TranslationForID); if (word == default) { return(ShowErrorViewForNotFoundWord(model.TranslationForID)); } var language = LanguagesService.Get(model.WordLanguageID); var newWord = new Word(word.MasterWord, model.WordText, language); EditEntityModel.FillUpWord(model, newWord, language); TryOrAlert(model, () => WordsService.Add(newWord)); if (model.AlertType == default) { return(RedirectToAction("Word", new { id = newWord.ID })); } else { model.AvailableLanguages = LanguagesService.GetAll() .Where(lang => word[lang.ID] == default && lang.ID != word.LanguageID).ToArray(); return(View("NewTranslation", model)); } }
public IActionResult GetResource(string lang, string name) { if (!lang.IsValidPartitionOrRowKey()) { return(BadRequest(ErrorResponse.Create($"Invalid {nameof(lang)} value"))); } if (!name.IsValidPartitionOrRowKey()) { return(BadRequest(ErrorResponse.Create($"Invalid {nameof(name)} value"))); } var language = _languagesService.Get(lang); if (language == null) { return(BadRequest(ErrorResponse.Create($"Language with code '{lang}' not found"))); } var resource = _textResourcesService.Get(lang, name); if (resource == null) { return(NotFound()); } return(Ok(resource)); }
public IActionResult CompleteNewBook(EditBookModel model) { if (!HandleErrorsBeforeCompletingBook(model)) { return(View("NewBook", model)); } // Add book var book = new Book(model.BookName, LanguagesService.Get(model.BookLanguageID), model.BookDescription); book = BooksService.Add(book); return(RedirectToAction("Book", new { id = book.ID })); }
/// <summary> /// Called when [activated]. /// </summary> /// <param name="disposables">The disposables.</param> protected override void OnActivated(CompositeDisposable disposables) { Languages = languageService.Get(); previousLanguage = SelectedLanguage = Languages.FirstOrDefault(p => p.IsSelected); var lanuageChanged = this.WhenAnyValue(p => p.SelectedLanguage).Where(p => p != null && Languages?.Count() > 0).Subscribe(p => { if (languageService.SetSelected(Languages, p)) { if (previousLanguage != p) { var args = new LocaleChangedEventArgs() { Locale = p.Abrv, OldLocale = previousLanguage.Abrv }; ReactiveUI.MessageBus.Current.SendMessage(args); previousLanguage = p; } } }).DisposeWith(disposables); base.OnActivated(disposables); }
public IActionResult Show(int LanguageFromID, int LanguageToID, int SelectedBookID) { var book = BooksService.Get(SelectedBookID); var model = new WordsModel() { LanguageFromID = LanguageFromID, LanguageToID = LanguageToID, SelectedBookID = SelectedBookID, AvailableLanguages = LanguagesService.GetAll().ToArray(), From = LanguagesService.Get(LanguageFromID), To = LanguagesService.Get(LanguageToID), Books = BooksService.GetAllWithLanguage().Select(w => (w.ID, w.Name, w.Language.Name)).ToArray(), }; PopulateModelWithWords(LanguageFromID, LanguageToID, SelectedBookID, model); return(View(model)); }
public IActionResult EditLanguages(string buttonName, string languageName) { Action ac = () => { }; if (buttonName == "New") { if (string.IsNullOrEmpty(languageName)) { return(RedirectToAction("ErrorIndex", new { errorMsg = "Language name cannot be empty." })); } var lang = new Language(languageName); ac = () => LanguagesService.Add(lang); } else { var id = int.Parse(buttonName.Split("_")[1]); var lang = LanguagesService.Get(id); if (buttonName.StartsWith("Rename")) { if (string.IsNullOrEmpty(languageName)) { return(RedirectToAction("ErrorIndex", new { errorMsg = "Language name cannot be empty." })); } lang.Name = languageName; ac = () => LanguagesService.Update(lang); } else if (buttonName.StartsWith("Delete")) { try { LanguagesService.Remove(lang); } catch { return(RedirectToAction("ErrorIndex", new { errorMsg = "Cannot delete language because there are words still using it." })); } } } try { ac.Invoke(); } catch (Exception e) { return(RedirectToAction("ErrorIndex", new { errorMsg = "Something went wrong: " + e.Message })); } return(RedirectToAction("Index")); }
public async Task <IActionResult> DeleteLanguage(string code) { if (string.IsNullOrEmpty(code)) { return(BadRequest(ErrorResponse.Create($"{nameof(code)} can't be empty"))); } if (!code.IsValidPartitionOrRowKey()) { return(BadRequest(ErrorResponse.Create($"Invalid {nameof(code)} value"))); } var language = _service.Get(code); if (language == null) { return(BadRequest(ErrorResponse.Create($"Language with code '{code}' not found"))); } await _service.DeleteAsync(code); return(Ok()); }
public async Task <Language> Get(int id) => await _memoryCache.GetOrCreateAsync( $"{_typeName}-Get-{id}", entry => _languagesService.Get(id));
public ActionResult Details(long id) { return(View(_languagesService.Get(id))); }
public Languages Get(int id, bool @readonly = false) { return(_service.Get(id, @readonly)); }
public ServiceResponse <LanguagesDto> Get(byte languagesId) { return(_service.Get(languagesId)); }