예제 #1
0
        public List<question> GetTopic( string id )
        {
            var query = from x in db.questions where x.cid == id
                         select x;

            List<question> data = new List<question>();
            List<string> temp = new List<string>();

            foreach (var q in query)
            {
                question c = new question();
                c.topic = q.topic;
                if ( !(temp.Contains(q.topic)) )
                    data.Add(c);
                temp.Add(q.topic);
            }
            return data;

        }
예제 #2
0
        public ActionResult GenerateResult(FormCollection form)
        {
            string questions = Request["QID"];

            string TeacherID = Request["TID"];
            string QuizID = Request["QuizID"];
            string CourseID = Request["CID"];
            string attempt = Request["TotalAttempts"];

            var qu = from x in db.courses where x.cid == CourseID select x;
            string cname = "";
            foreach (var a in qu)
                cname = a.name;

            string[] token = questions.Split(',');
            int totalQuestion = token.Length - 1;
            int obtainedMarks = 0;

            List<question> qs = new List<question>();

            var q = from x in db.questions
                    where (x.cid.Equals(CourseID))
                    select x;

            foreach (var a in q)
            {
                question s = new question();
                s.quid = a.quid;
                s.statement = a.statement;
                s.option_A = a.option_A;
                s.option_B = a.option_B;
                s.Option_C = a.Option_C;
                s.option_D = a.option_D;
                s.correctOption = a.correctOption;
                s.solution = a.solution;
                s.marks = a.marks;

                qs.Add(s);
            }

            int attempted = 0;
            int wrong = 0;
            int correct = 0;
            int blank = 0;
            string str = form[token[1]];
            for (int i = 1; i < token.Length; i++)
            {
                if (form[token[i]] != null)
                {
                    attempted = attempted + 1;
                    if (qs.Find(ques => ques.quid == Convert.ToInt32(token[i])).correctOption.Equals(form[token[i]]))
                    {
                        obtainedMarks = obtainedMarks + 1;
                        correct = correct + 1;
                    }
                    else
                    {
                        wrong = wrong + 1;
                    }
                }
                
            }
            blank = totalQuestion - attempted;
            int qid = Convert.ToInt32(QuizID);
            string id = Session["id"].ToString();
            var res = db.quizResults.SingleOrDefault(y =>y.qid == qid && y.cid.Equals(CourseID) && y.tid.Equals(TeacherID) && y.sid.Equals(id));

            quizResult qr = new quizResult();
            qr.cid = CourseID;
            qr.qid = Convert.ToInt32(QuizID);
            qr.tid = TeacherID;
            qr.sid = Session["id"].ToString();
            qr.totalmarks = totalQuestion.ToString();
            qr.obtainMarks = obtainedMarks.ToString();
            
            
            if (res != null)
            {
                if (Convert.ToInt32(attempt) > res.attempts && Convert.ToInt32(res.obtainMarks) < obtainedMarks)
                {
                    res.totalmarks = totalQuestion.ToString();
                    res.obtainMarks = obtainedMarks.ToString();
                    res.attempts = res.attempts + 1;

                    Log log = new Log();
                    log.courseId = qr.cid;
                    log.discription = "Take Quiz "+res.attempts;
                    log.totalMarks = Convert.ToInt32(qr.totalmarks);
                    log.tName = qr.tid;
                    log.type = "Quiz";
                    log.studentId = qr.sid;
                    log.obtainedMarks = Convert.ToInt32(qr.obtainMarks);
                    log.date = DateTime.Now;

                    db.Logs.Add(log);

                    db.SaveChanges();
                }
            }
            else if (res == null)
            {
                qr.attempts = 1;

                Log log = new Log();
                log.courseId = qr.cid;
                log.discription = "Take Quiz Attempt # " + qr.attempts;
                log.totalMarks = Convert.ToInt32(qr.totalmarks);
                log.tName = qr.tid;
                log.type = "Quiz";
                log.studentId = qr.sid;
                log.obtainedMarks = Convert.ToInt32(qr.obtainMarks);
                log.date = DateTime.Now;

                db.Logs.Add(log);

                db.quizResults.Add(qr);
                db.SaveChanges();
            }
            
            ViewBag.correct = correct;
            ViewBag.wrong = wrong;
            ViewBag.blank = blank;
            ViewBag.attempted = attempted;
            ViewBag.name = cname;

            return View(qr);
        }
예제 #3
0
        public void SaveQuestions(string id, string topic, string fileName)
        {
            FileStream fin = new FileStream(fileName, FileMode.Open);
            StreamReader sr = new StreamReader(fin);
            question q = new question();
            cours c = db.courses.SingleOrDefault(x => x.cid.Equals(id));

            q.statement = sr.ReadLine();
            q.option_A = sr.ReadLine();
            q.option_B = sr.ReadLine();
            q.Option_C = sr.ReadLine();
            q.option_D = sr.ReadLine();
            q.correctOption = sr.ReadLine();
            q.marks = Convert.ToInt32(sr.ReadLine());
            q.solution = sr.ReadLine();
            q.topic = topic;
            q.cid = id;
            c.questions.Add(q);
            db.questions.Add(q);
            db.SaveChanges();

            string str = sr.ReadLine();

            while (str != null)
            {
                q.statement = str;
                q.option_A = sr.ReadLine();
                q.option_B = sr.ReadLine();
                q.Option_C = sr.ReadLine();
                q.option_D = sr.ReadLine();
                q.correctOption = sr.ReadLine();
                q.marks = Convert.ToInt32(sr.ReadLine());
                q.solution = sr.ReadLine();
                q.topic = topic;
                q.cid = id;
                c.questions.Add(q);
                db.questions.Add(q);
                db.SaveChanges();

                str = sr.ReadLine();
            }
            sr.Close();
            fin.Close();
        }
예제 #4
0
        public List<question> getQuestions(string id , int totalQ )
        {
            List<question> qs = new List<question>();

            List<question> randomQuestions = new List<question>();

            var q = from x in db.questions
                    where (x.cid.Equals(id))
                    select x;

            foreach (var a in q)
            {
                question s = new question();
                s.quid = a.quid;
                s.statement = a.statement;
                s.option_A = a.option_A;
                s.option_B = a.option_B;
                s.Option_C = a.Option_C;
                s.option_D = a.option_D;
                s.correctOption = a.correctOption;
                s.solution = a.solution;
                s.marks = a.marks;

                qs.Add(s);
            }

            randomQuestions = getRandomList( qs , totalQ);

            return randomQuestions;
        }