public IActionResult Post(IFormFile file) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); // verify .csv file extension if (!fileName.ToLower().EndsWith(".csv")) { return(BadRequest("There was a problem with your file extension. Please make sure that it is properly formatted a .csv file.")); } try { string inputData; using (StreamReader stream = new StreamReader(file.OpenReadStream())) { inputData = stream.ReadToEnd(); } DataTable inputDataTable = new WheelchairData(inputData).wheelchairDataTable; // Run analyzer here and return the text to the view WheelchairMovementAnalyzer algo = new WheelchairMovementAnalyzer(); List <ResultSet> result = algo.AnalyzeDataTable(inputDataTable); Int64 moveTime = algo.MoveTime; Int64 stillTime = algo.StillTime; return(Ok(new { results = result, moveTimeTotal = moveTime, stillTimeTotal = stillTime })); } catch { return(StatusCode(500, "There was a problem analyzing your file. Please make sure it is properly formatted and try again.")); } }
public IActionResult Post(string inputData) { try { DataTable inputDataTable = new WheelchairData(inputData).wheelchairDataTable; WheelchairMovementAnalyzer algo = new WheelchairMovementAnalyzer(); List <ResultSet> result = algo.AnalyzeDataTable(inputDataTable); Int64 moveTime = algo.MoveTime; Int64 stillTime = algo.StillTime; return(Ok(new { results = result, moveTimeTotal = moveTime, stillTimeTotal = stillTime })); } catch { return(BadRequest("There was a problem analyzing your input. Please try again.")); } }