Пример #1
0
        public void Upsert(QuestionSuite qsuite)
        {
            //var coltn = helper.GetCollection<QuestionSuite>("exambank");
            var coltn = helper.GetCollection <QuestionSuite>(InactiveSubject_ExamSuite);
            var opt   = new UpdateOptions()
            {
                IsUpsert = true,
            };

            coltn.ReplaceOne(it => it._id == qsuite._id, qsuite, opt);
        }
Пример #2
0
 public void InsertQuestionSuite(QuestionSuite qsuite)
 {
     using (OracleConnection con = new OracleConnection(OracleUtility.conString))
     {
         con.Open();
         var cmd = con.CreateCommand();
         cmd.CommandText = $"INSERT INTO {OracleDbTableName.QuestionSuite} " +
                           $"VALUES(:Id,:Code,:Title,:SubjectId,:SubjectCode,:SubjectName,:Level_,:LayoutCode,:Description)";
         cmd.Parameters.Add("Id", qsuite._id);
         cmd.Parameters.Add("Code", qsuite.Code);
         cmd.Parameters.Add("Title", qsuite.Title);
         cmd.Parameters.Add("SubjectId", qsuite.SubjectId);
         cmd.Parameters.Add("SubjectCode", qsuite.SubjectCode);
         cmd.Parameters.Add("SubjectName", qsuite.SubjectName);
         cmd.Parameters.Add("Level_", qsuite.Level);
         cmd.Parameters.Add("LayoutCode", qsuite.LayoutCode);
         cmd.Parameters.Add("Description", qsuite.Description);
         cmd.ExecuteNonQuery();
     }
 }
Пример #3
0
 public void InsertQuestionSuite(QuestionSuite qsuite)
 {
     throw new NotImplementedException();
 }
Пример #4
0
        public void Upsert(QuestionSuite qsuite)
        {
            using (OracleConnection con = new OracleConnection(OracleUtility.conString))
            {
                con.Open();
                var cmd = con.CreateCommand();
                cmd.CommandText = $"INSERT INTO {OracleDbTableName.QuestionSuite} " +
                                  $"VALUES(:Id,:Code,:Title,:SubjectId,:SubjectCode,:SubjectName,:Level,:LayoutCode,:Description)" +
                                  $"WHEN duplicate THEN SET Code=:Code, Title=:Title, SubjectId=:SubjectId, SubjectCode=:SubjectCode, " +
                                  $"SubjectName=:SubjectName, Level_=:Level, LayoutCode=:LayoutCode, Description=:Description, ";
                cmd.Parameters.Add("Id", qsuite._id);
                cmd.Parameters.Add("Code", qsuite.Code);
                cmd.Parameters.Add("Title", qsuite.Title);
                cmd.Parameters.Add("SubjectId", qsuite.SubjectId);
                cmd.Parameters.Add("SubjectCode", qsuite.SubjectCode);
                cmd.Parameters.Add("SubjectName", qsuite.SubjectName);
                cmd.Parameters.Add("Level", qsuite.Level);
                cmd.Parameters.Add("LayoutCode", qsuite.LayoutCode);
                cmd.Parameters.Add("Description", qsuite.Description);
                cmd.ExecuteNonQuery();

                var cmd2        = con.CreateCommand();
                var commandText = $"REPLACE INTO {OracleDbTableName.Question} VALUES ";
                int i           = 0;
                foreach (MultipleChoiceQuestionWithOneCorrectAnswer question in qsuite.Questions)
                {
                    commandText += $"(:Id{i},:No{i},:Code{i},:Content{i},:GroupId{i},:NoShuffleChoice{i})";
                    if (i < qsuite.Questions.Count())
                    {
                        commandText += ",";
                    }

                    cmd2.Parameters.Add($"Id{i}", question._id);
                    cmd2.Parameters.Add($"No{i}", question.No);
                    cmd2.Parameters.Add($"Code{i}", question.Code);
                    cmd2.Parameters.Add($"Content{i}", question.Content);
                    cmd2.Parameters.Add($"GroupId{i}", question.GroupId);
                    cmd2.Parameters.Add($"NoShuffleChoice{i}", question.NoShuffleChoice);

                    i++;
                }
                cmd2.CommandText = commandText;
                cmd2.ExecuteNonQuery();

                var choices = qsuite.Questions.SelectMany(q => ((MultipleChoiceQuestionWithOneCorrectAnswer)q).Choices.Select(c =>
                {
                    return(new TheS.ExamBank.DataFormats.SelectableChoiceWithId
                    {
                        _id = $"{q._id}-{c.Code}",
                        Code = c.Code,
                        Content = c.Content,
                        IsCorrectAnswer = c.IsCorrectAnswer,
                        QuestionId = q._id,
                    });
                })).ToList();
                var cmd3 = con.CreateCommand();
                commandText = $"REPLACE INTO {OracleDbTableName.Choice} VALUES ";
                i           = 0;
                foreach (SelectableChoiceWithId choice in choices)
                {
                    commandText += $"(:Id{i},:Code{i},:Content{i},:IsCorrectAnswer{i})";
                    if (i < qsuite.Questions.Count())
                    {
                        commandText += ",";
                    }

                    cmd3.Parameters.Add($"Id{i}", choice._id);
                    cmd3.Parameters.Add($"Code{i}", choice.Code);
                    cmd3.Parameters.Add($"Content{i}", choice.Content);
                    cmd3.Parameters.Add($"IsCorrectAnswer{i}", choice.IsCorrectAnswer);

                    i++;
                }
                cmd3.CommandText = commandText;
                cmd3.ExecuteNonQuery();
            }
        }