public IActionResult FindChord([FromQuery] string sequence, [FromQuery] NamingConvention conv, [FromQuery] bool strict) { ViewData["conv"] = Helper.NamingConventionList(conv); if (sequence == null) { if (IsAjax()) { return(new EmptyResult()); } return(View("FindChord", string.Empty)); } var tokens = sequence.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Note note; var notes = tokens.Select(i => Note.TryParse(i, conv, out note) ? note : null) .Where(i => i != null) .ToArray(); var chords = Chord.Find(notes, strict); if (!chords.Any()) { return(StatusCode(StatusCodes.Status404NotFound, "No chord found")); } var chordDecorator = chords[0] != null ? new ChordDecorator(chords[0], conv) : null; ViewData["sequence"] = sequence; ViewData["parameters"] = new ShowChordParams { root = chords[0].Root.ToString(conv), @type = chords[0].ChordType.ToDescription(), @partial = true, conv = conv }; if (IsAjax()) { return(PartialView("ShowChord", chordDecorator)); } return(View("FindChord", sequence)); }
public void FindChord(WebView webView, NameValueCollection parameters) { string page; if (string.IsNullOrWhiteSpace(parameters["note"])) { var chordParams = new ChordParams(parameters); var model = new FindChordModel { conv = _currentSettings.conv, Strict = chordParams.Strict }; var template = new FindChordView() { Model = model }; page = template.GenerateString(); } else { Note note; var chordParams = new ChordParams(parameters); var tokens = parameters["note"].Split(','); var notes = tokens.Select(i => Note.TryParse(i, _currentSettings.conv, out note) ? note : null) .Where(i => i != null) .ToArray(); var chords = Chord.Find(notes, chordParams.Strict); _allowPartial = true; if (chords.Length > 0) { var chord = chords.First(); _currentRoot = chord.Root; _currentChordType = chord.ChordType; if (chords.Length > 1) { _allRoots = chords.Select(i => i.Root).ToArray(); _allChordTypes = chords.Select(i => i.ChordType.ToDescription()).ToArray(); } else { _allRoots = null; _allChordTypes = null; } parameters.Add("partial", "true"); ShowChordResults(webView, parameters); return; } var model = new FindChordModel { conv = _currentSettings.conv, Strict = chordParams.Strict, SelectedNotes = notes.Select(i => i.ToString(_currentSettings.conv)) .ToArray(), Error = "No chord found" }; var template = new FindChordView() { Model = model }; page = template.GenerateString(); } webView.LoadDataWithBaseURL("file:///android_asset/?page=FindChord", page, "text/html", "UTF-8", null); }