Esempio n. 1
0
        public long Insert(NewQuestionRequestModel item)
        {
            Question question = new Question
            {
                Question_ = item.Content,
                SubjectId = item.SubjectId,
                SysUserId = 1, // TODO: Change current sysUser
            };

            _questionRepo.Insert(question);
            return question.QuestionId;
        }
Esempio n. 2
0
        /// <summary>
        /// Cần kiểm tra SubjectId
        /// </summary>
        public static bool Validate(NewQuestionRequestModel model, out string message)
        {
            bool fail = false;

            if(model.Content == null ||
                model.Content.Length < QUESTION_MIN_LENGTH ||
                model.Content.Length > QUESIION_MAX_LENGTH)
            {
                fail = true;
                message = string.Format(
                    "Content of question must be between {0} to {1} in length",
                    QUESTION_MIN_LENGTH, QUESIION_MAX_LENGTH);
            }
            else if(!model.Choices.All(
                x => x.Content != null &&
                model.Content.Length >= CHOICE_MIN_LENGTH &&
                model.Content.Length <= CHOICE_MAX_LENGTH))
            {
                fail = true;
                message = string.Format(
                    "Content of choice must be between {0} to {1} in length",
                    CHOICE_MIN_LENGTH, CHOICE_MAX_LENGTH);
            }
            else if(model.Choices.Count(x => x.IsCorrect) == 0)
            {
                fail = true;
                message = "Question must have at least 1 correct choice";
            }
            else if(model.Choices.Count(x => !x.IsCorrect) == 0)
            {
                fail = true;
                message = "Question must have at least 1 incorrect choice";
            }
            else
            {
                message = "Success";
            }

            return !fail;
        }