public ActionResult UserArea()
        {
            scoreDetails obj = new scoreDetails();

            using (mocktestEntities1 selectStatement = new mocktestEntities1())
            {
                var userList = selectStatement.QuesDetails.Join(selectStatement.ScoreDetails, ques => ques.QuesDetailId, score => score.QuesDetailId, (ques, score) => new { ques, score }).Join(selectStatement.SubTopics, a => a.ques.SubTopicId, sub => sub.SubTopicId, (a, sub) => new { a, sub }).Join(selectStatement.Topics, b => b.sub.TopicId, top => top.TopicId, (b, top) => new { b, top }).Join(selectStatement.users, c => c.b.a.score.UserId, us => us.UserId, (c, us) => new { c, us }).Where(a => a.c.b.a.ques.Active == true).ToList();
                obj.scoreGrid = userList.Select(c => new GetScore
                {
                    today          = c.c.b.a.score.date,
                    user           = c.us.Name,
                    RollNo         = c.us.RollNo,
                    Branch         = c.us.Branch,
                    topicname      = c.c.top.Name,
                    subname        = c.c.b.sub.Name,
                    score          = Convert.ToInt32(c.c.b.a.score.Score),
                    Attempted      = c.c.b.a.score.Attempted,
                    correctAnswers = c.c.b.a.score.Corrected,
                    totalTime      = c.c.b.a.score.Duration,
                }).ToList();
                obj.scoreGrid = obj.scoreGrid.Reverse();
                //interval = interval + 20;

                return(Json(obj.scoreGrid, JsonRequestBehavior.AllowGet));
            }
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            mocktestEntities1 db = new mocktestEntities1();
            user        newUser  = new user();
            List <user> userList = new List <user>();
            int         count    = 0;

            userList = db.users.ToList();
            if (value != null)
            {
                string email = value.ToString();
                if (userList.Count > 0)
                {
                    foreach (var item in userList)
                    {
                        if (item.EmailId.Equals(email))
                        {
                            count++;
                        }
                    }
                }
                if (count != 0)
                {
                    return(new ValidationResult(ErrorMessage));
                }
                else
                {
                    return(ValidationResult.Success);
                }
            }
            else
            {
                return(ValidationResult.Success);
            }
        }
        // GET: RemoteValidation
        public ActionResult CheckExistingEmail(String EmailId)
        {
            mocktestEntities1 db     = new mocktestEntities1();
            user        newUser      = new user();
            bool        IfEmailExist = false;
            List <user> userList     = new List <user>();
            int         count        = 0;

            userList = db.users.ToList();
            try
            {
                if (userList.Count > 0)
                {
                    foreach (var item in userList)
                    {
                        if (item.EmailId.Equals(EmailId))
                        {
                            count++;
                        }
                    }
                }
                if (count != 0)
                {
                    IfEmailExist = true;
                }
                return(Json(!IfEmailExist, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult CheckExistingQuestion([Bind(Prefix = "question.Question")] string Question)
        {
            mocktestEntities1 db       = new mocktestEntities1();
            bool IfquestionExist       = false;
            int  count                 = 0;
            List <QuesDetail> quesList = new List <QuesDetail>();

            quesList = db.QuesDetails.Where(a => a.Question == Question & a.Active == true).ToList();
            try
            {
                if (quesList.Count > 0)
                {
                    count++;
                }


                if (count != 0)
                {
                    IfquestionExist = true;
                }
                return(Json(!IfquestionExist, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Edit(createOption option)
        {
            OptionDetail Op   = new OptionDetail();
            QuesDetail   ques = new QuesDetail();

            using (var ctx = new mocktestEntities1())
            {
                ctx.Configuration.LazyLoadingEnabled = false;
                Op   = ctx.OptionDetails.Where(s => s.QuesDetailId == option.Qid).FirstOrDefault <OptionDetail>();
                ques = ctx.QuesDetails.Where(a => a.QuesDetailId == option.Qid).FirstOrDefault <QuesDetail>();
            }
            ques.Question  = option.question.EditQuestion;
            ques.OpCorrect = option.question.optionCorrect;
            Op.OpOne       = option.optionOne;
            Op.OpTwo       = option.optionTwo;
            Op.OpThree     = option.optionThree;
            Op.OpFour      = option.optionFour;

            using (mocktestEntities1 selectStatement = new mocktestEntities1())
            {
                selectStatement.Entry(ques).State = System.Data.Entity.EntityState.Modified;
                selectStatement.Entry(Op).State   = System.Data.Entity.EntityState.Modified;
                selectStatement.SaveChanges();
            }
            return(Json(JsonRequestBehavior.AllowGet));
        }
        public JsonResult Delete(int Qid)
        {
            bool         result = false;
            QuesDetail   Active1;
            OptionDetail Active2;

            using (mocktestEntities1 db = new mocktestEntities1())
            {
                Active1 = db.QuesDetails.Where(a => a.QuesDetailId == Qid).FirstOrDefault <QuesDetail>();
                Active2 = db.OptionDetails.Where(a => a.QuesDetailId == Qid).FirstOrDefault <OptionDetail>();
            }
            if (Active1 != null && Active2 != null)
            {
                Active1.Active = false;
                Active2.Active = false;
            }
            using (mocktestEntities1 db2 = new mocktestEntities1())
            {
                db2.Entry(Active1).State = System.Data.Entity.EntityState.Modified;
                db2.Entry(Active2).State = System.Data.Entity.EntityState.Modified;
                db2.SaveChanges();
                result = true;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public IEnumerable <SubTopic> getSub()
        {
            mocktestEntities1 db      = new mocktestEntities1();
            List <SubTopic>   subName = new List <SubTopic>();

            subName = db.SubTopics.ToList();
            return(subName);
        }
        public JsonResult GetQuestions(Int32 subId, int?Page)
        {
            createOption      obj          = new createOption();
            List <QuesDetail> QuestionName = new List <QuesDetail>();
            //List<OptionDetail> OptionName = new List<OptionDetail>();
            Int32 subiD      = subId;
            int   pageSize   = 8;
            bool  Active     = true;
            int   pageNumber = (Page ?? 1);

            if (Session["RoleId"] != null)
            {
                using (mocktestEntities1 selectStatement = new mocktestEntities1())
                {
                    var quesdetail = selectStatement.QuesDetails.Join(selectStatement.OptionDetails, a => a.QuesDetailId, b => b.QuesDetailId, (a, b) => new { a, b })
                                     .Join(selectStatement.SubTopics, a => a.a.SubTopicId, b => b.SubTopicId, (a, b) => new { a, b }).Where(a => a.a.a.SubTopicId == subId & a.a.a.Active == Active).ToList();
                    obj.QuestionGrid = quesdetail.Select(c => new ShowQuiz
                    {
                        Qid          = c.a.a.QuesDetailId,
                        OpId         = c.a.b.OptionDetailsId,
                        QuestionName = c.a.a.Question.ToString(),
                        OpOne        = c.a.b.OpOne.ToString(),
                        OpTwo        = c.a.b.OpTwo.ToString(),
                        OpThree      = c.a.b.OpThree.ToString(),
                        OpFour       = c.a.b.OpFour.ToString(),
                        Correct      = c.a.a.OpCorrect.ToString()
                    }).ToList();
                    return(Json(obj.QuestionGrid, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                using (mocktestEntities1 selectStatement = new mocktestEntities1())
                {
                    if (TempData["SubId"] != null)
                    {
                        subId = Convert.ToInt32(TempData["SubId"]);
                    }
                    var quesdetail = selectStatement.QuesDetails.Join(selectStatement.OptionDetails, a => a.QuesDetailId, b => b.QuesDetailId, (a, b) => new { a, b })
                                     .Join(selectStatement.SubTopics, a => a.a.SubTopicId, b => b.SubTopicId, (a, b) => new { a, b }).Where(a => a.a.a.SubTopicId == subId & a.a.a.Active == Active).OrderBy(r => Guid.NewGuid()).Take(20).ToList();
                    obj.QuestionGrid = quesdetail.Select(c => new ShowQuiz
                    {
                        Qid          = c.a.a.QuesDetailId,
                        OpId         = c.a.b.OptionDetailsId,
                        QuestionName = c.a.a.Question.ToString(),
                        OpOne        = c.a.b.OpOne.ToString(),
                        OpTwo        = c.a.b.OpTwo.ToString(),
                        OpThree      = c.a.b.OpThree.ToString(),
                        OpFour       = c.a.b.OpFour.ToString(),
                        Correct      = c.a.a.OpCorrect.ToString()
                    }).ToList();
                    return(Json(obj.QuestionGrid, JsonRequestBehavior.AllowGet));
                }
            }
        }
        public List <OptionDetail> getOption(int QuesId)
        {
            int quesiD = Convert.ToInt32(QuesId);

            using (mocktestEntities1 selectStatement = new mocktestEntities1())
            {
                List <OptionDetail> OptionName = new List <OptionDetail>();
                OptionName = (selectStatement.OptionDetails.Where(x => x.QuesDetailId == QuesId)).ToList();
                return(OptionName);
            }
        }
        public ActionResult EditSub(Int32 SubEditId)
        {
            string   resultName;
            SubTopic Name;

            using (mocktestEntities1 db = new mocktestEntities1())
            {
                Name       = db.SubTopics.Where(a => a.SubTopicId == SubEditId).FirstOrDefault <SubTopic>();
                resultName = Name.Name;
                return(Json(resultName, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult CreateQuiz(createOption ques)
        {
            mocktestEntities1 db = new mocktestEntities1();

            List <Topic>      topicName = new List <Topic>();
            List <SubTopic>   subName   = new List <SubTopic>();
            List <QuesDetail> questList = new List <QuesDetail>();
            bool Active = true;

            QuesDetail   newQuestion = new QuesDetail();
            OptionDetail newOption   = new OptionDetail();
            int          quesId      = 0;

            topicName = db.Topics.ToList();
            subName   = db.SubTopics.ToList();
            if (QuestionIsVaild(ques.question.Question, ques.SubId))
            {
                Int32 Id = ques.SubId;
                newQuestion.SubTopicId = Id;
                string Queval  = ques.question.Question.Replace("&lt", "<");
                string Queval1 = Queval.Replace("&gt", ">");
                newQuestion.Question  = Queval1;
                newQuestion.OpCorrect = ques.question.optionCorrect;
                newQuestion.Active    = Active;

                newOption.OpOne   = ques.optionOne;
                newOption.OpTwo   = ques.optionTwo;
                newOption.OpThree = ques.optionThree;
                newOption.OpFour  = ques.optionFour;
                db.QuesDetails.Add(newQuestion);

                db.SaveChanges();
                var QSTID = newQuestion.QuesDetailId;

                //using (mocktestEntities1 select = new mocktestEntities1())
                //{
                //    var quid = select.QuesDetails.Where(a => a.Question == Queval1 & a.Active == true).FirstOrDefault();
                //    quesId = quid.QuesDetailId;
                //}
                newOption.QuesDetailId = QSTID;
                newOption.Active       = Active;
                db.OptionDetails.Add(newOption);
                db.SaveChanges();

                //return View();
                return(Json(new { result = 0, message = "Success" }));
            }
            //TempData["alertMessage"] = "Question Already Exist!";
            //return View();
            return(Json(new { result = 1, message = "Question Already Exist!" }));
        }
        public ActionResult ChangePassword(SignUp sgnp)
        {
            user   current = new user();
            string emId    = Session["EmailId"].ToString();

            using (var ctx = new mocktestEntities1())
            {
                current = ctx.users.Where(a => a.EmailId == emId).FirstOrDefault <user>();
            }
            current.Password = sgnp.Password;
            using (mocktestEntities1 db = new mocktestEntities1())
            {
                db.Entry(current).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            return(PartialView());
        }
 public ActionResult Profile()
 {
     using (mocktestEntities1 db = new mocktestEntities1())
     {
         user   result = new user();
         SignUp sgn    = new SignUp();
         if (Session["EmailId"] != null)
         {
             string EmailId = Session["EmailId"].ToString();
             result       = db.users.Where(a => a.EmailId == EmailId).FirstOrDefault <user>();
             sgn.EmailId  = result.EmailId;
             sgn.Name     = result.Name;
             sgn.Password = result.Password;
         }
         return(Json(sgn, JsonRequestBehavior.AllowGet));
     }
 }
        public bool QuestionIsVaild(string name, Int32 SubID)
        {
            List <QuesDetail> quesname = new List <QuesDetail>();

            using (mocktestEntities1 mk = new mocktestEntities1())
            {
                quesname = mk.QuesDetails.Where(x => x.Question == name & x.Active == true & x.SubTopicId == SubID).ToList();
                if (quesname.Count > 0)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
        public ActionResult CheckExistingSubTopic(string SubTopicName, Int32 TopId)
        {
            bool IfTopicExist = false;

            using (mocktestEntities1 mock = new mocktestEntities1())
            {
                var validtopic = mock.SubTopics.Where(a => a.Name == SubTopicName & a.TopicId == TopId).ToList();
                if (validtopic.Count != 0)
                {
                    IfTopicExist = true;
                }
                else
                {
                    IfTopicExist = false;
                }
                return(Json(!IfTopicExist, JsonRequestBehavior.AllowGet));
            }
        }
        public IEnumerable <Topic> getTopic()
        {
            mocktestEntities1 db        = new mocktestEntities1();
            List <Topic>      topicName = new List <Topic>();

            if (Session["RoleId"] != null)
            {
                topicName = db.Topics.Where(x => x.Active == true).ToList();
                return(topicName);
            }
            else
            {
                using (mocktestEntities1 mkt = new mocktestEntities1())
                {
                    topicName = (from t in mkt.Topics join s in mkt.SubTopics on t.TopicId equals s.TopicId join q in mkt.QuesDetails on s.SubTopicId equals q.SubTopicId where q.QuesDetailId != 0 & t.Active == true select t).Distinct().ToList();
                    return(topicName);
                }
            }
        }
        public ActionResult DeleteSub(Int32 SubDelId)
        {
            SubTopic Active;
            bool     result = false;

            using (mocktestEntities1 db = new mocktestEntities1())
            {
                Active = db.SubTopics.Where(a => a.SubTopicId == SubDelId).FirstOrDefault <SubTopic>();
            }
            if (Active != null)
            {
                Active.Active = false;
            }
            using (mocktestEntities1 db2 = new mocktestEntities1())
            {
                db2.Entry(Active).State = System.Data.Entity.EntityState.Modified;
                db2.SaveChanges();
                result = true;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult EditConfSub(Int32 SubEditId, string SubName)
        {
            bool     result = false;
            SubTopic Name;

            using (mocktestEntities1 db = new mocktestEntities1())
            {
                Name = db.SubTopics.Where(a => a.SubTopicId == SubEditId).FirstOrDefault <SubTopic>();
            }
            if (Name != null)
            {
                Name.Name = SubName;
            }
            using (mocktestEntities1 db2 = new mocktestEntities1())
            {
                db2.Entry(Name).State = System.Data.Entity.EntityState.Modified;
                db2.SaveChanges();
                result = true;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(int QId)
        {
            createOption objcreateOption = new createOption();


            using (mocktestEntities1 db = new mocktestEntities1())
            {
                var option = db.OptionDetails.FirstOrDefault(a => a.QuesDetailId == QId);
                if (option != null)
                {
                    objcreateOption.question.EditQuestion  = option.QuesDetail.Question;
                    objcreateOption.question.optionCorrect = option.QuesDetail.OpCorrect;
                    objcreateOption.optionOne   = option.OpOne;
                    objcreateOption.optionTwo   = option.OpTwo;
                    objcreateOption.optionThree = option.OpThree;
                    objcreateOption.optionFour  = option.OpFour;
                    objcreateOption.Qid         = QId;
                }
            }
            return(Json(objcreateOption, JsonRequestBehavior.AllowGet));
        }
        public ActionResult GetsubList(int TopicId)
        {
            if (Session["EmailId"] == null)
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            createOption         obj        = new createOption();
            List <SubTopic>      SubName    = new List <SubTopic>();

            List <string> subList = new List <string>();
            int           topiciD = Convert.ToInt32(TopicId);

            if (Session["RoleId"] != null)
            {
                using (mocktestEntities1 selectStatement = new mocktestEntities1())
                {
                    SubName     = (selectStatement.SubTopics.Where(x => x.TopicId == topiciD & x.Active == true)).ToList();
                    obj.SubList = SubName.Select(a => new SelectListItem
                    {
                        Value = a.SubTopicId.ToString(),
                        Text  = a.Name
                    }).ToList();
                    return(Json(obj.SubList, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                using (mocktestEntities1 mkt = new mocktestEntities1())
                {
                    SubName     = (from t in mkt.Topics join s in mkt.SubTopics on t.TopicId equals s.TopicId join q in mkt.QuesDetails on s.SubTopicId equals q.SubTopicId where (from r in mkt.QuesDetails where r.SubTopicId == q.SubTopicId select r).Count() > 19 & t.TopicId == topiciD & s.Active == true select s).Distinct().ToList();
                    obj.SubList = SubName.Select(a => new SelectListItem
                    {
                        Value = a.SubTopicId.ToString(),
                        Text  = a.Name
                    }).ToList();
                    return(Json(obj.SubList, JsonRequestBehavior.AllowGet));
                }
            }
        }
        public ActionResult login(Login log)
        {
            mocktestEntities1 db = new mocktestEntities1();
            //List<user> userList = new List<user>();
            //userList = db.users.ToList();

            //foreach (var item in userList)
            //{
            //    var i = item.roleId;
            //}
            var userDetail = db.users.Where(x => x.EmailId == log.EmailId && x.Password == log.Password).FirstOrDefault();

            if (userDetail != null)
            {
                Session["EmailId"] = log.EmailId.ToString();
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, log.EmailId, DateTime.Now, DateTime.Now.AddDays(30), true, FormsAuthentication.FormsCookiePath);
                string encTicket = FormsAuthentication.Encrypt(ticket);
                Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
                if (userDetail.roleId == 1)
                {
                    Session["RoleId"] = userDetail.roleId;
                    Session["UserId"] = userDetail.UserId;
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    Session["UserId"] = userDetail.UserId;
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                TempData["alertMessage"] = "Invalid Username and Password !";
                //return RedirectToAction("Index", "Home");
                ModelState.AddModelError("", "Invalid EmailId and Password");
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            //return View();
        }
 public ActionResult Register(SignUp reg)
 {
     if (ModelState.IsValid)
     {
         mocktestEntities1 db = new mocktestEntities1();
         user        newuser  = new user();
         List <user> userList = new List <user>();
         userList         = db.users.ToList();
         newuser.Name     = reg.Name;
         newuser.EmailId  = reg.EmailId;
         newuser.Password = reg.Password;
         newuser.Branch   = reg.Branch;
         newuser.RollNo   = reg.Rollno;
         newuser.roleId   = 2;
         db.users.Add(newuser);
         db.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     else
     {
         return(View(reg));
     }
 }
        public ActionResult GetScore(Int32 correctAnswers, string totalTime, DateTime today, Int32 currentQuestion, Int32 quesId)
        {
            Int32 uid = 0;

            if (Session["UserId"] != null)
            {
                uid = Convert.ToInt32(Session["UserId"]);
                mocktestEntities1 db       = new mocktestEntities1();
                ScoreDetail       newscore = new ScoreDetail();
                newscore.QuesDetailId = quesId;
                newscore.UserId       = uid;
                newscore.Corrected    = correctAnswers;
                newscore.date         = today;
                newscore.Duration     = totalTime;
                newscore.Score        = correctAnswers;
                newscore.Attempted    = currentQuestion;
                newscore.Active       = true;

                db.ScoreDetails.Add(newscore);
                db.SaveChanges();
            }
            return(PartialView("~/Views/Home/GetScore.cshtml"));
        }
        public ActionResult AddTopic(string TopicName)
        {
            mocktestEntities1 mock = new mocktestEntities1();

            var   trim     = TopicName.TrimStart();
            Topic newTopic = new Topic();

            using (mocktestEntities1 select = new mocktestEntities1())
            {
                var count = select.Topics.Where(a => a.Name == trim);
                if (count.Count() < 1)
                {
                    newTopic.Name   = TopicName;
                    newTopic.Active = true;
                    mock.Topics.Add(newTopic);
                    mock.SaveChanges();
                }
                else
                {
                }
            }

            return(View());
        }
        public ActionResult AddSub(Int32 TopId, string SubTopicName)
        {
            mocktestEntities1 mock    = new mocktestEntities1();
            List <Topic>      Tp      = new List <Topic>();
            SubTopic          newsubT = new SubTopic();
            var trim = SubTopicName.TrimStart();

            using (mocktestEntities1 select = new mocktestEntities1())
            {
                var count = select.SubTopics.Where(a => a.Name == trim);
                if (count.Count() < 1)
                {
                    newsubT.Name    = SubTopicName;
                    newsubT.Active  = true;
                    newsubT.TopicId = TopId;
                    mock.SubTopics.Add(newsubT);
                    mock.SaveChanges();
                }
                else
                {
                }
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Register()
        {
            mocktestEntities1 db            = new mocktestEntities1();
            List <string>     objRole       = new List <string>();
            List <Role>       objListOfRole = new List <Role>();

            objListOfRole = db.Roles.ToList();
            objRole.Add("Admin");
            objRole.Add("User");
            int  count = 0;
            Role role  = new Role();

            foreach (var item in objRole)
            {
                if (objListOfRole.Count > 0)
                {
                    foreach (var roleItem in objListOfRole)
                    {
                        if (item == roleItem.RoleName)
                        {
                            count++;
                        }
                    }
                }
                if (count != 0)
                {
                }
                else
                {
                    role.RoleName = item;
                    db.Roles.Add(role);
                    db.SaveChanges();
                }
            }
            return(View());
        }
        public ActionResult UploadExcel(List <HttpPostedFileBase> files, Int32 SubId)
        {
            mocktestEntities1 db        = new mocktestEntities1();
            var uploadFile              = Request.Files[0];
            List <QuesDetail> questList = new List <QuesDetail>();
            HomeController    home      = new HomeController();
            int  setCount = 0;
            int  Qid      = 0;
            bool check    = false;

            if (uploadFile != null && uploadFile.ContentLength > 0)
            {
                Stream           stream = uploadFile.InputStream;
                IExcelDataReader reader = null;
                if (uploadFile.FileName.EndsWith(".xls"))
                {
                    reader = ExcelReaderFactory.CreateBinaryReader(stream);
                }
                else if (uploadFile.FileName.EndsWith(".xlsx"))
                {
                    reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                }
                else
                {
                    return(Json(check, JsonRequestBehavior.AllowGet));
                }
                reader.IsFirstRowAsColumnNames = true;
                DataSet result = reader.AsDataSet();
                foreach (DataColumn col in result.Tables[0].Columns)
                {
                }
                foreach (DataRow row in result.Tables[0].Rows)
                {
                    DataColumn col1 = result.Tables[0].Columns[0];
                    if (row[col1.ColumnName].ToString() != "")
                    {
                        if (home.QuestionIsVaild(row[col1.ColumnName].ToString(), SubId))
                        {
                            QuesDetail   newQuestion = new QuesDetail();
                            OptionDetail newOPtion   = new OptionDetail();
                            newQuestion.Question = row[col1.ColumnName].ToString();
                            DataColumn col2 = result.Tables[0].Columns[1];
                            newQuestion.OpCorrect  = row[col2.ColumnName].ToString();
                            newQuestion.SubTopicId = SubId;
                            newQuestion.Active     = true;
                            db.QuesDetails.Add(newQuestion);
                            db.SaveChanges();
                            questList = db.QuesDetails.ToList();
                            using (mocktestEntities1 context = new mocktestEntities1())
                            {
                                var quid = context.QuesDetails.Where(a => a.Question == newQuestion.Question & a.Active == true & a.SubTopicId == SubId).FirstOrDefault();
                                // quesId = quid.QuesDetailId;
                                //foreach (var item in questList)
                                //{
                                //    if (item.Question.Equals(newQuestion.Question))
                                //    {
                                //        Qid = item.QuesDetailId;
                                //    }
                                //}
                                newOPtion.QuesDetailId = quid.QuesDetailId;
                            }
                            DataColumn col3 = result.Tables[0].Columns[2];
                            newOPtion.OpOne = row[col3.ColumnName].ToString();

                            DataColumn col4 = result.Tables[0].Columns[3];
                            newOPtion.OpTwo = row[col4.ColumnName].ToString();

                            DataColumn col5 = result.Tables[0].Columns[4];
                            newOPtion.OpThree = row[col5.ColumnName].ToString();

                            DataColumn col6 = result.Tables[0].Columns[5];
                            newOPtion.OpFour = row[col6.ColumnName].ToString();

                            newOPtion.Active = true;
                            db.OptionDetails.Add(newOPtion);
                            db.SaveChanges();
                            setCount = 1;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            if (setCount == 1)
            {
                ModelState.AddModelError("", "File Uploaded Successfully!");
                check = true;
                return(Json(check, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(check, JsonRequestBehavior.AllowGet));
            }
        }