public void Update(PropertyModel property) { Name = property.Name; Address1 = property.Address1; Address2 = property.Address2; City = property.City; State = property.State; Zip = property.Zip; }
public IHttpActionResult PostProperty(PropertyModel property) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbProperty = new Property(); dbProperty.Update(property); db.Properties.Add(dbProperty); db.SaveChanges(); property = Mapper.Map<PropertyModel>(dbProperty); return CreatedAtRoute("DefaultApi", new { id = property.PropertyId }, property); }
public IHttpActionResult PutProperty(int id, PropertyModel property) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != property.PropertyId) { return BadRequest(); } var dbProperty = db.Properties.Find(id); dbProperty.Update(property); db.Entry(dbProperty).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PropertyExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }