public void IsExamCompletion(UserExamCompletion objExamCompletion)
        {
            tbl_txn_Test_Completion objTestCompletion = new tbl_txn_Test_Completion();

            using (var objContext = new IPTSE_EXAMEntities())
            {
                using (var dbcxtransaction = objContext.Database.BeginTransaction())
                {
                    try
                    {
                        objTestCompletion.CandidateId     = Convert.ToInt32(objExamCompletion.CandidateId);
                        objTestCompletion.IsExamCompleted = objExamCompletion.IsExamCompleted;
                        objTestCompletion.CreatedBy       = objExamCompletion.CreatedBy;
                        objTestCompletion.CreatedDateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));
                        objContext.tbl_txn_Test_Completion.Add(objTestCompletion);
                        objContext.SaveChanges();
                        dbcxtransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
        public void SaveAnswer(Questions questions, login_table objUserProfile)
        {
            tbl_Txn_Test_Result           objQuest       = new tbl_Txn_Test_Result();
            tbl_Question_Choice           objQuestChoice = new tbl_Question_Choice();
            tbl_Txn_Question_Duration_Map objMap         = new tbl_Txn_Question_Duration_Map();

            using (var objContext = new IPTSE_EXAMEntities())
            {
                using (var dbcxtransaction = objContext.Database.BeginTransaction())
                {
                    try
                    {
                        objQuest.CandidateId      = Convert.ToInt32(objUserProfile.Id);
                        objQuest.CandidateEmailId = objUserProfile.email;
                        objQuest.TestXQId         = questions.Id;
                        objQuest.ChoiceId         = questions.selectedvalue;
                        objQuest.MarkScored       = questions.markScored;
                        var isRight = objContext.tbl_Question_Choice.Where(t => t.Id == questions.selectedvalue).Select(t1 => t1.IsAnswer).ToString();
                        if (isRight == "true")
                        {
                            objQuest.MarkScored = objContext.tbl_Question.Where(t1 => t1.Id == questions.Id).Select(t2 => t2.Points).FirstOrDefault();
                        }
                        objQuest.CreatedBy   = objUserProfile.email;
                        objQuest.CreatedDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));
                        objContext.tbl_Txn_Test_Result.Add(objQuest);
                        objMap.TestXQId       = questions.Id;
                        objMap.AnswerTime_Sec = Convert.ToInt32(60 - Convert.ToInt32(questions.skippedTime.Substring(questions.skippedTime.Length - 2)));
                        //objMap.AnswerTime_Sec = Convert.ToInt32(timeSpend);
                        objMap.CreatedBy   = objUserProfile.email;
                        objMap.CreatedDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));
                        objContext.tbl_Txn_Question_Duration_Map.Add(objMap);
                        objContext.SaveChanges();
                        dbcxtransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
        public void SaveRemaining(Questions quest, UserProfile objUserProfile)
        {
            tbl_Txn_Test_Result           objQuest       = new tbl_Txn_Test_Result();
            tbl_Question_Choice           objQuestChoice = new tbl_Question_Choice();
            tbl_Txn_Question_Duration_Map objMap         = new tbl_Txn_Question_Duration_Map();

            using (var objContext = new IPTSE_EXAMEntities())
            {
                using (var dbcxtransaction = objContext.Database.BeginTransaction())
                {
                    try
                    {
                        objQuest.CandidateId      = objUserProfile.Id;
                        objQuest.CandidateEmailId = objUserProfile.email;
                        objQuest.TestXQId         = quest.Id;
                        objQuest.ChoiceId         = quest.selectedvalue;
                        objQuest.MarkScored       = quest.markScored;
                        var isRight = objContext.tbl_Question_Choice.Where(t => t.Id == quest.selectedvalue).Select(t1 => t1.IsAnswer).ToString();
                        if (isRight == "true")
                        {
                            objQuest.MarkScored = objContext.tbl_Question.Where(t1 => t1.Id == quest.Id).Select(t2 => t2.Points).FirstOrDefault();
                        }
                        objContext.tbl_Txn_Test_Result.Add(objQuest);
                        objMap.TestXQId       = quest.Id;
                        objMap.AnswerTime_Sec = objMap.AnswerTime_Sec = Convert.ToInt32(60 - Convert.ToInt32(quest.skippedTime.Substring(quest.skippedTime.Length - 2)));
                        objContext.tbl_Txn_Question_Duration_Map.Add(objMap);
                        objContext.SaveChanges();
                        dbcxtransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
        public void SaveChanges(Questions ques)
        {
            using (IPTSE_EXAMEntities db = new IPTSE_EXAMEntities())
            {
                using (var dbcxtransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        tbl_Question tbl_Ques = new tbl_Question();
                        tbl_Ques.Id                   = ques.Id;
                        tbl_Ques.QuestionText         = ques.QuestionText;
                        tbl_Ques.QuestionCategoryId   = (int)ques.QuestionCategoryId;
                        tbl_Ques.QuestionDifficultyId = ques.QuestionDifficultyId;
                        tbl_Ques.IsActive             = ques.IsActive;
                        tbl_Ques.Points               = 1;
                        tbl_Ques.CreatedBy            = "Admin";
                        tbl_Ques.CreatedDate          = DateTime.Now;
                        ques.questionsChoice.ForEach(m => tbl_Ques.tbl_Question_Choice.Add(new tbl_Question_Choice
                        {
                            Id          = m.Id,
                            Question_Id = m.Question_Id,
                            ChoiceText  = m.ChoiceText,
                            IsAnswer    = m.IsAnswer,
                            IsActive    = m.IsActive,
                            CreatedBy   = "Admin",
                            CreatedDate = tbl_Ques.CreatedDate
                        }));

                        db.Entry(tbl_Ques).State = EntityState.Modified;

                        tbl_Test_Question_Map map = db.tbl_Test_Question_Map.FirstOrDefault(m => m.QuestionId == ques.Id);

                        //tbl_Ques.tbl_Test_Question_Map.Add(new tbl_Test_Question_Map
                        //{
                        //    ID = map.ID,
                        //    IsActive = true,
                        //    QuestionId = ques.Id,
                        //    TestId = ques.TestId,
                        //    CreatedBy = "Admin",
                        //    CreatedDate = tbl_Ques.CreatedDate
                        //});

                        foreach (var item in tbl_Ques.tbl_Test_Question_Map)
                        {
                            item.TestId          = ques.TestId;
                            db.Entry(item).State = EntityState.Modified;
                        }

                        foreach (var item in tbl_Ques.tbl_Question_Choice)
                        {
                            db.Entry(item).State = EntityState.Modified;
                        }

                        db.SaveChanges();
                        dbcxtransaction.Commit();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        dbcxtransaction.Rollback();
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        dbcxtransaction.Rollback();
                        throw ex;
                    }
                }
            }
        }
        public void AddQuestion(Questions in_question)
        {
            using (IPTSE_EXAMEntities db = new IPTSE_EXAMEntities())
            {
                using (var dbcxtransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        tbl_Question          question          = new tbl_Question();
                        tbl_Question_Category question_Category = new tbl_Question_Category();
                        tbl_Question_Choice   question_Choice   = new tbl_Question_Choice();
                        //tbl_Test test = new tbl_Test();
                        tbl_Test_Question_Map test_question_Map = new tbl_Test_Question_Map();

                        question.QuestionText         = in_question.QuestionText;
                        question.IsActive             = in_question.IsActive;
                        question.Points               = in_question.Points;
                        question.QuestionCategoryId   = (int)in_question.QuestionCategoryId;
                        question.QuestionDifficultyId = in_question.QuestionDifficultyId;
                        question.CreatedBy            = "Admin";
                        question.CreatedDate          = DateTime.Now;
                        question.Points               = 1;
                        db.tbl_Question.Add(question);
                        db.SaveChanges();
                        //question.Id

                        db.tbl_Test_Question_Map.Add(new tbl_Test_Question_Map
                        {
                            TestId      = in_question.TestId,
                            QuestionId  = question.Id,
                            IsActive    = in_question.IsActive,
                            CreatedBy   = "Admin",
                            CreatedDate = DateTime.Now
                        });

                        foreach (QuestionsChoice item in in_question.questionsChoice)
                        {
                            db.tbl_Question_Choice.Add(new tbl_Question_Choice
                            {
                                ChoiceText  = item.ChoiceText,
                                IsActive    = item.IsActive,
                                IsAnswer    = item.IsAnswer,
                                Question_Id = question.Id,
                                CreatedBy   = "Admin",
                                CreatedDate = DateTime.Now
                                              //,tbl_Question = question
                            });
                        }
                        db.SaveChanges();
                        dbcxtransaction.Commit();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        dbcxtransaction.Rollback();
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        dbcxtransaction.Rollback();
                        throw ex;
                    }
                }
            }
        }