public ActionResult Index(string index = null, string languageId = null) { var languages = _languageBranchRepository.ListEnabled() .Select(lang => new { lang.LanguageID, lang.Name }) .ToArray(); var indices = _indexHelper.GetIndices() .Select(i => i.Index).ToList(); if (String.IsNullOrWhiteSpace(index) || !indices.Contains(index)) { index = indices.FirstOrDefault(); } ViewBag.Indices = indices.Count > 1 ? indices : null; ViewBag.SelectedIndex = index; if (languageId != null) { CurrentLanguage = languageId; } var model = new SynonymsViewModel(CurrentLanguage); foreach (var language in languages) { var name = language.Name; name = String.Concat(name.Substring(0, 1).ToUpper(), name.Substring(1)); model.SynonymsByLanguage.Add(new LanguageSynonyms { Analyzer = Language.GetLanguageAnalyzer(language.LanguageID), LanguageName = name, LanguageId = language.LanguageID, Synonyms = _synonymRepository.GetSynonyms(language.LanguageID, index) .Select(s => { var key = s.From; if (key.Contains("=>")) { key = key.Split(new[] { "=>" }, StringSplitOptions.None)[0].Trim(); } return(new Synonym { From = key, To = s.To, TwoWay = s.TwoWay }); }) .ToList() }); } return(View("~/Views/ElasticSearchAdmin/Synonyms/Index.cshtml", model)); }
public ActionResult Delete(Synonym synonym, string languageId, string analyzer, string index) { List <Synonym> synonyms = _synonymRepository.GetSynonyms(languageId, index); synonyms.RemoveAll(s => { string synonymFrom = String.Join(",", synonym.From .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(w => w.Trim())); if (!s.TwoWay && !s.MultiWord) { synonymFrom += "=>" + synonymFrom; } return(s.From == synonymFrom && s.To == synonym.To && s.TwoWay == synonym.TwoWay && s.MultiWord == synonym.MultiWord); }); _synonymRepository.SetSynonyms(languageId, analyzer, synonyms, index); return(RedirectToAction("Index", new { index, languageId })); }