public void SaveQuiz(quiz z, string id) { teacher t = db.teachers.SingleOrDefault(x => x.tid == id); cours c = db.courses.SingleOrDefault(x => x.cid.Equals(z.cid)); z.tid = id; t.quizs.Add(z); c.quizs.Add(z); db.quizs.Add(z); db.SaveChanges(); }
public List<quiz> GetQuizes( string id , string cid) { var query = (from x in db.quizs where x.tid.Equals(id) && x.cid.Equals(cid) select x); DateTime d = DateTime.Now; List<quiz> data = new List<quiz> (); foreach (var q in query) { quiz z = new quiz(); z.cid = q.cid; z.qid = q.qid; z.totalQuestion = q.totalQuestion; z.TotalMarks = q.TotalMarks; z.TotalTime = q.TotalTime; z.topic = q.topic; z.startDate = q.startDate; z.endDate = q.endDate; z.quizNum = q.quizNum; if (z.endDate >= d) { data.Add(z); } } return data; }
public List<quiz> getQuize(string id , string cid ) { var query = from x in db.quizs where (x.tid == id && x.cid == cid ) select x; DateTime d = DateTime.Now; List<quiz> data = new List<quiz>(); foreach (var q in query) { quiz z = new quiz(); z.cid = q.cid; z.qid = q.qid; z.totalQuestion = q.totalQuestion; z.TotalMarks = q.TotalMarks; z.TotalTime = q.TotalTime; z.topic = q.topic; z.startDate = q.startDate; z.endDate = q.endDate; z.quizNum = q.quizNum; data.Add(z); } return data; }
public void SaveUpdatedQuiz( quiz q) { db.Entry(q).State = EntityState.Modified; db.SaveChanges(); }
public quiz GetQuizeForUpdation( int id ) { var query = from x in db.quizs.Where(f => f.qid.Equals(id)) select x; quiz q = new quiz(); foreach (var a in query) { q.qid = a.qid; q.tid = a.tid; q.cid = a.cid; q.topic = a.topic; q.TotalMarks = a.TotalMarks; q.totalQuestion = a.totalQuestion; q.TotalTime = a.TotalTime; q.startDate = a.startDate; q.endDate = a.endDate; } return q; }
public List<quiz> getQuiz(string id , string sid ) { var currentDate = DateTime.Now; var q = from x in db.quizs where (x.cid.Equals(id) && x.endDate >= currentDate) select x; List<quiz> qz = new List<quiz>(); foreach (var a in q) { var res = db.quizResults.SingleOrDefault (y=>y.qid == a.qid && y.cid.Equals(a.cid) && y.tid.Equals(a.tid) && y.sid.Equals(sid)); if (res != null && a.totalAttempts > res.attempts) { quiz z = new quiz(); z.qid = a.qid; z.cid = a.cid; z.tid = a.tid; z.totalQuestion = a.totalQuestion; z.TotalMarks = a.TotalMarks; z.TotalTime = a.TotalTime; z.startDate = a.startDate; z.endDate = a.endDate; z.totalAttempts = a.totalAttempts; z.quizNum = a.quizNum; qz.Add(z); } else if (res == null) { quiz z = new quiz(); z.qid = a.qid; z.cid = a.cid; z.tid = a.tid; z.totalQuestion = a.totalQuestion; z.TotalMarks = a.TotalMarks; z.TotalTime = a.TotalTime; z.startDate = a.startDate; z.endDate = a.endDate; z.totalAttempts = a.totalAttempts; z.quizNum = a.quizNum; qz.Add(z); } } return qz; }
public ActionResult SaveUpdatedQuiz( quiz q ) { if (Session["id"] != null ) { try { teacher.SaveUpdatedQuiz(q); LogTeacher log = new LogTeacher(); log.courseId = q.cid; log.discription = "Update Quiz"; log.totalMarks = q.TotalMarks; log.tName = q.tid; log.type = "Quiz"; log.date = DateTime.Today; db.LogTeachers.Add(log); db.SaveChanges(); return RedirectToAction("TeacherHome"); } catch (Exception e) { ViewBag.ErrorType = "Exception"; ViewBag.message = e.Message; return View("ErrorPage"); } } return RedirectToAction("signIn", "Home"); }
public ActionResult Save(quiz z) { if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("Teacher")) { try { string tid = Session["id"].ToString(); string id = tid; var startdate = Request["startDate"]; var enddate = Request["endDate"]; LogTeacher log = new LogTeacher(); log.courseId = z.cid; log.discription = "Save Quiz"; log.totalMarks = z.TotalMarks; log.tName = tid; log.type = "Quiz"; log.date = DateTime.Today; db.LogTeachers.Add(log); db.SaveChanges(); string[] str = startdate.Split(' '); string[] time = str[1].Split(':'); string[] date = str[0].Split('/'); string tt = str[2]; if (tt.Equals("AM")) { DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[0]), Convert.ToInt32(date[1]), Convert.ToInt32(time[0]), Convert.ToInt32(time[1]), 0); z.startDate = dt; } else { DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[0]), Convert.ToInt32(date[1]), Convert.ToInt32(time[0]) + 12, Convert.ToInt32(time[1]), 0); z.startDate = dt; } string[] str1 = enddate.Split(' '); string[] time1 = str1[1].Split(':'); string[] date1 = str1[0].Split('/'); string tt1 = str1[2]; if (tt1.Equals("AM")) { DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]), Convert.ToInt32(time1[1]), 0); z.endDate = dt; } else { DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]) + 12, Convert.ToInt32(time1[1]), 0); z.endDate = dt; } teacher.SaveQuiz(z, id); ViewBag.message = 2; return View("TeacherHome"); } catch (Exception e) { ViewBag.ErrorType = "Exception"; ViewBag.message = e.Message; return View("ErrorPage"); } } else return RedirectToAction("signIn" , "Home"); }