Ejemplo n.º 1
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.º 2
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.º 3
0
 public void EditCandidate(int id)
 {
     using (var ctx = new QuizzContext())
     {
         var query = ctx.Candidates
                     .Where(c => c.QuizzCandidateId == id);
     }
 }
Ejemplo n.º 4
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.º 5
0
 public void GetCandidates()
 {
     using (var ctx = new QuizzContext())
     {
         var candidates = ctx.Candidates;
         candidates.ToList();
         foreach (Candidate candidate in candidates)
         {
             Console.WriteLine(candidate);
         }
     }
 }
Ejemplo n.º 6
0
 //Retourne la liste des Quizz
 public void GetQuizzList(QuizzListViewModel model)
 {
     using (var ctx = new QuizzContext())
     {
         //Repo
         model.ListQuizzes = ctx.Quizzs
                             .Include(q => q.QuizzCandidate)
                             .Include(q => q.QuizzSkillLevel)
                             .Include(q => q.QuizzTechno)
                             .ToList();
     }
 }
Ejemplo n.º 7
0
        public void GetQuestions(int nbQuestions, int skillId, int technoId)
        {
            Random rnd = new Random();

            using (var ctx = new QuizzContext())
            {
                List <Question> questions = ctx.Questions
                                            .Where(q => q.QuestionSkillId.SkillLevelId == skillId && q.QuestionTechnoId.TechnologieId == technoId)
                                            .ToList();

                for (int i = 0; i < nbQuestions; i++)
                {
                    int questionSelected = rnd.Next(0, questions.Count());
                    questions.ElementAt(questionSelected);
                }
            }
        }
Ejemplo n.º 8
0
        public List <Question> GenerateQuestions(QuizzAddViewModel model, int nbQuestions)
        {
            Random          rnd           = new Random();
            List <Question> listQuestions = new List <Question>();


            using (var ctx = new QuizzContext())
            {
                List <Question> questions = ctx.Questions
                                            .Where(q => q.QuestionSkillId.SkillLevelId == model.SkillId && q.QuestionTechnoId.TechnologieId == model.TechnoId)
                                            .ToList();

                for (int i = 0; i < nbQuestions; i++)
                {
                    int questionSelected = rnd.Next(0, questions.Count());
                    listQuestions.Add(questions.ElementAt(questionSelected));
                }
            }
            return(listQuestions);
        }
Ejemplo n.º 9
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.º 10
0
 public QuizzContext Init()
 {
     return(dbContext ?? (dbContext = new QuizzContext()));
 }
Ejemplo n.º 11
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();
            }
        }