public ActionResult CreateQuestion(Question question, int TestID) { var model = new Question(); DataContext _db = new DataContext(); ((Test)_db.Test.Find(TestID)).Questions.Add(question); _db.SaveChanges(); return RedirectToAction("CreateQuestion"); }
public void AddQuestion() { string text = Request.Form["text"]; int test_id = Convert.ToInt32(Request.Form["test_id"]); DataContext db = new DataContext(); Question q = db.Question.Create(); q.GivenQuestion = text; q.TestID = test_id; db.Test.Find(test_id).Questions.Add(q); if(db.SaveChanges() > 0) { Response.Write(q.QuestionID.ToString()); Response.End(); } else { Response.Write("Fail"); Response.End(); } }
public ActionResult CreateQuestion(Test test) { @ViewBag.TestID = test.TestID; DataContext _db = new DataContext(); //_db.Test.Find(test.TestID). //context.Entry(book).Collection(b => b.Reviews).Query().Take(20).Load(); //_db.Entry(test).Collection(x => x.Questions).Query().Load(); //context.Shops.Include(s => s.ShopFacilities.Select(f => f.Facility)) // .First(x => x.Id == id); //context.Shops.Include(s => s.ShopFacilities.Select(f => f.Facility)) // .First(x => x.Id == id); //test = _db.Test.Include(x => x.Questions.Select(f => f.Test)).Take(20); test.Questions = _db.Question.Where(x => x.TestID == test.TestID).ToList(); //_db.Test. //_db.Test. return View(test); }
//GET public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!"; DataContext _db = new DataContext(); _db.Test.First(); return View(); }
public ActionResult Index(Test test) { DataContext _db = new DataContext(); _db.Test.Add(test); _db.SaveChanges(); return RedirectToAction("CreateQuestion", test); }
public ActionResult CreateAnswer(Answer answer) { DataContext _db = new DataContext(); //_db.Question.Answers.Add(); return RedirectToAction("Index"); }