// PUT api/Tests/5 public HttpResponseMessage Puttests(int id, tests tests) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != tests.id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(tests).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Tests public HttpResponseMessage Posttests(tests tests) { if (ModelState.IsValid) { db.tests.Add(tests); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, tests); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = tests.id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public bool add_test(int users_id, int correct, int total) { using (english_projectEntities db = new english_projectEntities()) { tests x = db.tests.Add(new tests { users_id = users_id, correct = correct, total = total, created_datetime = DateTime.Now }); try { db.SaveChanges(); } catch { return(false); } return(true); } }