public IHttpActionResult PostEmail(Email email) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _emailService.AddOrUpdate(email); return CreatedAtRoute("DefaultApi", new { id = email.Id }, email); }
public void AddOrUpdate(Email email) { if (email.Id == 0) { _repository.Add<Email>(email); _unitOfWork.Commit(); } else { _repository.Update<Email>(email); _unitOfWork.Commit(); } }
public IHttpActionResult PutEmail(int id, Email email) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != email.Id) { return BadRequest(); } if (!EmailExists(id)) { return NotFound(); } else { _emailService.AddOrUpdate(email); } return StatusCode(HttpStatusCode.NoContent); }