public async Task <IActionResult> Edit(int id, [Bind("ID,QuestionContents,HasOptions,MultipleSelect,Options")] Question question) { if (id != question.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(question); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!QuestionExists(question.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(question)); }
public async Task <IActionResult> Edit(int id, [Bind("UniversityID,UniversityName,UniversityPoints")] University university) { if (id != university.UniversityID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(university); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UniversityExists(university.UniversityID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(university)); }
public async Task <IActionResult> Edit(ViewModel student) { Dictionary <int, List <string> > answers = new Dictionary <int, List <string> >(); var coll = Request.Form.ToList(); foreach (var str in coll) { if (int.TryParse(str.Key, out int key)) { if (answers.ContainsKey(key)) { answers[key].Add(str.Value); } else { answers.Add(key, new List <string> { str.Value }); } Debug.WriteLine(str.Value); } } student.OneStudent.Answers = answers; try { _context.Update(student.OneStudent); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(student.OneStudent.StudentID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", "Students")); }