Ejemplo n.º 1
0
        public IActionResult ShowChordLayouts([FromQuery] ShowChordParams parameters)
        {
            if (string.IsNullOrWhiteSpace(parameters.root))
            {
                return(BadRequest());
            }
            if (!IsAjax())
            {
                return(BadRequest());
            }

            var cacheId = parameters.ToString();
            var result  = _cache.GetOrCreate(cacheId, entry =>
            {
                try
                {
                    var chordSymbol = $"{parameters.root}{parameters.@type}";
                    Chord chord;

                    if (!Chord.TryParse(chordSymbol, parameters.conv, out chord))
                    {
                        return(null);
                    }
                    var chordDecorator = new ChordDecorator(chord, parameters.conv);
                    var layouts        = chordDecorator.GenerateLayouts(true, parameters.special, parameters.@partial, 10);

                    return(layouts);
                }
                catch (Exception)
                {
                    return(null);
                }
            });

            if (result == null)
            {
                return(BadRequest());
            }

            return(PartialView(result));
        }