Example #1
0
        /// <summary>
        /// Fonction retournant tous les quizz dans une liste de Quizz
        /// Fonctionne avec une fluentQuerry
        /// </summary>
        /// <returns>Retourne tous les quizz</returns>
        public List <Quizz> GetAllQuizz()
        {
            List <Quizz>      desQuizz = new List <Quizz>();
            FilRougeDBContext db       = new FilRougeDBContext();

            try
            {
                IQueryable <Quizz> fluentQuery = db.Quizz.Select(e => e);
                if (fluentQuery.Count() == 0)
                {
                    throw new ListQuizzEmpty("La liste des quizz est vide");
                }
                foreach (var item in fluentQuery)
                {
                    desQuizz.Add(item);
                }
                db.Dispose();
            }
            catch (ListQuizzEmpty)
            {
                db.Dispose();
            }

            return(desQuizz);
        }
Example #2
0
        /// <summary>
        /// Création d'un Quizz
        /// </summary>
        /// <param name="difficultyid"></param>
        /// <param name="technoid"></param>
        /// <param name="userid"></param>
        /// <param name="nomuser"></param>
        /// <param name="prenomuser"></param>
        /// <param name="questionlibre"></param>
        /// <param name="nombrequestions"></param>
        public Quizz CreateQuizz(QuizzViewModel quizzViewModel, int difficultymasterid)
        {
            Quizz unQuizz = null;

            using (FilRougeDBContext db = new FilRougeDBContext())
            {
                var quizz = quizzViewModel.MapToQuizz();

                List <Questions> questionsQuizz = AddQuestionToQuizz(quizz.QuestionLibre, quizz.NombreQuestion, quizz.TechnologyId, difficultymasterid, db);
                int timer = quizz.Timer;


                try
                {
                    //TODO creer un viewbag des users => authorize create quizz
                    // verifier paramètres de création d'un quizz
                    Contact    creatingQuizzContact = db.Users.Single(e => e.Id == quizz.ContactId);
                    Difficulty difficultyQuizz      = db.Difficulties.Single(e => e.DifficultyId == difficultymasterid);
                    Technology technoQuizz          = db.Technologies.Single(e => e.TechnoId == quizz.TechnologyId);

                    unQuizz = new Quizz
                    {
                        ContactId      = creatingQuizzContact.Id,
                        DifficultyId   = difficultymasterid,
                        TechnologyId   = quizz.TechnologyId,
                        Timer          = quizz.Timer,
                        PrenomUser     = quizz.PrenomUser,
                        NomUser        = quizz.NomUser,
                        NombreQuestion = quizz.NombreQuestion,
                        EtatQuizz      = quizz.EtatQuizz,
                        QuestionLibre  = quizz.QuestionLibre,
                        Contact        = creatingQuizzContact,
                        Difficulty     = difficultyQuizz,
                        Questions      = questionsQuizz,
                        Technology     = technoQuizz
                    };
                    db.Quizz.Add(unQuizz);
                    db.SaveChanges();
                    db.Dispose();
                }
                catch (AlreadyInTheQuestionsList e)
                {
                    Console.WriteLine(e.Message);
                    db.Dispose();
                }
                catch (NoQuestionsForYou e)
                {
                    Console.WriteLine(e.Message);
                    db.Dispose();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            return(unQuizz);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="difficultyid"></param>
        /// <param name="technoid"></param>
        /// <param name="userid"></param>
        /// <param name="nomuser"></param>
        /// <param name="prenomuser"></param>
        /// <param name="questionlibre"></param>
        /// <param name="nombrequestions"></param>
        public static void CreateQuizz(int userid, int difficultymasterid, int technoid, string nomuser, string prenomuser, bool questionlibre, int nombrequestions)
        {
            List <Question>   questionsQuizz = AddQuestionToQuizz(questionlibre, nombrequestions, technoid, difficultymasterid);
            int               timer          = 0;
            FilRougeDBContext db             = new FilRougeDBContext();

            try
            {
                Contact        creatingQuizzContact = db.Contact.Single(e => e.UserId == userid);
                DifficultyRate difficultyQuizz      = db.DifficultyMaster.Single(e => e.DiffMasterId == difficultymasterid);
                Technology     technoQuizz          = db.Technology.Single(e => e.TechnoId == technoid);

                Quizz unQuizz = new Quizz
                {
                    ContactId          = userid,
                    DifficultyMasterId = difficultymasterid,
                    TechnologyId       = technoid,
                    Timer            = timer,
                    PrenomUser       = prenomuser,
                    NomUser          = nomuser,
                    NombreQuestion   = nombrequestions,
                    EtatQuizz        = 0,
                    QuestionLibre    = questionlibre,
                    Contact          = creatingQuizzContact,
                    DifficultyMaster = difficultyQuizz,
                    Questions        = questionsQuizz,
                    Technology       = technoQuizz
                };
                db.SaveChanges();
                db.Dispose();
            }
            catch (AlreadyInTheQuestionsList e)
            {
                Console.WriteLine(e.Message);
                db.Dispose();
            }
            catch (NoQuestionsForYou e)
            {
                Console.WriteLine(e.Message);
                db.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                db.Dispose();
            }
        }
Example #4
0
        public Technology GetTechnologyById(int id)
        {
            FilRougeDBContext db = new FilRougeDBContext();
            var fluentQuery      = db.Technology.Single(e => e.TechnoId == id);

            db.Dispose();
            return(fluentQuery);
        }
Example #5
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Example #6
0
        }                         //Constructeur

        #region Methods

        /// <summary>
        /// Méthode permettant d'obtenir un quizz en fonction de son id
        /// Fonctionne avec une fluentQuerry
        /// </summary>
        /// <param name="id">l'ID du quizz (sa clé primaire)</param>
        /// <returns>Retourne un objet Quizz</returns>
        public Quizz GetQuizz(int id)
        {
            Quizz             fluentQuery = new Quizz();
            FilRougeDBContext db          = new FilRougeDBContext();

            try
            {
                fluentQuery = db.Quizz.Single(e => e.QuizzId == id);
                if (fluentQuery == null)
                {
                    throw new WrongIdQuizz(id);
                }
                db.Dispose();
            }
            catch (FormatException e)
            {
                db.Dispose();
                Console.WriteLine(e.Message);
            }
            return(fluentQuery);
        }
        }                         //Constructeur

        #region Methods

        /// <summary>
        /// Méthode permettant d'obtenir un quizz en fonction de son id
        /// Fonctionne avec une fluentQuerry
        /// </summary>
        /// <param name="id">l'ID du quizz (sa clé primaire)</param>
        /// <returns>Retourne un objet Quizz</returns>
        public Quizz GetQuizz(int id)
        {
            Quizz             fluentQuery = new Quizz();
            FilRougeDBContext db          = new FilRougeDBContext();

            try
            {
                fluentQuery = db.Quizz.Single(e => e.QuizzId == id);
                if (fluentQuery == null)
                {
                    throw new WrongIdQuizz("L'id saisie n'existe pas");
                }
                db.Dispose();
            }
            catch (FormatException)
            {
                db.Dispose();
                Console.WriteLine("Veuillez saisir un id valide");
            }
            return(fluentQuery);
        }
Example #8
0
        /// <summary>
        /// Cette méthode permet de récupérer toutes les difficultés
        /// Fonctionne avec une fluentQuerry
        /// </summary>
        /// <returns>Retourne une liste d'objets Diffulties</returns>
        public List <DifficultyRate> GetDifficulties()
        {
            List <DifficultyRate> desDifficulties = new List <DifficultyRate>();
            FilRougeDBContext     db = new FilRougeDBContext();
            var fluentQuery          = db.DifficultyMaster.Select(e => e);

            foreach (var item in fluentQuery)
            {
                desDifficulties.Add(item);
            }
            db.Dispose();
            return(desDifficulties);
        }
Example #9
0
        /// <summary>
        /// Cette fonction permet d'obtenir toutes les technologies
        /// Fonctionne avec une fluentQuerry
        /// </summary>
        /// <returns>Retourne une liste d'objets Technologies</returns>
        public List <Technology> GetTechnologies()
        {
            List <Technology> desTechnologies = new List <Technology>();
            FilRougeDBContext db = new FilRougeDBContext();
            var fluentQuery      = db.Technology.Select(e => e);

            foreach (var item in fluentQuery)
            {
                desTechnologies.Add(item);
            }
            db.Dispose();
            return(desTechnologies);
        }
Example #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="questionsQuizz"></param>
        /// <param name="lesQuestions"></param>
        /// <param name="questionlibre"></param>
        /// <param name="nombrequestions"></param>
        /// <returns></returns>
        ///

        public static List <Question> AddQuestionToQuizz(bool questionlibre, int nombrequestions, int technoid, int difficultymasterid)
        {
            Random          rand = new Random();
            List <Question> sortedQuestionsQuizz = new List <Question>();

            FilRougeDBContext db = new FilRougeDBContext();

            try
            {
                //Requêtes Linq
                int nbrTotalQuestions = db.Question.Select(e => e).Count();
                IQueryable <Question>     AllQuestionsByTechno = db.Question.Where(e => e.TechnologyId == technoid);
                IQueryable <TypeQuestion> TypesQuestions       = db.TypeQuestion.Select(e => e);

                //Génération de la liste de questions en fonction des paramètres
                foreach (var rate in RatesQuizz)
                {//Pour gérer la répartition des questions dans le quizz
                    for (int i = 0; i < Math.Floor(); i++)
                    {
                        //pas encore utilisé
                        IQueryable <Question> QuestionByType = AllQuestionsByTechno.Where(e => e.TypeQuestion.NameType == "Question libre");
                        foreach (var question in QuestionByType)
                        {//Vérification par id de la présence d'une question
                            if (question.QuestionId == rand.Next(0, nbrTotalQuestions))
                            {
                                foreach (var newQuestion in sortedQuestionsQuizz)
                                {
                                    //Gestion des doublons
                                    if (question.QuestionId != newQuestion.QuestionId)
                                    {
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                db.Dispose();
            }


            return(sortedQuestionsQuizz);
        }
Example #11
0
        /// <summary>
        /// Ajouter une question dans le Quizz.
        /// </summary>
        /// <param name="questionsQuizz"></param>
        /// <param name="lesQuestions"></param>
        /// <param name="questionlibre"></param>
        /// <param name="nombrequestions"></param>
        /// <returns></returns>
        public static List <Questions> AddQuestionToQuizz(bool questionlibre, int nombrequestions, int technoid, int difficultymasterid)
        {
            Random           rand = new Random();
            List <Questions> sortedQuestionsQuizz = new List <Questions>();

            FilRougeDBContext db = new FilRougeDBContext();

            try
            {
                int nbrTotalQuestions = db.Questions.Select(e => e).Count();
                IQueryable <Questions>      AllQuestionsByTechno = db.Questions.Where(e => e.TechnologyId == technoid && e.Active);
                IQueryable <DifficultyRate> RatesQuizz           = db.DifficultyRates.Where(e => e.DifficultyMasterId == difficultymasterid);

                foreach (var rate in RatesQuizz)
                {//Pour gérer la répartition des questions dans le quizz
                    for (int i = 0; i < Math.Floor(nombrequestions * rate.Rate); i++)
                    {
                        foreach (var question in AllQuestionsByTechno)
                        {//Vérification par id de la présence d'une question
                            if (!(sortedQuestionsQuizz.Contains(question)))
                            {
                                sortedQuestionsQuizz.Add(question);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                db.Dispose();
            }


            return(sortedQuestionsQuizz);
        }