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