public ActionResult EditPost(int? id) { TestMain item = null; try { if (id.HasValue) { item = db.TestMain.SingleOrDefault(i => i.Id == id); if (item == null) throw new ArgumentException("Тест не найден."); } else { item = new TestMain(); } TryUpdateModel(item, "Item", new[] { "Title", "Topic", "Author", "Code" }); if (ModelState.IsValid) { if (id == null) db.TestMain.Add(item); else db.Entry<TestMain>(item).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } return View(new TestViewModel(db, item)); }
// // GET: /Admin/Test/Edit public ActionResult Edit(int? id) { TestMain item = null; try { if (id.HasValue) { item = db.TestMain.SingleOrDefault(i => i.Id == id); if (item == null) throw new ArgumentException("Тест не найден."); } else { item = new TestMain(); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } return View(new TestViewModel(db, item)); }
public TestViewModel(DataContext db, TestMain item, Question question, Answer answer) : this(db, item, question) { Answer = answer; }
public TestViewModel(DataContext db, TestMain item, Question question) : this(db, item) { Question = question; }
public TestViewModel(DataContext db, TestMain item) : this(db) { Item = item; }