public void Update(AddressModel modelAddress) { Address1 = modelAddress.Address1; Address2 = modelAddress.Address2; Address3 = modelAddress.Address3; Address4 = modelAddress.Address4; Address5 = modelAddress.Address5; City = modelAddress.City; State = modelAddress.State; PostCode = modelAddress.PostCode; International = modelAddress.International; }
public IHttpActionResult PutAddress(int id, AddressModel modelAddress) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != modelAddress.AddressId) { return BadRequest(); } #region // to be changed // 1.Grab the entry from the database var dbAddress = db.Addresses.Find(id); // 2. Update the entry fetched from the database dbAddress.Update(modelAddress); // 3. Mark entry as modified db.Entry(dbAddress).State = EntityState.Modified; #endregion try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AddressExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostAddress(AddressModel address) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var newAddress = new Address(); newAddress.Update(address); db.Addresses.Add(newAddress); db.SaveChanges(); address.AddressId = newAddress.AddressId; return CreatedAtRoute("DefaultApi", new { id = address.AddressId }, address); }