//用户选择时保存答案的接口
        public SubmitResponseModel SubmitAnswer(SubmitAnswerParameter parameter)
        {
            SubmitResponseModel model = new SubmitResponseModel();

            try
            {
                var userScore = DataHelp.GetUserScore(parameter.UserId);
                if (userScore.IsSubmit != "1")
                {
                    if (DataHelp.SubmitAnswer(parameter))
                    {
                        var questionList = DataHelp.GetQuestionList();
                        int sum          = 0;
                        foreach (var answer in parameter.UserAnswerList)
                        {
                            var userAnswer = questionList.Where(x => x.Id == answer.QuestionId).FirstOrDefault();
                            if (userAnswer != null)
                            {
                                if (userAnswer.Answer == answer.Answer)
                                {
                                    if (userAnswer.Multi == "1")
                                    {
                                        sum++;
                                    }
                                    else
                                    {
                                        sum = sum + 2;
                                    }
                                }
                            }
                        }
                        if (DataHelp.SubmitScore(parameter.UserId, sum))
                        {
                            model.Score  = sum.ToString();
                            model.Status = "1";
                        }
                        else
                        {
                            model.Status = "0";
                        }
                    }
                }
                else
                {
                    model.Score  = userScore.Score.ToString();
                    model.Status = "1";
                }
            }
            catch
            {
                model.Status = "0";
            }
            return(model);
        }
Exemple #2
0
        public QuestionModel GetQuestionList(string userId)
        {
            QuestionModel model = new QuestionModel();

            try
            {
                var userScore = DataHelp.GetUserScore(userId);
                if (userScore.IsSubmit != "1")
                {
                    var questionList = DataHelp.GetQuestionList();
                    int type         = 6;
                    int multi        = 3;
                    List <QuestionEntity> singleQuestionList = new List <QuestionEntity>();
                    List <QuestionEntity> multiQuestionList  = new List <QuestionEntity>();
                    for (int j = 1; j < multi; j++)
                    {
                        for (int i = 1; i < type; i++)
                        {
                            if (j == 1)
                            {
                                singleQuestionList.AddRange(questionList.Where(x => x.Type == i.ToString() && x.Multi == j.ToString()).OrderBy(x => Guid.NewGuid()).Take(8).ToList());
                            }
                            else
                            {
                                multiQuestionList.AddRange(questionList.Where(x => x.Type == i.ToString() && x.Multi == j.ToString()).OrderBy(x => Guid.NewGuid()).Take(2).ToList());
                            }
                        }
                    }
                    model.QuestionList.AddRange(singleQuestionList.OrderBy(x => Guid.NewGuid()));
                    model.QuestionList.AddRange(multiQuestionList.OrderBy(x => Guid.NewGuid()));
                    for (int i = 0; i > model.QuestionList.Count; i++)
                    {
                        model.QuestionList[i].Answer = string.Empty;
                    }
                    model.IsSubmit       = "0";
                    model.FirstLoginTime = ((userScore.CreateTime.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString();
                    model.NowTime        = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString();
                }
                else
                {
                    //已经提交了,直接给分
                    model.IsSubmit = "1";
                    model.Score    = userScore.Score;
                }
                model.Status = "1";
            }
            catch
            {
                model.Status = "0";
            }
            return(model);
        }
Exemple #3
0
        public QuestionModel GetQuestionList(string userId)
        {
            QuestionModel model     = new QuestionModel();
            var           userScore = DataHelp.GetUserScore(userId);

            if (userScore.IsSubmit != "1")
            {
                var questionList = DataHelp.GetQuestionList();
                var oneList      = questionList.Where(x => x.Type == "1" && x.Multi == "0").Take(8).ToList();
                var oneMultiList = questionList.Where(x => x.Type == "1" && x.Multi == "1").Take(2).ToList();
                int type         = 6;
                int multi        = 2;
                List <QuestionEntity> singleQuestionList = new List <QuestionEntity>();
                List <QuestionEntity> multiQuestionList  = new List <QuestionEntity>();
                for (int j = 0; j < multi; j++)
                {
                    for (int i = 1; i < type; i++)
                    {
                        if (j == 0)
                        {
                            singleQuestionList.AddRange(questionList.Where(x => x.Type == i.ToString() && x.Multi == j.ToString()).Take(8).ToList());
                        }
                        else
                        {
                            multiQuestionList.AddRange(questionList.Where(x => x.Type == i.ToString() && x.Multi == j.ToString()).Take(2).ToList());
                        }
                    }
                }
                model.QuestionList.AddRange(singleQuestionList.OrderBy(x => Guid.NewGuid()));
                model.QuestionList.AddRange(multiQuestionList.OrderBy(x => Guid.NewGuid()));
                model.IsSubmit       = "0";
                model.FirstLoginTime = userScore.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
            }
            else
            {
                //已经提交了,直接给分
                model.IsSubmit = "1";
                model.Score    = userScore.Score;
            }
            return(model);
        }