Пример #1
0
        /// <summary>
        /// 添加问题
        /// </summary>
        /// <param name="description"></param>
        /// <returns></returns>
        public QuestionOption AddQuestionOption(string description)
        {
            var questionOption = QuestionOption.CreateNew(this, description);

            if (QuestionOptions == null)
            {
                QuestionOptions = new List <QuestionOption>();
            }
            QuestionOptions.Add(questionOption);
            return(questionOption);
        }
Пример #2
0
        /// <summary>
        /// 设置正确选项
        /// </summary>
        /// <param name="questionOptionGuid"></param>
        public void SetCorrectOption(Guid questionOptionGuid)
        {
            if (QuestionOptions == null)
            {
                throw new Exception($"问题选项{questionOptionGuid}不存在!");
            }

            var qOption = QuestionOptions.FirstOrDefault(p => p.QuestionOptionGuid.Equals(questionOptionGuid));

            CorrectOption   = qOption ?? throw new Exception($"问题选项{questionOptionGuid}不存在!");
            CorrectOptionId = questionOptionGuid;
        }
Пример #3
0
        /// <summary>
        /// 删除问题选项
        /// </summary>
        /// <param name="questionOptionGuid"></param>
        public void RemoveQuestionOption(Guid questionOptionGuid)
        {
            if (QuestionOptions == null)
            {
                throw new Exception($"问题选项{questionOptionGuid}不存在!");
            }
            var qOption = QuestionOptions.FirstOrDefault(p => p.QuestionOptionGuid.Equals(questionOptionGuid));

            if (qOption == null)
            {
                throw new Exception($"问题选项{questionOptionGuid}不存在!");
            }

            QuestionOptions.Remove(qOption);
            if (qOption.QuestionOptionGuid.Equals(CorrectOptionId))
            {
                CorrectOptionId = default(Guid);
                CorrectOption   = null;
            }
        }
Пример #4
0
        /// <summary>
        /// 修改问题选项
        /// </summary>
        /// <param name="questionOptionGuid"></param>
        /// <param name="description"></param>
        public void UpdateQuestionOption(Guid questionOptionGuid, string description)
        {
            if (QuestionOptions == null)
            {
                throw new Exception($"问题选项{questionOptionGuid}不存在!");
            }
            var qOption = QuestionOptions.FirstOrDefault(p => p.QuestionOptionGuid.Equals(questionOptionGuid));

            if (qOption == null)
            {
                throw new Exception($"问题选项{questionOptionGuid}不存在!");
            }

            qOption.UpdateDescription(description);

            if (qOption.QuestionOptionGuid.Equals(CorrectOptionId))
            {
                CorrectOption = qOption;
            }
        }