public async Task <IHttpActionResult> PutQuizRun(int id, QuizRun model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != model.Id) { return(BadRequest()); } db.Entry(model).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!QuizRunExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PostQuizRun(QuizRun model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.QuizRuns.Add(model); await db.SaveChangesAsync(); var ret = await db.QuizRuns.Select(QuizRunDTO.SELECT).FirstOrDefaultAsync(x => x.Id == model.Id); return(CreatedAtRoute("DefaultApi", new { id = model.Id }, model)); }
public async Task <IHttpActionResult> DeleteQuizRun(int id) { QuizRun model = await db.QuizRuns.FindAsync(id); if (model == null) { return(NotFound()); } db.QuizRuns.Remove(model); await db.SaveChangesAsync(); var ret = await db.QuizRuns.Select(QuizRunDTO.SELECT).FirstOrDefaultAsync(x => x.Id == model.Id); return(Ok(ret)); }