예제 #1
0
        public IHttpActionResult PostAddress(Address address)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            _addressService.AddOrUpdate(address);

            return CreatedAtRoute("DefaultApi", new { id = address.Id }, address);
        }
예제 #2
0
 public void AddOrUpdate(Address address)
 {
     if (address.Id == 0) {
         _repository.Add<Address>(address);
         _unitOfWork.Commit();
     }
     else
     {
         _repository.Update<Address>(address);
         _unitOfWork.Commit();
     }
 }
예제 #3
0
        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);
        }