示例#1
0
        /// <summary>
        ///     Retourne un Level
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        internal FindLevelDto GetLevelById(int id)
        {
            Level lev = LevelRepository.Find(id);

            if (lev.IdLevel == null)
            {
                throw new HttpResponseException(HttpStatusCode.OK);
            }
            return(TransformModelToDto(lev));
        }
        private FindCandidateDto TransformModelToDto(Candidate candidat)
        {
            LevelRepository repo = new LevelRepository(new QueryBuilder());

            return(new FindCandidateDto(
                       candidat.idCandidate,
                       candidat.firstname,
                       candidat.lastname,
                       candidat.email,
                       (repo.Find((int)candidat.idLevel)).NameLevel,
                       (int)candidat.idUser));
        }
        /// <summary>
        ///     Transforme le model d'un quizz en dto pour un candidat, sans les réponses
        /// </summary>
        /// <param name="quizz">Quizz à transformer</param>
        /// <returns>FindQuizzCandidateDto</returns>
        private FindQuizzCandidateDto TransformModelToDtoCandidate(Quizz quizz)
        {
            CategoryRepository      repoCat    = new CategoryRepository(new QueryBuilder());
            LevelRepository         repoLev    = new LevelRepository(new QueryBuilder());
            QuizzQuestionRepository quizzQRepo = new QuizzQuestionRepository(new QueryBuilder());

            return(new FindQuizzCandidateDto(
                       quizz.idQuizz,
                       quizz.codeQuizz,
                       quizz.date,
                       repoCat.Find((int)quizz.idCategory).NameCategory,
                       repoLev.Find((int)quizz.idLevel).NameLevel,
                       quizz.idUser,
                       quizz.idCandidate,
                       ReturnQuestionsCandidateQuizz(quizzQRepo.FindAll((int)quizz.idQuizz))
                       ));
        }
        /// <summary>
        /// Converti un Model en DTO
        /// </summary>
        /// <param name="question"></param>
        /// <returns>Une question en DTO</returns>
        private FindQuestionsDto TransformsModelToDTO(Question question, FindAnswerDto answer = null)
        {
            LevelRepository    lvlRepo = new LevelRepository(new QueryBuilder());
            CategoryRepository catRepo = new CategoryRepository(new QueryBuilder());

            // Si answer est inconnu alors aller le récupérer à l'aide de service answer et rappel la méthode
            if (answer == null)
            {
                return(TransformsModelToDTO(question, AnswerServices.GetAnswerById((int)question.IdAnswer)));
            }
            return(new FindQuestionsDto(
                       question.IdQuestion,
                       question.Intitule,
                       catRepo.Find((int)question.IdCategory).NameCategory,
                       lvlRepo.Find((int)question.IdLevel).NameLevel,
                       answer
                       ));
        }
        /// <summary>
        ///     Transforme l'id level par son nom
        /// </summary>
        /// <param name="id">identifiant de Level</param>
        /// <returns>son du level</returns>
        public string TransformeIdLevelToString(int id)
        {
            LevelRepository repo = new LevelRepository(new QueryBuilder());

            return(repo.Find(id).NameLevel);
        }