Exemple #1
0
        public async Task <IActionResult> AddAftertestChoice(AddLectureandDoneDto model)
        {
            var msg = "";

            if (model.userid > 0 && model.questionid > 0 && model.questionchoiceid > 0 && model.usercourseid > 0)
            {
                var userchoice = await db.UserQuestionChoices
                                 .FirstOrDefaultAsync(a => a.UserId == model.userid && a.UserCourseDetailId == model.usercoursedetailid && a.QuestionId == model.questionid);

                if (userchoice == null)
                {
                    repo.AddUserQuestionChoice(model.userid, model.questionid, model.questionchoiceid, model.usercourseid, model.usercoursedetailid, model.type);
                }
                else
                {
                    if (userchoice.QuestionChoiceId != model.questionchoiceid)
                    {
                        userchoice.QuestionChoiceId = model.questionchoiceid;
                    }
                }
            }
            await repo.SaveAll();

            var pretestChoice = await db.UserQuestionChoices.Where(a => a.UserId == model.userid && a.UserCourseId == model.usercourseid && a.QuestionId == model.questionid && a.Type == SD.Pretest)
                                .Include(a => a.QuestionChoice).Select(a => a.QuestionChoice.Text).FirstOrDefaultAsync();

            msg = !string.IsNullOrEmpty(pretestChoice) ? pretestChoice : "";

            return(Ok(msg));
        }
Exemple #2
0
        public async Task <IActionResult> AddQuestionChoice(AddLectureandDoneDto model)
        {
            if (model.userid > 0 && model.questionid > 0 && model.questionchoiceid > 0 && model.usercourseid > 0)
            {
                var userchoice = await db.UserQuestionChoices
                                 .FirstOrDefaultAsync(a => a.UserId == model.userid && a.UserCourseDetailId == model.usercoursedetailid && a.QuestionId == model.questionid);

                if (userchoice == null)
                {
                    repo.AddUserQuestionChoice(model.userid, model.questionid, model.questionchoiceid, model.usercourseid, model.usercoursedetailid, model.type);
                }
                else
                {
                    if (userchoice.QuestionChoiceId != model.questionchoiceid)
                    {
                        userchoice.QuestionChoiceId = model.questionchoiceid;
                    }
                }
            }


            if (await repo.SaveAll())
            {
                return(Ok("1"));
            }
            else
            {
                return(Ok("0"));
            }
        }
Exemple #3
0
        public async Task <IActionResult> GetUserChoice([FromQuery] AddLectureandDoneDto model)
        {
            var userchoice = await db.UserQuestionChoices.Where(a => a.UserId == model.userid && a.QuestionId == model.questionid && a.UserCourseDetailId == model.usercoursedetailid).Select(a => a.QuestionChoiceId).FirstOrDefaultAsync();

            return(Ok(userchoice));
        }