public IHttpActionResult PostLease(LeaseModel lease) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbLease = new Lease(); dbLease.Update(lease); db.Leases.Add(dbLease); db.SaveChanges(); lease = Mapper.Map<LeaseModel>(dbLease); return CreatedAtRoute("DefaultApi", new { id = lease.LeaseId }, lease); }
public IHttpActionResult PutLease(int id, LeaseModel lease) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != lease.LeaseId) { return BadRequest(); } var dbLease = db.Leases.Find(id); dbLease.Update(lease); db.Entry(dbLease).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!LeaseExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }