示例#1
0
        /// <summary>
        /// 获取答题次序号
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="websiteOwner"></param>
        /// <returns></returns>
        private int GetResultNum(string userId, string websiteOwner)
        {
            StringBuilder sbSql = new StringBuilder();

            sbSql.AppendFormat(" WebsiteOwner='{0}' ", websiteOwner);
            sbSql.AppendFormat(" AND UserId='{0}' ", userId);
            sbSql.AppendFormat(" ORDER BY Num Desc ", websiteOwner);
            ForbesQuestionResult questionResult = Get <ForbesQuestionResult>(sbSql.ToString());

            if (questionResult == null)
            {
                return(1);
            }
            else
            {
                return(questionResult.Num + 1);
            }
        }
示例#2
0
        /// <summary>
        /// 提交答案
        /// </summary>
        /// <param name="questionPersonalList"></param>
        /// <param name="needCount"></param>
        /// <param name="UserId"></param>
        /// <param name="websiteOwner"></param>
        /// <param name="errmsg"></param>
        /// <returns></returns>
        public bool PostQuestionResult(List <ForbesQuestionPersonal> questionPersonalList, int needCount, string UserId, string websiteOwner
                                       , string activity, out string errmsg, out int totalScore, out int resultNum)
        {
            if (needCount > 0 && questionPersonalList.Count < needCount)
            {
                errmsg     = "请完成答题";
                totalScore = 0;
                resultNum  = 0;
                return(false);
            }
            ForbesQuestionResult questionResult = new ForbesQuestionResult();

            questionResult.Num          = GetResultNum(UserId, websiteOwner);
            resultNum                   = questionResult.Num;
            questionResult.TotalScore   = questionPersonalList.Sum(p => p.Score);
            totalScore                  = questionResult.TotalScore;
            questionResult.UserId       = UserId;
            questionResult.WebsiteOwner = websiteOwner;
            questionResult.CreateDate   = DateTime.Now;
            questionResult.Status       = 1;
            questionResult.Activity     = activity;

            if (Add(questionResult))
            {
                foreach (ForbesQuestionPersonal QuestionPersonal in questionPersonalList)
                {
                    QuestionPersonal.Count  = questionResult.Num;
                    QuestionPersonal.Status = 1;
                    Add(QuestionPersonal);
                }
                errmsg = "提交完成";
                return(true);
            }
            else
            {
                errmsg = "提交失败";
                return(false);
            }
        }