예제 #1
0
        public ActionResult DeleteAssignStudentPost(int id)
        {
            //if ((string)Session["Userid"] != null && (string)Session["Level"] != null)
            //{
            //    if ((string)Session["Level"] == "admin")
            //    {
            using (TsmsDBContext context = new TsmsDBContext())
            {
                ExamAssign assign = context.ExamAssigns.SingleOrDefault(p => p.Id == id);
                int        examid = assign.ExamID;
                context.ExamAssigns.Remove(assign);
                context.SaveChanges();
                return(RedirectToAction("AssaignCourse", new { id = examid }));
            }
            //    }

            //    else
            //    {
            //        return RedirectToAction("Index", "Exam");
            //    }
            //}
            //else
            //{
            //    return RedirectToAction("Index", "Exam");
            //}
        }
예제 #2
0
        public ActionResult ShowQuestion(FormCollection form)
        {
            //if ((string)Session["Userid"] != null && (string)Session["Level"] != null)
            //{
            using (TsmsDBContext context = new TsmsDBContext())
            {
                int  examId = Convert.ToInt32(Request.Form["hidden"]);
                Exam exam   = context.Exams.SingleOrDefault(p => p.Id == examId);
                for (int i = 1; i <= exam.TotalQues; i++)
                {
                    Answer ans = new Answer();
                    ans.StudentId  = (string)Session["Userid"];
                    ans.StuAns     = Convert.ToInt32(Request.Form[i.ToString()]);
                    ans.ExamId     = examId;
                    ans.QuestionId = Convert.ToInt32(Request.Form["QuesId" + i.ToString()]);
                    Question ques = context.Questions.SingleOrDefault(p => p.Id == ans.QuestionId);
                    if (ans.StuAns == ques.CorrectAns)
                    {
                        ans.Result = true;
                    }
                    else
                    {
                        ans.Result = false;
                    }

                    context.Answers.Add(ans);
                    context.SaveChanges();
                }
                List <Answer> answers = context.Answers.Where(p => p.ExamId == examId && p.StudentId == (string)Session["Userid"]).ToList();
                float         achived = 0;
                foreach (Answer answer in answers)
                {
                    if (answer.Result == true)
                    {
                        achived++;
                    }
                }
                Exam       examOb = context.Exams.SingleOrDefault(p => p.Id == examId);
                float      Marks  = achived * examOb.MarkPerQues;
                ExamAssign assign = context.ExamAssigns.SingleOrDefault(p => p.ExamID == examId && p.StudentID == Convert.ToString(Session["Userid"]));
                assign.gotMark = Marks.ToString();
                context.ExamAssigns.Attach(assign);
                var entry = context.Entry(assign);
                entry.Property(e => e.gotMark).IsModified = true;
                context.SaveChanges();
                float totalmarks = examOb.TotalQues * examOb.MarkPerQues;
                return(RedirectToAction("ShowResult", new { id = examId, total = totalmarks, achieved = Marks }));
            }
            //}
            //else
            //{
            //    return RedirectToAction("Index", "Exam");
            //}
        }
예제 #3
0
        public ActionResult AssaignStudent(FormCollection form)
        {
            //if ((string)Session["Userid"] != null && (string)Session["Level"] != null)
            //{
            //    if ((string)Session["Level"] == "admin")
            //    {

            using (TsmsDBContext context = new TsmsDBContext())
            {
                List <ExamAssign> all = context.ExamAssigns.Where(p => p.StudentID == Request.Form["stuName"] && p.ExamID == Convert.ToInt32(Request.Form["ExamId"])).ToList();
                if (all == null)
                {
                    ViewBag.ExamId = Convert.ToInt32(Request.Form["ExamId"]);
                    ExamAssign assign = new ExamAssign();
                    assign.ExamID    = Convert.ToInt32(Request.Form["ExamId"]);
                    assign.StudentID = Request.Form["stuName"];
                    context.ExamAssigns.Add(assign);
                    context.SaveChanges();
                    List <ExamAssign> assaign = context.ExamAssigns.Where(p => p.ExamID == Convert.ToInt32(Request.Form["ExamId"])).ToList();
                    return(View(assaign));
                }
                else
                {
                    ViewBag.ExamId = Convert.ToInt32(Request.Form["ExamId"]);
                    List <ExamAssign> assaign = context.ExamAssigns.Where(p => p.ExamID == Convert.ToInt32(Request.Form["ExamId"])).ToList();
                    return(View(assaign));
                }
            }
            //    }
            //    else
            //    {
            //        return RedirectToAction("Index", "Exam");
            //    }
            //}
            //else
            //{
            //    return RedirectToAction("Index", "Exam");
            //}
        }
예제 #4
0
        public ActionResult DeleteAssignStudent(int id)
        {
            //if ((string)Session["Userid"] != null && (string)Session["Level"] != null)
            //{
            //    if ((string)Session["Level"] == "admin")
            //    {
            using (TsmsDBContext context = new TsmsDBContext())
            {
                ExamAssign assign = context.ExamAssigns.SingleOrDefault(p => p.Id == id);
                return(View(assign));
            }
            //    }

            //    else
            //    {
            //        return RedirectToAction("Index", "Exam");
            //    }
            //}
            //else
            //{
            //    return RedirectToAction("Index", "Exam");
            //}
        }
예제 #5
0
        public ActionResult ShowQuestion(int id)
        {
            User CurrentUser = (User)Session["CurrentUser"];

            //if (Session["Userid"] != null)
            //{
            using (TsmsDBContext context = new TsmsDBContext())
            {
                Exam exam = context.Exams.SingleOrDefault(p => p.Id == id);
                if (CurrentUser.level == "admin")
                {
                    Answer ans = context.Answers.SingleOrDefault(p => p.ExamId == id && p.StudentId == CurrentUser.UserId);
                    if (ans == null)
                    {
                        ViewBag.ExamId = id;

                        ViewBag.Total = exam.TotalQues;
                        var      src     = DateTime.Now;
                        string   hour    = src.Hour.ToString();
                        string   min     = src.Minute.ToString();
                        string   end     = exam.FinishTime;
                        char[]   d       = { ' ', ':' };
                        string[] words   = end.Split(d, System.StringSplitOptions.RemoveEmptyEntries);
                        string   endHour = words[0];
                        string   endMin  = words[1];
                        ViewBag.duration  = ((Convert.ToInt32(endHour) * 60 + Convert.ToInt32(endMin)) - (Convert.ToInt32(hour) * 60 + Convert.ToInt32(min))) * 60 * 1000;
                        ViewBag.CountDown = exam.Date + " " + end + ":00";
                        List <Question> questions = context.Questions.Where(p => p.ExamID == id).ToList();
                        return(View(questions));
                    }
                    else
                    {
                        List <Answer> answers = context.Answers.Where(p => p.ExamId == id && p.StudentId == Convert.ToString(Session["Userid"])).ToList();
                        foreach (Answer ansob in answers)
                        {
                            context.Answers.Attach(ansob);
                            context.Answers.Remove(ansob);
                            context.SaveChanges();
                        }
                        ViewBag.ExamId = id;

                        ViewBag.Total = exam.TotalQues;
                        var      src     = DateTime.Now;
                        string   hour    = src.Hour.ToString();
                        string   min     = src.Minute.ToString();
                        string   end     = exam.FinishTime;
                        char[]   d       = { ' ', ':' };
                        string[] words   = end.Split(d, System.StringSplitOptions.RemoveEmptyEntries);
                        string   endHour = words[0];
                        string   endMin  = words[1];
                        ViewBag.duration  = ((Convert.ToInt32(endHour) * 60 + Convert.ToInt32(endMin)) - (Convert.ToInt32(hour) * 60 + Convert.ToInt32(min))) * 60 * 1000;
                        ViewBag.CountDown = exam.Date + " " + end + ":00";
                        List <Question> questions = context.Questions.Where(p => p.ExamID == id).ToList();
                        return(View(questions));
                    }
                }
                else
                {
                    if (exam.ExamState == "open")
                    {
                        ExamAssign assign = context.ExamAssigns.SingleOrDefault(p => p.StudentID == (string)Session["Userid"] && p.Id == id);
                        if (assign != null)
                        {
                            Answer ans = context.Answers.SingleOrDefault(p => p.ExamId == id && p.StudentId == Convert.ToString(Session["Userid"]));
                            if (ans == null)
                            {
                                ViewBag.ExamId = id;

                                ViewBag.Total = exam.TotalQues;
                                var      src     = DateTime.Now;
                                string   hour    = src.Hour.ToString();
                                string   min     = src.Minute.ToString();
                                string   end     = exam.FinishTime;
                                char[]   d       = { ' ', ':' };
                                string[] words   = end.Split(d, System.StringSplitOptions.RemoveEmptyEntries);
                                string   endHour = words[0];
                                string   endMin  = words[1];
                                ViewBag.duration  = ((Convert.ToInt32(endHour) * 60 + Convert.ToInt32(endMin)) - (Convert.ToInt32(hour) * 60 + Convert.ToInt32(min))) * 60 * 1000;
                                ViewBag.CountDown = exam.Date + " " + end + ":00";
                                List <Question> questions = context.Questions.Where(p => p.ExamID == id).ToList();
                                return(View(questions));
                            }
                            else
                            {
                                return(RedirectToAction("Index", "Exam"));
                            }
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Exam"));
                        }
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Exam"));
                    }
                }
            }
            // }
            //else
            //{
            //    return RedirectToAction("Index", "Exam");
            //}
        }