public IHttpActionResult SolveMaze(int x1, int y1, int x2, int y2) { byte[] content; try { foreach (string file in HttpContext.Current.Request.Files) { var fileContent = HttpContext.Current.Request.Files[file]; if (fileContent != null && fileContent.ContentLength > 0) { // get a stream var stream = fileContent.InputStream; content = new byte[stream.Length]; stream.Read(content, 0, (int)stream.Length - 1); Business.MazeHound mh = new Business.MazeHound(); if (mh.SolveMaze(System.Text.Encoding.UTF8.GetString(content), x1, y1, x2, y2, 5, 5)) { return(Ok(new ResponseStatus() { email = "*****@*****.**", repo = "", solution = mh.Path })); } } } } catch (Exception) { HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Ok(new ResponseStatus())); } return(Ok(new ResponseStatus() { email = "*****@*****.**", repo = "", solution = "There is not solution" })); }
public JsonResult SolveMaze(HttpPostedFileBase file, InputModel model) { try { byte[] content; Business.MazeHound mh = new Business.MazeHound(); if (file.ContentLength > 0) { content = new byte[file.InputStream.Length]; file.InputStream.Read(content, 0, (int)file.InputStream.Length - 1); if (mh.SolveMaze(System.Text.Encoding.UTF8.GetString(content), model.X1, model.Y1, model.X2, model.Y2, 5, 5)) { return(Json(new ResponseModel() { email = "*****@*****.**", repo = "https://github.com/nhmunoz/GAPHoundChallenge", solution = mh.Path })); } } return(Json(new ResponseModel() { email = "*****@*****.**", repo = "https://github.com/nhmunoz/GAPHoundChallenge", solution = "" })); } catch { return(Json("Error solving maze.")); } }