public async Task<IHttpActionResult> PutQuestion(Question entity) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _unitOfWork.QuestionRepository.Update(entity); try { await _unitOfWork.SaveChangesAsync(); } catch (UpdateConcurrencyException) { if (_unitOfWork.QuestionRepository.Find(entity.QuestionId) == null) { return Conflict(); } throw; } await _unitOfWork.QuestionRepository.LoadRelatedEntitiesAsync(entity); entity.AcceptChanges(); return Ok(entity); }
public async Task<IHttpActionResult> PostQuestion(Question entity) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _unitOfWork.QuestionRepository.Insert(entity); try { await _unitOfWork.SaveChangesAsync(); } catch (UpdateException) { if (_unitOfWork.QuestionRepository.Find(entity.QuestionId) == null) { return Conflict(); } throw; } await _unitOfWork.QuestionRepository.LoadRelatedEntitiesAsync(entity); entity.AcceptChanges(); return CreatedAtRoute("DefaultApi", new { id = entity.QuestionId }, entity); }