public void UpdateTest(EditTestViewModel editedData)
        {
            var     config   = new MapperConfiguration(cfg => { cfg.CreateMap <EditTestViewModel, Test>(); cfg.IgnoreUnmapped(); });
            IMapper mapper   = config.CreateMapper();
            Test    editTest = mapper.Map <EditTestViewModel, Test>(editedData);

            testRepository.UpdateTest(editTest);
        }
Ejemplo n.º 2
0
 public ActionResult EditTest(EditTestViewModel editedData)
 {
     if (ModelState.IsValid)
     {
         editedData.ModifiedBy   = Convert.ToInt32(Session["CurrentUserID"]);
         editedData.ModifiedTime = DateTime.Now;
         testService.UpdateTest(editedData);
         return(RedirectToAction("UpcomingTest"));
     }
     return(View());
 }
 public ActionResult EditTest(EditTestViewModel editedData)
 {
     if (ModelState.IsValid)
     {
         editedData.ModifiedBy   = Convert.ToInt32(Session["CurrentUserID"]);
         editedData.ModifiedTime = DateTime.Now;
         testService.UpdateTest(editedData);
         return(RedirectToAction("DisplayQuestions", "Question", new { testId = editedData.TestId }));
     }
     return(View());
 }
Ejemplo n.º 4
0
        public IActionResult QuestionsList(string Id)
        {
            EditTestViewModel      model     = new EditTestViewModel();
            List <TestingQuestion> questions = new List <TestingQuestion>();
            var currentTest = _context.Questions.Where(q => q.TestId == Convert.ToInt32(Id));

            questions       = currentTest.ToList();
            model.TestId    = Convert.ToInt32(Id);
            model.Questions = questions;
            return(View(model));
        }
Ejemplo n.º 5
0
 public ActionResult EditTest(EditTestViewModel model, int?testId)
 {
     if (model == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     if (ModelState.IsValid)
     {
         var bllTest = model.ToBllEditTest();
         bllTest.Id = Convert.ToInt32(testId);
         testService.Update(bllTest);
         return(RedirectToAction("TestDetails", "Test", new { testId = testId }));
     }
     return(RedirectToAction("EditTest", "Test", new { testId = testId }));
 }
Ejemplo n.º 6
0
 public static BllTest ToBllEditTest(this EditTestViewModel createTestViewModel)
 {
     if (createTestViewModel == null)
     {
         return(null);
     }
     return(new BllTest()
     {
         Title = createTestViewModel.Title,
         Description = createTestViewModel.Description,
         TimeLimit = createTestViewModel.TimeLimit,
         MinToSuccess = createTestViewModel.MinToSuccess,
         ThemeId = createTestViewModel.ThemeId,
         Questions = new List <BllQuestion>(),
         TestResults = new List <BllTestResult>()
     });
 }
        public ActionResult Test(int?testId)
        {
            var model = new EditTestViewModel();

            if (testId.HasValue)
            {
                var test = DbContext.Tests.Where(x => x.Id == testId.Value).First();

                model.TestId    = test.Id;
                model.Name      = test.Name;
                model.Questions = DbContext.Questions
                                  .Where(x => x.TestId == testId).ToList()
                                  .Select(x => Map(x)).ToList();
            }

            return(View("EditTestView", model));
        }
Ejemplo n.º 8
0
        public IActionResult UpdateTest(EditTestViewModel editTest, int testId)
        {
            Test test = context.Tests
                        .Include(t => t.Questions)
                        .ThenInclude(q => q.Options)
                        .Single(t => t.Id == testId);

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

            if (ModelState.IsValid)
            {
                test.Description = editTest.Description;
                test.NameOfTest  = editTest.NameOfTest;
                test.UpdatedAt   = DateTime.Now;

                foreach (Question question in editTest.Questions)
                {
                    Question existingQuestion = context.Questions.SingleOrDefault(q => q.Id == question.Id);

                    existingQuestion.Prompt             = question.Prompt;
                    existingQuestion.ImgRelatedToPrompt = question.ImgRelatedToPrompt;
                    existingQuestion.Answer             = question.Answer;

                    if (question.Options != null)
                    {
                        foreach (Option option in question.Options)
                        {
                            Option existingOption = context.Options.SingleOrDefault(o => o.Id == option.Id);
                            existingOption.Label = option.Label;
                        }
                    }
                }


                context.SaveChanges();
                return(Redirect("/Test/Details/" + test.Id));
            }



            return(View("/Index"));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Edit(int id)
        {
            Test test = await db.Tests.Include("Section").FirstOrDefaultAsync(t => t.Id == id);

            if (test == null)
            {
                return(Content("Нет теста с таким Id"));
            }
            EditTestViewModel model = new EditTestViewModel {
                Id = test.Id, Name = test.Name, Section = test.Section.Name
            };
            List <string> list = new List <string>();

            foreach (Section sect in db.Sections)
            {
                list.Add(sect.Name);
            }
            ViewBag.Sections = new SelectList(list.ToArray());
            return(View(model));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Edit(EditTestViewModel model)
        {
            if (ModelState.IsValid)
            {
                Test test = await db.Tests.FirstOrDefaultAsync(t => t.Id == model.Id);

                if (test != null)
                {
                    test.Name      = model.Name;
                    test.SectionId = db.Sections.FirstOrDefault(t => t.Name == model.Section).Id;
                    db.Tests.Update(test);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Нет такого теста в базе, возможно он был удалён");
                }
            }
            return(View(model));
        }
        public ActionResult Test(EditTestViewModel model)
        {
            if (ModelState.IsValid)
            {
                var test = model.TestId.HasValue
                    ? DbContext.Tests.Where(x => x.Id == model.TestId.Value).First()
                    : new Test();

                test.Name = model.Name;

                if (!model.TestId.HasValue)
                {
                    DbContext.Tests.Add(test);
                }

                DbContext.SaveChanges();

                return(RedirectToAction("Index", "Tests", null));
            }

            return(View("EditTestView", model));
        }
Ejemplo n.º 12
0
 public EditTestPage(EditTestViewModel vm) : this()
 {
     BindingContext = vm;
 }