Exemplo n.º 1
0
        /// <summary>
        /// 更新最佳选项到db
        /// </summary>
        /// <param name="session"></param>
        private static void UpdateCorrectOptions(Session session)
        {
            var kingRequest = KingRequest.FromSession(session);
            var kingAnswer  = KingAnswer.FromSession(session);

            if (kingAnswer == null || kingAnswer.IsValidate() == false)
            {
                return;
            }

            var context = KingContextTable.TakeByRequest(kingRequest);

            if (context == null)
            {
                return;
            }

            using (var sqlLite = new SqlliteContext())
            {
                var quiz       = context.KingQuestion.data.quiz;
                var quizAnswer = sqlLite.QuizAnswer.Find(quiz);

                if (quizAnswer != null)
                {
                    quizAnswer.Answer = context.GetAnswer(kingAnswer);
                    sqlLite.SaveChanges();
                    Console.WriteLine($"更新正确答案到db:{Environment.NewLine}{quizAnswer}");
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 从本地和网络查找答案
        /// 返回正确选项的索引
        /// </summary>
        /// <param name="session">会话</param>
        /// <returns></returns>
        private static int GetOptionIndex(Session session, out KingQuestion kingQuestion)
        {
            kingQuestion = KingQuestion.FromSession(session);
            if (kingQuestion == null || kingQuestion.IsValidate() == false)
            {
                return(-1);
            }

            KingContextTable.Add(new KingContext
            {
                KingQuestion = kingQuestion,
                KingRequest  = KingRequest.FromSession(session)
            });

            // 找答案
            return(SearchOptionIndex(kingQuestion));
        }