Ejemplo n.º 1
0
        public IActionResult Post([FromBody] ConvertModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(
                           new ConvertResult <ConvertModel>(
                               ModelState.SelectMany(r => r.Value.Errors.Select(e => e.ErrorMessage))
                               .ToArray())));
            }

            var parseResult = _commandLineParser.Parse(new Span <char>(model.Curl.ToCharArray()));

            if (!parseResult.Success)
            {
                return(BadRequest(parseResult));
            }

            var csharp = _converterService.ToCsharp(parseResult.Data);

            csharp.AddWarnings(parseResult.Warnings);

            return(Ok(csharp));
        }