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); }
// 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); }