public IHttpActionResult PostPhone(Phone phone) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _phoneService.AddOrUpdate(phone); return CreatedAtRoute("DefaultApi", new { id = phone.Id }, phone); }
public void AddOrUpdate(Phone phone) { if (phone.Id == 0) { _repository.Add<Phone>(phone); _unitOfWork.Commit(); } else { _repository.Update<Phone>(phone); _unitOfWork.Commit(); } }
public IHttpActionResult PutPhone(int id, Phone phone) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != phone.Id) { return BadRequest(); } if (!PhoneExists(id)) { return NotFound(); } else { _phoneService.AddOrUpdate(phone); } return StatusCode(HttpStatusCode.NoContent); }