public IHttpActionResult UploadFile() { try { string filePath; var httpRequest = HttpContext.Current.Request; var subcategoryID = httpRequest.Form["subcategoryID"]; var available = httpRequest.Form["available"]; var questionPaperName = httpRequest.Form["questionPaperName"]; var duration = httpRequest.Form["duration"]; if (httpRequest.Files.Count < 1) { return(BadRequest("Invalid Request")); } test newTest = new test(); if (available == "true") { newTest.available = true; } else { newTest.available = false; } newTest.subcategoryID = Convert.ToInt32(subcategoryID); newTest.questionPaperName = questionPaperName; newTest.duration = TimeSpan.FromMinutes(Convert.ToInt32(duration)); newTest.created_on = DateTime.Now; var postedFile = httpRequest.Files[0]; filePath = HttpContext.Current.Server.MapPath("~/Uploads/" + postedFile.FileName); postedFile.SaveAs(filePath); bllService.AddTest(newTest, filePath); return(Ok("Test Created")); } catch (Exception e) { return(BadRequest(e.Message)); } }