Esempio n. 1
0
        public async Task <IActionResult> EditCQO(int idTest, int idLevel, int idClosedQuestionOption)
        {
            var test = await UserContext.Tests.FindAsync(idTest);

            var cqo = await UserContext.ClosedQuestionOptions.FindAsync(idClosedQuestionOption);

            if (test == null || cqo == null)
            {
                return(NotFound());
            }

            var modelCQO = new ChangeCQOViewModel
            {
                TestId = test.Id,
                ClosedQuestionOptionId = cqo.Id,
                Content      = cqo.Content,
                OptionNumber = cqo.OptionNumber,
            };

            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user.Equals(test.User))
            {
                return(View("./Question/ClosedQuestion/ClosedQuestionOption/EditCQO", modelCQO));
            }
            else
            {
                return(NotFound());
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> EditCQO(ChangeCQOViewModel changeCQOViewModel)
        {
            var cqo = await UserContext.ClosedQuestionOptions.FirstOrDefaultAsync(p => p.Id == changeCQOViewModel.ClosedQuestionOptionId);

            if (ModelState.IsValid)
            {
                try
                {
                    cqo.Content      = changeCQOViewModel.Content;
                    cqo.OptionNumber = changeCQOViewModel.OptionNumber;
                    UserContext.ClosedQuestionOptions.Update(cqo);
                    await UserContext.SaveChangesAsync();
                }

                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToRoute("default", new { controller = "Tests", action = "Details", id = changeCQOViewModel.TestId }));
            }

            return(RedirectToAction(nameof(Index)));
        }