Esempio n. 1
0
        public async Task <IActionResult> Edit(long?id)
        {
            if (IsNotAdmin())
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id == null)
            {
                return(NotFound());
            }
            if (_context.Tests.Any(x => x.Id == id))
            {
                if (_context.Tests.FirstOrDefault(x => x.Id == id).ReleaseStatus != TestStatus.InProgress)
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            else if (id != Consts.backUpTestId)
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (id != Consts.backUpTestId)
            {
                originalTestId = (long)id;
                return(RedirectToAction("Edit", "TestCreation", new { id = Consts.backUpTestId }, lastChangedQuestion));
            }

            var backUpTest = CreateBackUp();
            var viewModel  = TestCreationTransformer.TransformToTestCreationViewModel(backUpTest);

            viewModel.LastChangedQuestion = lastChangedQuestion;
            return(View(viewModel));
        }