public ActionResult PreviewResult(String ResultId)
        {
            String Tid             = ((Teacher)Session["CurrentUser"]).Id;
            Int32  AutherizeAccess = (Int32)DataAccess.Reader("select Count(R.Result_Id) from Result as R Join Exam as E on E.Exam_Id = R.Exam_Id Join Courses as C on C.Course_Id = E.Course_Id where C.Teacher_Id = '" + Tid + "' and R.Result_Id = " + ResultId + "", false, false);

            if (AutherizeAccess > 0)
            {
                DataTable dtexam = DataAccess.daobj("select E.* from Result as R Join Exam as E on E.Exam_Id = R.Exam_Id where R.Result_Id = " + ResultId, false);
                Exam      exam   = new Exam();
                if (dtexam.Rows.Count > 0)
                {
                    exam.Exam_Id       = (int)dtexam.Rows[0]["Exam_Id"];
                    exam.Course_Id     = (int)dtexam.Rows[0]["Course_Id"];
                    exam.Exam_Name     = dtexam.Rows[0]["Exam_Name"].ToString();
                    exam.Exam_Date     = (DateTime)dtexam.Rows[0]["Exam_Date"];
                    exam.Start_Time    = exam.Exam_Date.Date.Add((TimeSpan)dtexam.Rows[0]["Start_Time"]);
                    exam.End_Time      = exam.Exam_Date.Date.Add((TimeSpan)dtexam.Rows[0]["End_Time"]);
                    exam.Total_Marks   = (Double)dtexam.Rows[0]["Total_Marks"];
                    exam.Passing_Marks = (Double)dtexam.Rows[0]["Passing_Marks"];
                    exam.Duration      = TimeSpan.FromMinutes(Int32.Parse(dtexam.Rows[0]["Duration"].ToString()));
                    exam.AutoSubmit    = (Boolean)dtexam.Rows[0]["AutoSubmit"];
                    exam.Temp          = ResultId;
                    DataTable dtparts = DataAccess.daobj("select * from Section where Exam_Id = " + exam.Exam_Id.ToString() + " order by Section_Order Asc");
                    if (dtparts.Rows.Count > 0)
                    {
                        exam.Sections = new Section[dtparts.Rows.Count];
                        for (int i = 0; i < dtparts.Rows.Count; i++)
                        {
                            Section section = new Section();
                            section.Section_Id    = (int)dtparts.Rows[i]["Section_Id"];
                            section.Exam_Id       = (int)dtparts.Rows[i]["Exam_Id"];
                            section.Section_Text  = dtparts.Rows[i]["Section_Text"].ToString();
                            section.Section_Marks = (double)dtparts.Rows[i]["Section_Marks"];
                            section.Section_Order = (int)dtparts.Rows[i]["Section_Order"];
                            exam.Sections[i]      = section;

                            DataTable dtquestion = DataAccess.daobj("select Q.* , A.* from Question  as Q Join Answer as A on Q.Question_Id = A.Question_Id Join Section as S on S.Section_Id = Q.Section_Id Join Exam as E on E.Exam_Id = S.Exam_Id  Join Result as R on R.Exam_Id = E.Exam_Id  where R.Result_Id = " + ResultId + " and S.Section_Id  = " + section.Section_Id + " Order by Q.Question_Order Asc");

                            if (dtquestion.Rows.Count > 0)
                            {
                                exam.Sections[i].Questions = new Question[dtquestion.Rows.Count];
                                for (int j = 0; j < dtquestion.Rows.Count; j++)
                                {
                                    Question question = new Question();
                                    question.Question_Id = (int)dtquestion.Rows[j]["Question_Id"];
                                    if (dtquestion.Rows[j]["Question_Type"].ToString().Equals("FB"))
                                    {
                                        question.QuestionText = StudentController.ConvertintoFB(dtquestion.Rows[j]["Question"].ToString());
                                    }
                                    else
                                    {
                                        question.QuestionText = dtquestion.Rows[j]["Question"].ToString();
                                    }
                                    question.Type                 = dtquestion.Rows[j]["Question_Type"].ToString();
                                    question.Question_Marks       = (double)dtquestion.Rows[j]["Question_Marks"];
                                    question.Question_Order       = (int)dtquestion.Rows[j]["Question_Order"];
                                    question.Sample_Answer        = (String)dtquestion.Rows[j]["Answer"];
                                    question.Obtained_Marks       = (double)dtquestion.Rows[j]["Obtain_Marks"];
                                    exam.Sections[i].Questions[j] = question;

                                    if (question.Type.Equals("MCQ"))
                                    {
                                        DataTable dtchoices = DataAccess.daobj("select * from Choice where Question_Id = " + question.Question_Id.ToString() + " order by Choice_Id Asc");
                                        if (dtchoices.Rows.Count > 0)
                                        {
                                            exam.Sections[i].Questions[j].Options = new String[dtchoices.Rows.Count];
                                            for (int k = 0; k < dtchoices.Rows.Count; k++)
                                            {
                                                String Choice = dtchoices.Rows[k]["Choice"].ToString();
                                                exam.Sections[i].Questions[j].Options[k] = Choice;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    return(View(exam));
                }
                else
                {
                    ViewBag.ErrorHeading = "Invalid Exam Access";
                    return(View("~/Views/Shared/Error.cshtml"));
                }
            }
            else
            {
                ViewBag.ErrorHeading = "Invalid Result Access";
                return(View("~/Views/Shared/Error.cshtml"));
            }
        }
        public ActionResult PreviewExam(String ExamId, String Type = "Solved")
        {
            String    Tid    = ((Teacher)Session["CurrentUser"]).Id;
            DataTable dtexam = DataAccess.daobj("select E.* from Exam as E Join Courses as C on E.Course_Id = C.Course_Id where C.Teacher_Id = '" + Tid + "' and E.Exam_Id = " + ExamId, false);
            Exam      exam   = new Exam();

            if (dtexam.Rows.Count > 0)
            {
                exam.Exam_Id       = (int)dtexam.Rows[0]["Exam_Id"];
                exam.Course_Id     = (int)dtexam.Rows[0]["Course_Id"];
                exam.Exam_Name     = dtexam.Rows[0]["Exam_Name"].ToString();
                exam.Exam_Date     = (DateTime)dtexam.Rows[0]["Exam_Date"];
                exam.Start_Time    = exam.Exam_Date.Date.Add((TimeSpan)dtexam.Rows[0]["Start_Time"]);
                exam.End_Time      = exam.Exam_Date.Date.Add((TimeSpan)dtexam.Rows[0]["End_Time"]);
                exam.Total_Marks   = (Double)dtexam.Rows[0]["Total_Marks"];
                exam.Passing_Marks = (Double)dtexam.Rows[0]["Passing_Marks"];
                exam.Duration      = TimeSpan.FromMinutes(Int32.Parse(dtexam.Rows[0]["Duration"].ToString()));
                exam.AutoSubmit    = (Boolean)dtexam.Rows[0]["AutoSubmit"];
                DataTable dtparts = DataAccess.daobj("select * from Section where Exam_Id = " + ExamId + " order by Section_Order Asc");
                if (dtparts.Rows.Count > 0)
                {
                    exam.Sections = new Section[dtparts.Rows.Count];
                    for (int i = 0; i < dtparts.Rows.Count; i++)
                    {
                        Section section = new Section();
                        section.Section_Id    = (int)dtparts.Rows[i]["Section_Id"];
                        section.Exam_Id       = (int)dtparts.Rows[i]["Exam_Id"];
                        section.Section_Text  = dtparts.Rows[i]["Section_Text"].ToString();
                        section.Section_Marks = (double)dtparts.Rows[i]["Section_Marks"];
                        section.Section_Order = (int)dtparts.Rows[i]["Section_Order"];
                        exam.Sections[i]      = section;

                        DataTable dtquestion = DataAccess.daobj("select *  from Question where Section_Id = " + section.Section_Id.ToString() + " order by Question_Order Asc");

                        if (dtquestion.Rows.Count > 0)
                        {
                            exam.Sections[i].Questions = new Question[dtquestion.Rows.Count];
                            for (int j = 0; j < dtquestion.Rows.Count; j++)
                            {
                                Question question = new Question();
                                question.Question_Id = (int)dtquestion.Rows[j]["Question_Id"];
                                if (dtquestion.Rows[j]["Question_Type"].ToString().Equals("FB"))
                                {
                                    question.QuestionText = StudentController.ConvertintoFB(dtquestion.Rows[j]["Question"].ToString());
                                }
                                else
                                {
                                    question.QuestionText = dtquestion.Rows[j]["Question"].ToString();
                                }
                                question.Type           = dtquestion.Rows[j]["Question_Type"].ToString();
                                question.Question_Marks = (double)dtquestion.Rows[j]["Question_Marks"];
                                question.Question_Order = (int)dtquestion.Rows[j]["Question_Order"];
                                if (Type.Equals("Solved"))
                                {
                                    question.Sample_Answer = (String)dtquestion.Rows[j]["Sample_Answer"];
                                }
                                else
                                {
                                    question.Sample_Answer = "";
                                }
                                exam.Sections[i].Questions[j] = question;

                                if (question.Type.Equals("MCQ"))
                                {
                                    DataTable dtchoices = DataAccess.daobj("select * from Choice where Question_Id = " + question.Question_Id.ToString() + " order by Choice_Id Asc");
                                    if (dtchoices.Rows.Count > 0)
                                    {
                                        exam.Sections[i].Questions[j].Options = new String[dtchoices.Rows.Count];
                                        for (int k = 0; k < dtchoices.Rows.Count; k++)
                                        {
                                            String Choice = dtchoices.Rows[k]["Choice"].ToString();
                                            exam.Sections[i].Questions[j].Options[k] = Choice;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return(View(exam));
            }
            else
            {
                ViewBag.ErrorHeading = "Invalid Exam Access";
                return(View("~/Views/Shared/Error.cshtml"));
            }
        }