public ActionResult AddQuestion(string id, string Exception)
        {
            ViewBag.CourseList   = new SelectList(_course.GetAll(), "pkid", "CourseName");
            ViewBag.DivisionList = new SelectList(_division.GetAll(), "pkid", "DivisioName");
            ViewBag.Exception    = Exception;
            if (!String.IsNullOrWhiteSpace(id))
            {
                int _id = Convert.ToInt32(id);
                tbl_QuestionMaster model = _question.Get(_id);
                QuestionMaster     abc   = new QuestionMaster();
                abc.pkid             = model.pkid;
                abc.subjecttype_fkid = model.subjecttype_fkid;
                abc.Question         = model.Question;
                abc.Explaination     = model.Explaination;
                abc.Subject_fkid     = Convert.ToInt32(model.Subject_fkid);
                abc.Division_fkid    = model.Division_fkid;
                abc.hint             = model.hint;

                abc.SelectLevel   = model.SelectLevel;
                abc.SelectLevel   = model.SelectLevel;
                abc.NegativeMarks = model.NegativeMarks;
                abc.Marks         = model.Marks;
                abc.Status        = model.Status;
                abc.Adddate       = model.Adddate;

                if (model.subjecttype_fkid == 5)
                {
                    abc.Questtype_fkid = model.subjecttype_fkid;
                    abc.MATContent     = _Matc.GetAll().Where(x => x.Ques_fkid == model.pkid).ToList();
                }
                else if (model.subjecttype_fkid == 7)
                {
                    abc.Questtype_fkid = model.subjecttype_fkid;
                    abc.FULLF          = _Matc.GetAll().Where(x => x.Ques_fkid == model.pkid).ToList();
                }
                else
                {
                    tbl_AnswerMaster ANS = _answer.GetAll().Where(x => x.Ques_fkid == model.pkid).FirstOrDefault();
                    abc.Questtype_fkid  = ANS.Questtype_fkid;
                    abc.Answer1         = ANS.Answer1;
                    abc.Answer2         = ANS.Answer2;
                    abc.Answer3         = ANS.Answer3;
                    abc.Answer4         = ANS.Answer4;
                    abc.CorrectAnswerDD = ANS.CorrectAnswer;
                    abc.BlanckSpace     = ANS.BlanckSpace;
                    abc.TrueFalse       = ANS.TrueFalse;
                    abc.SubAnswer       = ANS.SubAnswer;
                    abc.Status          = ANS.status;
                    abc.Adddate         = ANS.Adddate;
                }
                return(View(abc));
            }
            return(View());
        }
        public ActionResult DeleteQuestion(int id)
        {
            string exception = "";

            try
            {
                tbl_QuestionMaster QUE = _question.Get(id);
                tbl_AnswerMaster   ANS = _answer.GetAll().Where(x => x.Ques_fkid == QUE.pkid).FirstOrDefault();
                _answer.Remove(ANS, true);
                _question.Remove(QUE, true);
                exception = "Deleted Successfully.";
                return(Json(exception, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                Commonfunction.LogError(e, Server.MapPath("~/Log.txt"));
                exception = e.Message;
                return(Json(exception, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult ShowQuestion(int id)
        {
            try
            {
                QuestionMaster     abc = new QuestionMaster();
                tbl_QuestionMaster QUE = _question.Get(id);
                abc.subjecttype_fkid = QUE.subjecttype_fkid;
                abc.Question         = QUE.Question;
                abc.Marks            = QUE.Marks;
                abc.NegativeMarks    = QUE.NegativeMarks;
                if (abc.subjecttype_fkid == 5)
                {
                    abc.MATContent = _Matc.GetAll().Where(x => x.Ques_fkid == id).ToList();
                }
                else if (abc.subjecttype_fkid == 7)
                {
                    abc.FULLF = _Matc.GetAll().Where(x => x.Ques_fkid == id).ToList();
                }
                else
                {
                    tbl_AnswerMaster ANS = _answer.GetAll().Where(x => x.Ques_fkid == QUE.pkid).FirstOrDefault();
                    abc.Answer1         = ANS.Answer1;
                    abc.Answer2         = ANS.Answer2;
                    abc.Answer3         = ANS.Answer3;
                    abc.Answer4         = ANS.Answer4;
                    abc.CorrectAnswerDD = ANS.CorrectAnswer;
                    abc.BlanckSpace     = ANS.BlanckSpace;
                    abc.TrueFalse       = ANS.TrueFalse;
                }

                return(PartialView(abc));
            }
            catch {
                return(PartialView());
            }
        }
        public ActionResult UploadExcel(QuestionMaster model)
        {
            ViewBag.QueTypeList = new SelectList(_subtype.GetAll().Where(x => x.pkid != 4).ToList(), "pkid", "Questiontype");
            ViewBag.CourseList  = new SelectList(_course.GetAll(), "pkid", "CourseName");
            string exception = "";

            try
            {
                WebFunction        comm = new WebFunction();
                HttpPostedFileBase FileUpload = Request.Files[0];
                DataTable          dt = new DataTable();
                string             alert = "", msg = "";

                if (FileUpload != null)
                {
                    dt = comm.GetExcesData(FileUpload);

                    //   List<tbl_MonthlyLibility> monthlyLibalityList = new List<tbl_MonthlyLibility>();
                    int i = 1;
                    foreach (DataRow dr in dt.Rows.Cast <DataRow>().Skip(2))
                    {
                        if (model.Questtype_fkid == 5)
                        {
                            if (FileUpload.FileName == "Match_Content5.xlsx")
                            {
                                tbl_QuestionMaster QUESTION = new tbl_QuestionMaster();


                                var q = dr[1].ToString();
                                var A = dr[2].ToString();
                                QUESTION.subjecttype_fkid = Convert.ToInt32(dr[0]);
                                QUESTION.Question         = dr[1].ToString();
                                QUESTION.Explaination     = dr[2].ToString();
                                QUESTION.Subject_fkid     = Convert.ToInt32(dr[3]);
                                QUESTION.Division_fkid    = Convert.ToInt32(dr[4]);
                                QUESTION.hint             = dr[5].ToString();
                                QUESTION.Marks            = Convert.ToDecimal(dr[6]);
                                try { QUESTION.NegativeMarks = Convert.ToDecimal(dr[7]); }
                                catch { QUESTION.NegativeMarks = 0; }

                                QUESTION.SelectLevel  = Convert.ToInt32(dr[8]);
                                QUESTION.Adddate      = DateTime.Now;
                                QUESTION.Status       = 1;
                                QUESTION.lastModified = DateTime.Now;
                                _question.Add(QUESTION);

                                int _Maxid = _question.GetAll().Max(x => x.pkid);
                                for (int p = 1; p <= 10; p++)
                                {
                                    tbl_MatchContentQuestionMaster ANSWER = new tbl_MatchContentQuestionMaster();
                                    int AA = 0; int BB = 0; int CC = 0;
                                    if (p == 1)
                                    {
                                        AA = 9; BB = 10; CC = 11;
                                    }
                                    else if (p == 2)
                                    {
                                        AA = 12; BB = 13; CC = 14;
                                    }
                                    else if (p == 3)
                                    {
                                        AA = 15; BB = 16; CC = 17;
                                    }
                                    else if (p == 4)
                                    {
                                        AA = 18; BB = 19; CC = 20;
                                    }
                                    else if (p == 5)
                                    {
                                        AA = 21; BB = 22; CC = 23;
                                    }
                                    else if (p == 6)
                                    {
                                        AA = 24; BB = 25; CC = 26;
                                    }
                                    else if (p == 7)
                                    {
                                        AA = 27; BB = 28; CC = 29;
                                    }
                                    else if (p == 8)
                                    {
                                        AA = 30; BB = 31; CC = 32;
                                    }
                                    else if (p == 9)
                                    {
                                        AA = 33; BB = 34; CC = 35;
                                    }
                                    else
                                    {
                                        AA = 36; BB = 37; CC = 38;
                                    }

                                    ANSWER.Ques_fkid       = _Maxid;
                                    ANSWER.FirstColoumn    = dr[AA].ToString();
                                    ANSWER.OppositeColoumn = dr[BB].ToString();
                                    ANSWER.AnsweColoumn    = dr[CC].ToString();
                                    ANSWER.LastDatetime    = DateTime.Now;
                                    if (!string.IsNullOrWhiteSpace(ANSWER.FirstColoumn) && !string.IsNullOrWhiteSpace(ANSWER.OppositeColoumn) && !string.IsNullOrWhiteSpace(ANSWER.AnsweColoumn))
                                    {
                                        _Matc.Add(ANSWER);
                                    }
                                }
                            }
                            else
                            {
                                exception = "Select Correct File.";
                                return(RedirectToAction("UploadExcel", "SubjectGroup", new { Exception = exception }));
                            }
                        }
                        else if (model.Questtype_fkid == 7)
                        {
                            if (FileUpload.FileName == "Full_Form7.xlsx")
                            {
                                tbl_QuestionMaster QUESTION = new tbl_QuestionMaster();

                                var q = dr[1].ToString();
                                var A = dr[2].ToString();
                                QUESTION.subjecttype_fkid = Convert.ToInt32(dr[0]);
                                QUESTION.Question         = dr[1].ToString();
                                QUESTION.Explaination     = dr[2].ToString();
                                QUESTION.Subject_fkid     = Convert.ToInt32(dr[3]);
                                QUESTION.Division_fkid    = Convert.ToInt32(dr[4]);
                                QUESTION.hint             = dr[5].ToString();
                                QUESTION.Marks            = Convert.ToDecimal(dr[6]);
                                try { QUESTION.NegativeMarks = Convert.ToDecimal(dr[7]); }
                                catch { QUESTION.NegativeMarks = 0; }

                                QUESTION.SelectLevel  = Convert.ToInt32(dr[8]);
                                QUESTION.Adddate      = DateTime.Now;
                                QUESTION.Status       = 1;
                                QUESTION.lastModified = DateTime.Now;
                                _question.Add(QUESTION);

                                int _Maxid = _question.GetAll().Max(x => x.pkid);
                                for (int p = 1; p <= 10; p++)
                                {
                                    tbl_MatchContentQuestionMaster ANSWER = new tbl_MatchContentQuestionMaster();
                                    int AA = 0; int CC = 0;
                                    if (p == 1)
                                    {
                                        AA = 9; CC = 10;
                                    }
                                    else if (p == 2)
                                    {
                                        AA = 11; CC = 12;
                                    }
                                    else if (p == 3)
                                    {
                                        AA = 13; CC = 14;
                                    }
                                    else if (p == 4)
                                    {
                                        AA = 15; CC = 16;
                                    }
                                    else if (p == 5)
                                    {
                                        AA = 17; CC = 18;
                                    }
                                    else if (p == 6)
                                    {
                                        AA = 19; CC = 20;
                                    }
                                    else if (p == 7)
                                    {
                                        AA = 21; CC = 22;
                                    }
                                    else if (p == 8)
                                    {
                                        AA = 23; CC = 24;
                                    }
                                    else if (p == 9)
                                    {
                                        AA = 25; CC = 26;
                                    }
                                    else
                                    {
                                        AA = 27; CC = 28;
                                    }


                                    ANSWER.Ques_fkid    = _Maxid;
                                    ANSWER.FirstColoumn = dr[AA].ToString();
                                    ANSWER.AnsweColoumn = dr[CC].ToString();
                                    ANSWER.LastDatetime = DateTime.Now;
                                    if (!string.IsNullOrWhiteSpace(ANSWER.FirstColoumn) && !string.IsNullOrWhiteSpace(ANSWER.AnsweColoumn))
                                    {
                                        _Matc.Add(ANSWER);
                                    }
                                }
                            }
                            else
                            {
                                exception = "Select Correct File.";
                                return(RedirectToAction("UploadExcel", "SubjectGroup", new { Exception = exception }));
                            }
                        }
                        else
                        {
                            if (FileUpload.FileName == "QuestionAnswer.xlsx")
                            {
                                tbl_QuestionMaster QUESTION = new tbl_QuestionMaster();
                                tbl_AnswerMaster   ANSWER   = new tbl_AnswerMaster();

                                var q = dr[1].ToString();
                                var A = dr[2].ToString();
                                QUESTION.subjecttype_fkid = Convert.ToInt32(dr[0]);
                                QUESTION.Question         = dr[1].ToString();
                                QUESTION.Explaination     = dr[2].ToString();
                                QUESTION.Subject_fkid     = Convert.ToInt32(dr[3]);
                                QUESTION.Division_fkid    = Convert.ToInt32(dr[4]);
                                QUESTION.hint             = dr[5].ToString();
                                QUESTION.Marks            = Convert.ToDecimal(dr[6]);
                                try { QUESTION.NegativeMarks = Convert.ToDecimal(dr[7]); }
                                catch { QUESTION.NegativeMarks = 0; }

                                QUESTION.SelectLevel  = Convert.ToInt32(dr[8]);
                                QUESTION.Adddate      = DateTime.Now;
                                QUESTION.Status       = 1;
                                QUESTION.lastModified = DateTime.Now;
                                _question.Add(QUESTION);
                                ANSWER.Ques_fkid      = _question.GetAll().Max(x => x.pkid);
                                ANSWER.Questtype_fkid = Convert.ToInt32(dr[0]);
                                ANSWER.Answer1        = dr[9].ToString();
                                ANSWER.Answer2        = dr[10].ToString();
                                ANSWER.Answer3        = dr[11].ToString();
                                ANSWER.Answer4        = dr[12].ToString();
                                try { ANSWER.CorrectAnswer = Convert.ToInt32(dr[13]); }
                                catch { }

                                ANSWER.BlanckSpace = dr[14].ToString();
                                try { ANSWER.TrueFalse = Convert.ToBoolean(dr[15]); }
                                catch { }
                                ANSWER.Adddate      = DateTime.Now;
                                ANSWER.status       = 1;
                                ANSWER.lastmodified = DateTime.Now;
                                _answer.Add(ANSWER);
                            }
                            else
                            {
                                exception = "Select Correct File.";
                                return(RedirectToAction("UploadExcel", "SubjectGroup", new { Exception = exception }));
                            }
                        }
                    }
                    exception = "All Data Uploaded Successfully";
                }
                else
                {
                    exception = "Please select File.";
                }

                return(RedirectToAction("UploadExcel", "SubjectGroup", new { Exception = exception }));
            }
            catch (Exception e)
            {
                Commonfunction.LogError(e, Server.MapPath("~/Log.txt"));
                exception = e.Message;
                return(RedirectToAction("UploadExcel", "SubjectGroup", new { Exception = exception }));
            }
        }
        public ActionResult AddQuestion(QuestionMaster model)
        {
            WebFunction web       = new WebFunction();
            string      exception = "";

            try
            {
                if (model.pkid == 0)
                {
                    tbl_QuestionMaster abc = new tbl_QuestionMaster();
                    abc.subjecttype_fkid = model.Questtype_fkid;
                    abc.Question         = model.Question;
                    abc.Explaination     = model.Explaination;
                    abc.Subject_fkid     = model.Subject_fkid;
                    abc.Division_fkid    = model.Division_fkid;
                    abc.hint             = model.hint;
                    abc.SelectLevel      = model.SelectLevel;
                    abc.NegativeMarks    = model.NegativeMarks;
                    abc.Marks            = model.Marks;
                    abc.Status           = 1;
                    abc.Adddate          = DateTime.Now;
                    abc.lastModified     = DateTime.Now;
                    _question.Add(abc);
                    int Maxid = _question.GetAll().Max(x => x.pkid);
                    if (model.Questtype_fkid == 5)
                    {
                        foreach (var item in model.MATContent)
                        {
                            if (!string.IsNullOrWhiteSpace(item.FirstColoumn) && !string.IsNullOrWhiteSpace(item.OppositeColoumn) && !string.IsNullOrWhiteSpace(item.AnsweColoumn))
                            {
                                tbl_MatchContentQuestionMaster MA = new tbl_MatchContentQuestionMaster();
                                MA.Ques_fkid       = Maxid;
                                MA.FirstColoumn    = item.FirstColoumn;
                                MA.OppositeColoumn = item.OppositeColoumn;
                                MA.AnsweColoumn    = item.AnsweColoumn;
                                MA.LastDatetime    = DateTime.Now;
                                _Matc.Add(MA);
                            }
                        }
                    }
                    else if (model.Questtype_fkid == 7)
                    {
                        foreach (var item in model.FULLF)
                        {
                            if (!string.IsNullOrWhiteSpace(item.FirstColoumn) && !string.IsNullOrWhiteSpace(item.AnsweColoumn))
                            {
                                tbl_MatchContentQuestionMaster MA = new tbl_MatchContentQuestionMaster();
                                MA.Ques_fkid    = Maxid;
                                MA.FirstColoumn = item.FirstColoumn;
                                MA.AnsweColoumn = item.AnsweColoumn;
                                MA.LastDatetime = DateTime.Now;
                                _Matc.Add(MA);
                            }
                        }
                    }
                    else if (model.Questtype_fkid == 6)
                    {
                        tbl_AnswerMaster ANS = new tbl_AnswerMaster();
                        ANS.Ques_fkid      = _question.GetAll().Max(x => x.pkid);
                        ANS.Questtype_fkid = model.Questtype_fkid;
                        var httpRequest = System.Web.HttpContext.Current.Request;
                        if (httpRequest.Files.Count > 0)
                        {
                            var docfiles = new List <string>();
                            for (int i = 0; i <= httpRequest.Files.Count - 1; i++)
                            {
                                string path       = "";
                                var    postedFile = httpRequest.Files[i];
                                if (i == 0)
                                {
                                    DateTime date  = DateTime.Now;
                                    string   dates = date.Day.ToString() + date.Month.ToString() + date.Year.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + date.ToString("tt");
                                    ANS.Answer1 = "/UploadFiles/QuestionImage/" + dates + postedFile.FileName;
                                    path        = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("/UploadFiles/QuestionImage/"), dates + postedFile.FileName);
                                    postedFile.SaveAs(path);
                                }
                                else if (i == 1)
                                {
                                    DateTime date  = DateTime.Now;
                                    string   dates = date.Day.ToString() + date.Month.ToString() + date.Year.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + date.ToString("tt");
                                    ANS.Answer2 = "/UploadFiles/QuestionImage/" + dates + postedFile.FileName;
                                    path        = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("/UploadFiles/QuestionImage/"), dates + postedFile.FileName);
                                    postedFile.SaveAs(path);
                                }
                                else if (i == 2)
                                {
                                    DateTime date  = DateTime.Now;
                                    string   dates = date.Day.ToString() + date.Month.ToString() + date.Year.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + date.ToString("tt");
                                    ANS.Answer3 = "/UploadFiles/QuestionImage/" + dates + postedFile.FileName;
                                    path        = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("/UploadFiles/QuestionImage/"), dates + postedFile.FileName);
                                    postedFile.SaveAs(path);
                                }
                                else if (i == 3)
                                {
                                    DateTime date  = DateTime.Now;
                                    string   dates = date.Day.ToString() + date.Month.ToString() + date.Year.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + date.ToString("tt");
                                    ANS.Answer4 = "/UploadFiles/QuestionImage/" + dates + postedFile.FileName;
                                    path        = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("/UploadFiles/QuestionImage/"), dates + postedFile.FileName);
                                    postedFile.SaveAs(path);
                                }
                            }
                        }
                        ANS.CorrectAnswer = model.CorrectAnswerDD;
                        ANS.BlanckSpace   = model.BlanckSpace;
                        ANS.TrueFalse     = model.TrueFalse;
                        ANS.SubAnswer     = model.SubAnswer;
                        ANS.status        = 1;
                        ANS.Adddate       = DateTime.Now;
                        ANS.lastmodified  = DateTime.Now;
                        _answer.Add(ANS);
                        exception = "Save Successfully";
                    }
                    else
                    {
                        tbl_AnswerMaster ANS = new tbl_AnswerMaster();
                        ANS.Ques_fkid      = _question.GetAll().Max(x => x.pkid);
                        ANS.Questtype_fkid = model.Questtype_fkid;
                        ANS.Answer1        = model.Answer1;
                        ANS.Answer2        = model.Answer2;
                        ANS.Answer3        = model.Answer3;
                        ANS.Answer4        = model.Answer4;
                        ANS.CorrectAnswer  = model.CorrectAnswerDD;
                        ANS.BlanckSpace    = model.BlanckSpace;
                        ANS.TrueFalse      = model.TrueFalse;
                        ANS.SubAnswer      = model.SubAnswer;
                        ANS.status         = 1;
                        ANS.Adddate        = DateTime.Now;
                        ANS.lastmodified   = DateTime.Now;
                        _answer.Add(ANS);
                        exception = "Save Successfully";
                    }
                }
                else
                {
                    int _id = Convert.ToInt32(model.pkid);
                    tbl_QuestionMaster abc = _question.Get(_id);
                    abc.subjecttype_fkid = model.Questtype_fkid;
                    abc.Division_fkid    = model.Division_fkid;
                    abc.Question         = model.Question;
                    abc.Explaination     = model.Explaination;
                    abc.Subject_fkid     = model.Subject_fkid;
                    abc.Division_fkid    = model.Division_fkid;
                    abc.hint             = model.hint;
                    abc.SelectLevel      = model.SelectLevel;
                    abc.SelectLevel      = model.SelectLevel;
                    abc.NegativeMarks    = model.NegativeMarks;
                    abc.Marks            = model.Marks;
                    abc.Status           = model.Status;
                    abc.Adddate          = model.Adddate;
                    abc.lastModified     = DateTime.Now;
                    _question.Update(abc);

                    if (model.Questtype_fkid == 5)
                    {
                        foreach (var item in model.MATContent)
                        {
                            if (!string.IsNullOrWhiteSpace(item.FirstColoumn) && !string.IsNullOrWhiteSpace(item.OppositeColoumn) && !string.IsNullOrWhiteSpace(item.AnsweColoumn))
                            {
                                tbl_MatchContentQuestionMaster MA = _Matc.Get(item.pkid);
                                MA.FirstColoumn    = item.FirstColoumn;
                                MA.OppositeColoumn = item.OppositeColoumn;
                                MA.AnsweColoumn    = item.AnsweColoumn;
                                MA.LastDatetime    = DateTime.Now;
                                _Matc.Update(MA);
                            }
                        }
                    }
                    else if (model.Questtype_fkid == 7)
                    {
                        foreach (var item in model.FULLF)
                        {
                            if (!string.IsNullOrWhiteSpace(item.FirstColoumn) && !string.IsNullOrWhiteSpace(item.AnsweColoumn))
                            {
                                tbl_MatchContentQuestionMaster MA = _Matc.Get(item.pkid);
                                MA.FirstColoumn = item.FirstColoumn;
                                MA.AnsweColoumn = item.AnsweColoumn;
                                MA.LastDatetime = DateTime.Now;
                                _Matc.Update(MA);
                            }
                        }
                    }
                    else if (model.Questtype_fkid == 6)
                    {
                        tbl_AnswerMaster ANS = _answer.GetAll().Where(x => x.Ques_fkid == _id).FirstOrDefault();
                        ANS.Ques_fkid      = _id;
                        ANS.Questtype_fkid = model.Questtype_fkid;
                        var httpRequest = System.Web.HttpContext.Current.Request;
                        if (httpRequest.Files.Count > 0)
                        {
                            var docfiles = new List <string>();
                            for (int i = 0; i <= httpRequest.Files.Count - 1; i++)
                            {
                                string path       = "";
                                var    postedFile = httpRequest.Files[i];
                                if (i == 0)
                                {
                                    if (System.IO.File.Exists(ANS.Answer1))
                                    {
                                        System.IO.File.Delete(ANS.Answer1);
                                    }
                                    DateTime date  = DateTime.Now;
                                    string   dates = date.Day.ToString() + date.Month.ToString() + date.Year.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + date.ToString("tt");
                                    ANS.Answer1 = "/UploadFiles/QuestionImage/" + dates + postedFile.FileName;
                                    path        = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("/UploadFiles/QuestionImage/"), dates + postedFile.FileName);
                                    postedFile.SaveAs(path);
                                }
                                else if (i == 1)
                                {
                                    if (System.IO.File.Exists(ANS.Answer2))
                                    {
                                        System.IO.File.Delete(ANS.Answer2);
                                    }
                                    DateTime date  = DateTime.Now;
                                    string   dates = date.Day.ToString() + date.Month.ToString() + date.Year.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + date.ToString("tt");
                                    ANS.Answer2 = "/UploadFiles/QuestionImage/" + dates + postedFile.FileName;
                                    path        = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("/UploadFiles/QuestionImage/"), dates + postedFile.FileName);
                                    postedFile.SaveAs(path);
                                }
                                else if (i == 2)
                                {
                                    if (System.IO.File.Exists(ANS.Answer3))
                                    {
                                        System.IO.File.Delete(ANS.Answer3);
                                    }
                                    DateTime date  = DateTime.Now;
                                    string   dates = date.Day.ToString() + date.Month.ToString() + date.Year.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + date.ToString("tt");
                                    ANS.Answer3 = "/UploadFiles/QuestionImage/" + dates + postedFile.FileName;
                                    path        = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("/UploadFiles/QuestionImage/"), dates + postedFile.FileName);
                                    postedFile.SaveAs(path);
                                }
                                else if (i == 3)
                                {
                                    if (System.IO.File.Exists(ANS.Answer4))
                                    {
                                        System.IO.File.Delete(ANS.Answer4);
                                    }
                                    DateTime date  = DateTime.Now;
                                    string   dates = date.Day.ToString() + date.Month.ToString() + date.Year.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + date.ToString("tt");
                                    ANS.Answer4 = "/UploadFiles/QuestionImage/" + dates + postedFile.FileName;
                                    path        = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("/UploadFiles/QuestionImage/"), dates + postedFile.FileName);
                                    postedFile.SaveAs(path);
                                }
                            }
                        }
                        ANS.CorrectAnswer = model.CorrectAnswerDD;
                        ANS.BlanckSpace   = model.BlanckSpace;
                        ANS.TrueFalse     = model.TrueFalse;
                        ANS.SubAnswer     = model.SubAnswer;
                        ANS.status        = 1;
                        ANS.Adddate       = DateTime.Now;
                        ANS.lastmodified  = DateTime.Now;
                        _answer.Update(ANS);
                        exception = "Save Successfully";
                    }
                    else
                    {
                        tbl_AnswerMaster ANS = _answer.GetAll().Where(x => x.Ques_fkid == model.pkid).FirstOrDefault();
                        ANS.Questtype_fkid = model.Questtype_fkid;
                        ANS.Answer1        = model.Answer1;
                        ANS.Answer2        = model.Answer2;
                        ANS.Answer3        = model.Answer3;
                        ANS.Answer4        = model.Answer4;
                        ANS.CorrectAnswer  = model.CorrectAnswerDD;
                        ANS.BlanckSpace    = model.BlanckSpace;
                        ANS.TrueFalse      = model.TrueFalse;
                        ANS.SubAnswer      = model.SubAnswer;
                        ANS.status         = 1;
                        ANS.Adddate        = DateTime.Now;
                        ANS.lastmodified   = DateTime.Now;
                        _answer.Update(ANS);
                    }
                    exception = "Updated Successfully";
                }
                return(RedirectToAction("AddQuestion", "SubjectGroup", new { Exception = exception }));
            }
            catch (Exception e)
            {
                Commonfunction.LogError(e, Server.MapPath("~/Log.txt"));
                exception = e.Message;
                return(RedirectToAction("AddQuestion", "SubjectGroup", new { Exception = exception }));
            }
        }