public IActionResult Index(EncodedViewModel encodedViewModel) { if (!ModelState.IsValid) { return(View(encodedViewModel)); } try { var validatedDocument = _documentValidator.ValidateDocument(encodedViewModel.EncodedData.Trim(), encodedViewModel.DocumentHash.Trim()); return(View("Decoded", validatedDocument)); } catch (FormatException e) { _logger.LogWarning(e, $"An exception was thrown at decoding. Could not decode base64. Check your input {encodedViewModel.EncodedData.Trim()}"); ModelState.AddModelError("EncodedData", "Invalid format. Could not decode base64."); return(View(encodedViewModel)); } catch (JsonReaderException e) { _logger.LogWarning(e, $"An exception was thrown at parsing the content to JSON. Check if document encoded data contains a JSON. Input {encodedViewModel.EncodedData.Trim()}"); ModelState.AddModelError("EncodedData", "Invalid format. Could not find valid JSON in decoded text"); return(View(encodedViewModel)); } }
public IActionResult PostContent([FromBody] EncodedViewModel data) { if (!ModelState.IsValid) { throw new ModelStateException("Missing required information"); } byte[] result = _generatorService.GetBytesArray(data.Content, data.BarcodeFormat, data.Height, data.Width, data.Margin); return(File(result, MediaTypeNames.Application.Octet, "encoded.png")); }