public IHttpActionResult PostWildlifesighting(Wildlifesighting wildlifesighting) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var session = HttpContext.Current.Session; if (session != null) { if (session["LogedUserID"] == null) wildlifesighting.UserID = 2; else wildlifesighting.UserID = Int32.Parse(session["LogedUserID"].ToString()); } db.Wildlifesightings.Add(wildlifesighting); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = wildlifesighting.WildlifeSightingID }, wildlifesighting); }
public IHttpActionResult PutWildlifesighting(int id, Wildlifesighting wildlifesighting) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != wildlifesighting.WildlifeSightingID) { return BadRequest(); } db.Entry(wildlifesighting).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!WildlifesightingExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }