Exemple #1
0
        public async Task CreateMatchQuiz(MatchQuizModel quiz)
        {
            try
            {
                DynamicParameters p = new DynamicParameters();

                p.Add("Question", quiz.Question);
                p.Add("OrderNo", quiz.OrderNo);
                p.Add("SectionId", quiz.SectionId);
                p.Add("Id", DbType.Int32, direction: ParameterDirection.Output);

                _dataAccess.StartTransaction(SD.DB);

                await _dataAccess.SaveDataInTransaction("dbo.spMatchQuiz_Insert", p);

                var quizId = p.Get <int>("Id");

                foreach (var option in quiz.Options)
                {
                    option.QuizId = quizId;

                    var op = new
                    {
                        option.Id,
                        option.QuizId,
                        option.LeftOption,
                        option.RightOption
                    };

                    await _dataAccess.SaveDataInTransaction("dbo.spMatchQuizOptions_Insert", op);
                }

                _dataAccess.CommitTransaction();
            }
            catch
            {
                _dataAccess.RollbackTransaction();

                throw;
            }
        }
Exemple #2
0
        private async Task CreateNewMatchQuiz()
        {
            MatchQuizModel quizToSave = new MatchQuizModel
            {
                Question  = quiz.Question,
                SectionId = SectionId,
                OrderNo   = OrderNo
            };

            foreach (var option in quiz.Options)
            {
                quizToSave.Options.Add(new MatchQuizOptionModel
                {
                    LeftOption  = option.LeftOption,
                    RightOption = option.RightOption
                });
            }

            await MatchQuizData.CreateMatchQuiz(quizToSave);

            NavMan.NavigateTo($"/projects/{ProjectId}");
        }