Пример #1
0
        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));
        }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }