public IHttpActionResult PostLease(LeaseModel lease) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbLease = new Lease(); // Lease doesn't need the following code in POST because it's not being created directly by the user // dbLease.User = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); dbLease.Update(lease); db.Leases.Add(dbLease); db.SaveChanges(); lease.LeaseId = dbLease.LeaseId; return CreatedAtRoute("DefaultApi", new { id = lease.LeaseId }, lease); }
public IHttpActionResult PostLease(LeaseModel lease) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbLease = new Lease(); dbLease.User = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); dbLease.Update(lease); db.Leases.Add(dbLease); db.SaveChanges(); lease.LeaseId = dbLease.LeaseId; return CreatedAtRoute("DefaultApi", new { id = lease.LeaseId }, lease); }