public IHttpActionResult GetKingAnswer(int id) { KingAnswer kinganswer = db.KingAnswers.Find(id); if (kinganswer == null) { return(NotFound()); } return(Ok(kinganswer)); }
public IHttpActionResult PostKingAnswer(KingAnswer kinganswer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.KingAnswers.Add(kinganswer); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = kinganswer.Id }, kinganswer)); }
public IHttpActionResult DeleteKingAnswer(int id) { KingAnswer kinganswer = db.KingAnswers.Find(id); if (kinganswer == null) { return(NotFound()); } db.KingAnswers.Remove(kinganswer); db.SaveChanges(); return(Ok(kinganswer)); }
// PUT api/KingAnswer/5 public IHttpActionResult PutKingAnswer(int id, KingAnswer kinganswer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //get week var weekId = db.Week.First().Week_Id; //set week to geomaster kinganswer.Week = weekId; if (id != kinganswer.Id) { return(BadRequest()); } db.Entry(kinganswer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!KingAnswerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }