public IHttpActionResult PostAddress(AddressesModel address) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var add = new Address(address); db.Addresses.Add(add); db.SaveChanges(); address.AddressId = add.AddressId; return CreatedAtRoute("DefaultApi", new { id = address.AddressId }, address); }
public void Update(AddressesModel a) { AddressId = a.AddressId; Address1 = a.Address1; Address2 = a.Address2; Address3 = a.Address3; Address4 = a.Address4; Address5 = a.Address5; City = a.City; Region = a.Region; PostCode = a.PostCode; International = a.International; }
public IHttpActionResult PutAddress(int id, AddressesModel address) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != address.AddressId) { return BadRequest(); } //grab entry from db var dbAddress = db.Addresses.Find(id); //save entry fetched dbAddress.Update(address); //mark entry as modified db.Entry(dbAddress).State = EntityState.Modified; //save changes try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AddressExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public Address(AddressesModel model) { this.Update(model); }