Пример #1
0
        /// <summary>
        /// Finds the answersheet by id
        /// </summary>
        /// <param name="context"></param>
        public async Task <IActionResult> PutAnswerSheet(long id, AnswerSheet answerSheet)
        {
            if (id != answerSheet.Id)
            {
                return(BadRequest());
            }

            _context.Entry(answerSheet).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AnswerSheetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        /// <summary>
        /// Returns the test on the given id
        /// Checks if the test exists,
        /// if it does, it takes it from the DB and loads all the questions and answers from the test
        /// </summary>
        /// <param name="id"></param>
        /// <returns>/Tests/Details/{id}</returns>
        public async Task <IActionResult> Details(long id)
        {
            if (TestExists(id))
            {
                var test = await _context.Tests
                           .FirstOrDefaultAsync(m => m.Id == id);

                await _context.Entry(test).Collection(e => e.Questions).LoadAsync();

                foreach (var question in test.Questions)
                {
                    await _context.Entry(question).Collection(e => e.Answers).LoadAsync();
                }
                return(View(test));
            }
            else
            {
                return(NotFound());
            }
        }