// PUT: api/People/5 public async Task<IHttpActionResult> Put([FromUri]int id, Person person) { if (!ModelState.IsValid) return BadRequest(ModelState); try { using (var db = new DatabaseContext()) { // Note: Maybe sync properties... Instead of this. // If we where to sync the properties then we would use this code. //var databasePerson = await db.People.Where(x => x.Id == id).FirstOrDefaultAsync(); //if (databasePerson == null) // return NotFound(); db.Entry(person).State = EntityState.Modified; await db.SaveChangesAsync(); } return Ok(); } catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ce) { return NotFound(); } catch (Exception ex) { return InternalServerError(); } }
// POST: api/People public async Task<IHttpActionResult> Post(Person model) { if (!ModelState.IsValid) return BadRequest(ModelState); model.DateCreated = DateTime.Now; using (var db = new DatabaseContext()) { db.People.Add(model); await db.SaveChangesAsync(); } return Ok(); }