Ejemplo n.º 1
0
        public void Create(QuizzAddViewModel model)
        {
            using (var ctx = new QuizzContext())
            {
                Quizz quizz = new Quizz()
                {
                    CreatedBy = model.CreatedBy,
                    CreatedOn = model.CreatedOn,

                    ModifiedBy = model.ModifiedBy,
                    ModifiedOn = model.ModifiedOn,

                    QuizzQuestions = model.QuizzQuestions,

                    QuizzCandidate = new Candidate()
                    {
                        Name = model.CandidateName,
                        Age  = model.CandidateAge,
                        Mail = model.CandidateMail,
                    },

                    QuizzSkillLevel = model.QuizzSkillLevel,
                    QuizzTechno     = model.QuizzTechno,
                    QuizzUser       = model.QuizzUser
                };

                ctx.Quizzs.Add(quizz);
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public void AddCandidate()
        {
            string   name       = Console.ReadLine();
            int      age        = Int32.Parse(Console.ReadLine());
            string   mail       = Console.ReadLine();
            int      skilllevel = Int32.Parse(Console.ReadLine());
            string   techno     = Console.ReadLine();
            DateTime createdon  = DateTime.Now;
            string   createdby  = "Test1";
            DateTime modifiedon = DateTime.Now;
            string   modifiedby = "Test1";


            using (var ctx = new QuizzContext())
            {
                var candidate = new Candidate()
                {
                    Name = name, Age = age, Mail = mail, SkillLevel = skilllevel, Techno = techno, CreatedOn = createdon, CreatedBy = createdby, ModifiedBy = modifiedby, ModifiedOn = modifiedon
                };
                ctx.Candidates.Add(candidate);
                ctx.SaveChanges();

                var query = ctx.Candidates.ToList();

                //foreach(var candidates in query)
                //{
                //    foreach (var item in candidates) ;
                //}
                //Console.ReadLine();
            }
        }
Ejemplo n.º 3
0
 public void DeleteCandidate(int id)
 {
     using (var ctx = new QuizzContext())
     {
         ctx.Candidates.Remove(ctx.Candidates.Single(c => c.QuizzCandidateId == id));
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 4
0
        public void GenerateQuizz(QuizzAddViewModel model)
        {
            using (var ctx = new QuizzContext())
            {
                Quizz quizz = new Quizz()
                {
                    CreatedBy = model.CreatedBy,
                    CreatedOn = model.CreatedOn,

                    ModifiedBy = model.ModifiedBy,
                    ModifiedOn = model.ModifiedOn,

                    QuizzQuestions = new List <QuizzLinkQuestions>(),

                    QuizzCandidate = new Candidate()
                    {
                        Name = model.CandidateName,
                        Age  = model.CandidateAge,
                        Mail = model.CandidateMail,
                    },

                    QuizzSkillLevelId = model.SkillId,
                    QuizzTechnoId     = model.TechnoId,
                    QuizzUser         = model.QuizzUser
                };

                var generatedQuestions = GenerateQuestions(model, 15);
                foreach (var question in generatedQuestions)
                {
                    quizz.QuizzQuestions.Add(new QuizzLinkQuestions()
                    {
                        QuizzQuestionsId = question.QuizzQuestionsId
                    });
                }
                //Repo
                ctx.Quizzs.Add(quizz);
                ctx.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        public void QuestionsMarker(int nbQuestions)
        {
            Random rnd = new Random();

            using (var ctx = new QuizzContext())
            {
                for (int i = 0; i < 3; i++)
                {
                    ctx.SkillLevels.Add(new SkillLevel()
                    {
                        NameSkillLevel = "SkillLevel" + i.ToString()
                    });
                }

                for (int i = 0; i < 10; i++)
                {
                    ctx.Technologies.Add(new Technology()
                    {
                        NameTechnologie = "Techno " + i.ToString()
                    });
                }

                ctx.SaveChanges();

                for (int i = 0; i < nbQuestions; i++)
                {
                    int rndTechno = rnd.Next(1, ctx.Technologies.Count());
                    int rndSkill  = rnd.Next(1, ctx.SkillLevels.Count());

                    ctx.Questions.Add(new Question
                    {
                        QuestionStr = "Text Sample " + i.ToString(),

                        QuestionTechnoId = ctx.Technologies
                                           .Where(t => t.TechnologieId == rndTechno)
                                           .FirstOrDefault(),

                        QuestionSkillId = ctx.SkillLevels
                                          .Where(s => s.SkillLevelId == rndSkill)
                                          .FirstOrDefault(),
                    });
                }
                ctx.SaveChanges();

                foreach (var question in ctx.Questions)
                {
                    ctx.Answers.AddRange(new List <Answer>
                    {
                        new Answer
                        {
                            AnswerStr      = "Answer 1",
                            RightAnswer    = false,
                            AnswerQuestion = question,
                        },
                        new Answer
                        {
                            AnswerStr      = "Answer 2",
                            RightAnswer    = false,
                            AnswerQuestion = question,
                        },
                        new Answer
                        {
                            AnswerStr      = "Answer 3",
                            RightAnswer    = true,
                            AnswerQuestion = question,
                        },
                        new Answer
                        {
                            AnswerStr      = "Answer 4",
                            RightAnswer    = false,
                            AnswerQuestion = question,
                        }
                    });
                }
                ctx.SaveChanges();
            }
        }