public IHttpActionResult PostAddress(Address address) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _addressService.AddOrUpdate(address); return CreatedAtRoute("DefaultApi", new { id = address.Id }, address); }
public void AddOrUpdate(Address address) { if (address.Id == 0) { _repository.Add<Address>(address); _unitOfWork.Commit(); } else { _repository.Update<Address>(address); _unitOfWork.Commit(); } }
public IHttpActionResult PutAddress(int id, Address address) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != address.Id) { return BadRequest(); } if (!AddressExists(id)) { return NotFound(); } else { _addressService.AddOrUpdate(address); } return StatusCode(HttpStatusCode.NoContent); }