public async Task <IActionResult> Edit(int id, [Bind("eId,nrQuestions,examTime,examDifficulty,Group,ApplicationUserId,CourseID")] Exam exam) { if (id != exam.eId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(exam); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExamExists(exam.eId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "Id", exam.ApplicationUserId); ViewData["CourseID"] = new SelectList(_context.Course, "cId", "courseName", exam.CourseID); return(View(exam)); }
public async Task <IActionResult> Create([Bind("qId,eId")] ExamQuestion examQuestion) { if (ModelState.IsValid) { _context.Add(examQuestion); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["eId"] = new SelectList(_context.Exam, "eId", "eId", examQuestion.eId); ViewData["qId"] = new SelectList(_context.Question, "qId", "qId", examQuestion.qId); return(View(examQuestion)); }
public async Task <IActionResult> Details(StudAnswer studAnswer) { var examId = RouteData.Values["id"]; var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); System.Collections.Generic.List <ExamQuestion> StudQuestionsList = _context.ExamQuestion.Where(aa => aa.eId == Convert.ToUInt32(examId)).ToList(); string[] StudAnswerList = Request.Form["textarea3"].ToString().Split(new[] { ',' }); var CurrentExam = _context.StudExam.Where(a => a.EId == Convert.ToUInt32(examId) && a.ApplicationUserId == userId).FirstOrDefault(); if (ModelState.IsValid) { for (int i = 0; i < StudQuestionsList.Count; i++) { studAnswer.AnswerId = Guid.NewGuid().ToString(); studAnswer.Answer = StudAnswerList[i]; studAnswer.QuestionId = StudQuestionsList[i].qId; studAnswer.ExamId = CurrentExam.StudExamId; CurrentExam.IsSolved = true; _context.Add(studAnswer); await _context.SaveChangesAsync(); } } return(Redirect("~/Students/LogIn")); }
public async Task <IActionResult> Create([Bind("qId,Text,Answer,Difficulty,Time,CourseId")] Question question) { if (ModelState.IsValid) { _context.Add(question); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } var loggedUser = User.FindFirstValue(ClaimTypes.NameIdentifier); var coursesList = from c in _context.Course join q in _context.Question on c.cId equals q.CourseId where c.ApplicationUserId == loggedUser select c.courseName; ViewData["CourseId"] = new SelectList(_context.Set <Course>(), "cId", "courseName", coursesList.FirstOrDefault()); return(View(question)); }