public ActionResult Create(StudentModel model) { if (!ModelState.IsValid) { return(ReturnJson(false)); } if (model.PhotoFile != null) { var PhotoPath = HttpContext.Server.MapPath("~/Files/Stud"); if (!Directory.Exists(PhotoPath)) { Directory.CreateDirectory(PhotoPath); } var PhotoFileName = Path.Combine(PhotoPath, model.PhotoFile.FileName); if (System.IO.File.Exists(PhotoFileName)) { System.IO.File.Delete(PhotoFileName); } model.PhotoFile.SaveAs(PhotoFileName); model.Info.Photo = model.PhotoFile.FileName; } return(ReturnJson(StudentBiz.AddNew(model.Info))); }
// POST api/default1 public HttpResponseMessage Post(StudentInfo info) { if (ModelState.IsValid) { var result = StudentBiz.AddNew(info); if (result) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, info); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = info.Sn })); return(response); } } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); }