public IHttpActionResult PostLease(LeasesModel lease) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbLease = new Lease(lease); db.Leases.Add(dbLease); db.SaveChanges(); lease.LeaseId = dbLease.LeaseId; return CreatedAtRoute("DefaultApi", new { id = lease.LeaseId }, lease); }
public IHttpActionResult PutLease(int id, LeasesModel lease) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != lease.LeaseId) { return BadRequest(); } //var dbLease = db.Leases.Find(id); var dbLease = db.Leases.FirstOrDefault(p => p.Property.User.UserName == User.Identity.Name && p.LeaseId == id); if (dbLease == null) { return BadRequest(); } 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); }
public void Update(LeasesModel l) { LeaseId = l.LeaseId; TenantId = l.TenantId; PropertyId = l.PropertyId; StartDate = l.StartDate; EndDate = l.EndDate; Rent = l.Rent; RentFrequency = (RentFrequencies)l.RentFrequency; }
public Lease(LeasesModel lease) { this.Update(lease); }