コード例 #1
0
 private QuestionInfo UpdateQuestion(QuestionInfo questionInfo)
 {
     //先加载出来数据库当前这个问题的数据
     //保存原有的答案
     //对比现在的答案得到已删除的答案
     //更新问题数据
     DbModel.QuestionInfo question = InternalLoad(questionInfo.Id);
     question.QuestionName  = questionInfo.Name;
     question.QuestionScore = questionInfo.QuestionScore;
     question.QuestionType  = (DbModel.QuestionType)questionInfo.QuestionType;
     question = _repository.Save(question);
     //保存问题答案
     if (questionInfo.Solutions != null && questionInfo.Solutions.Count() > 0)
     {
         IEnumerable <SolutionInfo> oldSolutions    = QuerySolutions(questionInfo.Id);
         List <SolutionInfo>        deleteSolutions = new List <SolutionInfo>();
         foreach (SolutionInfo item in oldSolutions)
         {
             SolutionInfo solution = questionInfo.Solutions.FirstOrDefault(p => p.Name.Equals(item.Name));
             if (solution == null)
             {
                 deleteSolutions.Add(item);
             }
             else
             {
                 solution.Id         = item.Id;
                 solution.RelationId = item.RelationId;
             }
         }
         SaveRelation(questionInfo);
         RemoveRelation(questionInfo, deleteSolutions);
     }
     return(questionInfo);
 }
コード例 #2
0
        public QuestionInfo Load(int questionId)
        {
            DbModel.QuestionInfo question = InternalLoad(questionId);
            if (question == null)
            {
                return(null);
            }
            QuestionInfo result = new QuestionInfo();

            result.Id                = question.Id;
            result.Name              = question.QuestionName;
            result.QuestionScore     = question.QuestionScore;
            result.QuestionType      = (QuestionType)question.QuestionType;
            result.QuestionGroupName = question.QuestionGroupName;
            result.Solutions         = QuerySolutions(question.Solutions);
            return(result);
        }
コード例 #3
0
 private QuestionInfo CreateQuestion(QuestionInfo questionInfo)
 {
     //创建的时候答案肯定是没有的,所以不用判断relation
     DbModel.QuestionInfo question = new DbModel.QuestionInfo();
     question.QuestionName      = questionInfo.Name;
     question.QuestionScore     = questionInfo.QuestionScore;
     question.QuestionType      = (DbModel.QuestionType)questionInfo.QuestionType;
     question.QuestionGroupName = questionInfo.QuestionGroupName;
     question.CreateUserId      = _loginUser.Id;
     question.CreateDate        = DateTime.Now;
     question        = _repository.Save(question);
     questionInfo.Id = question.Id;
     //保存答案
     if (questionInfo.Solutions != null && questionInfo.Solutions.Count() > 0)
     {
         SaveRelation(questionInfo);
     }
     return(questionInfo);
 }