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 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 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 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 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 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 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 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 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 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 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));
            }
        }