public void StoreQuestionToUsersAnswers(Question question) { Answer selectedAnswer = CurrentAnswers.Where(x => x.IsSelected == true).Single(); Answer dbSelectedAnswer = QuizEntities.Answers.Where(x => x.Id == selectedAnswer.Id).Single(); UsersAnswers.Add(question, dbSelectedAnswer); }
public void Delete(DalUsersAnswers e) { if (context.Database.Connection.State != ConnectionState.Open) { context.Database.Connection.Open(); } UsersAnswers ua = context.Set <UsersAnswers>(). FirstOrDefault(a => a.UsersTestId == e.UserTestId && a.QuestionId == e.QuestionId && a.BeginningTime == e.BeginningTime); context.Set <UsersAnswers>().Remove(ua); }
public void Update(DalUsersAnswers entity) { if (context.Database.Connection.State != ConnectionState.Open) { context.Database.Connection.Open(); } UsersAnswers ua = context.Set <UsersAnswers>(). FirstOrDefault(a => a.UsersTestId == entity.UserTestId && a.QuestionId == entity.QuestionId && a.BeginningTime == entity.BeginningTime); ua.AnswerStructure = entity.AnswerStructure; ua.EndingTime = entity.EndingTime; }
public void Create(DalUsersAnswers e) { if (context.Database.Connection.State != ConnectionState.Open) { context.Database.Connection.Open(); } UsersAnswers ua = new UsersAnswers() { AnswerStructure = e.AnswerStructure, BeginningTime = e.BeginningTime, EndingTime = e.EndingTime, QuestionId = e.QuestionId, UsersTestId = e.UserTestId }; context.Set <UsersAnswers>().Add(ua); }
public IActionResult CheckAnswers() { int?userID = HttpContext.Session.GetInt32("LogedUserID"); if (userID != null) { dbUser = _context.users.SingleOrDefault(u => u.id == userID); if (dbUser == null) { return(RedirectToAction("Index", "Home")); } Console.WriteLine("***********************************"); // int score = 0; // globalQuestions try{ foreach (string key in Request.Form.Keys) { string value = Request.Form[key]; int keyId; if (int.TryParse(key, out keyId)) { Questions qest = null; string user_answer = null; foreach (var gq in globalQuestions) { if (gq.id == keyId) { qest = gq; } } foreach (var ans in qest.Answers) { if (ans.id == int.Parse(value)) { user_answer = ans.answer; if (ans.correct_answer == 1) { score += 100; } } } UsersAnswers ua = new UsersAnswers() { userId = dbUser.id, questionId = qest.id, answer = user_answer }; _context.Add(ua); // _context.SaveChanges(); } } }catch (Exception e) { Console.WriteLine("*********************************" + e.ToString() + "*********************************"); } finally{ game.status = "Closed"; dbUser.points += score; // _context.Add(dbUser); _context.SaveChanges(); } } Console.WriteLine("***********************************"); // return RedirectToAction("Index", "Home"); return(RedirectToAction("ViewResults")); }