public IEnumerable <KeyEntity> ToEntities(ProfessionalQualitiesDbContext dbContext,
                                                  TestEntity testEntity, ScaleEntity scaleEntity)
        {
            var questionEntities     = testEntity.Questions;
            var answerOptionEntities = new List <AnswerOptionEntity>();

            if (!testEntity.AreAnswerOptionsUnique)
            {
                answerOptionEntities = testEntity.TestAnswerOptions.Select(tao => tao.AnswerOption).ToList();
            }

            foreach (var questionIndex in QuestionIndexes)
            {
                var questionEntity = questionEntities[questionIndex];
                if (testEntity.AreAnswerOptionsUnique)
                {
                    answerOptionEntities = questionEntity.QuestionAnswerOptions.Select(qao => qao.AnswerOption).ToList();
                }

                foreach (var answerOptionIndex in AnswerOptionIndexes)
                {
                    var keyEntity = new KeyEntity
                    {
                        Test     = testEntity,
                        Scale    = scaleEntity,
                        Question = questionEntity,
                        Answer   = answerOptionEntities[answerOptionIndex],
                        Points   = Points
                    };
                    dbContext.Keys.Add(keyEntity);

                    yield return(keyEntity);
                }
            }
        }
Пример #2
0
        private IEnumerable <PartOfKey> MakeKey(ScaleEntity scaleEntity, TestEntity testEntity)
        {
            var keyEntites = testEntity.Key
                             .Where(ke => ke.ScaleId == scaleEntity.Id);
            var evaluatedAnswers = KeyToEvaluatedAnswers(keyEntites, testEntity);

            if (testEntity.AreAnswerOptionsUnique)
            {
                var groupedEvaluatedAnswers = evaluatedAnswers
                                              .GroupBy(ea => new { ea.QuestionIndex, ea.Points }, ea => ea.AnswerIndex);

                foreach (var group in groupedEvaluatedAnswers)
                {
                    var answerOptionIndexes = new List <int>();

                    foreach (var answerOptionIndex in group)
                    {
                        answerOptionIndexes.Add(answerOptionIndex);
                    }

                    yield return(new PartOfKey
                    {
                        QuestionIndexes = new List <int> {
                            group.Key.QuestionIndex
                        },
                        AnswerOptionIndexes = answerOptionIndexes.OrderBy(idx => idx),
                        Points = group.Key.Points
                    });
                }
            }
            else
            {
                var groupedEvaluatedAnswers = evaluatedAnswers
                                              .GroupBy(ea => new { ea.AnswerIndex, ea.Points }, ea => ea.QuestionIndex);

                foreach (var group in groupedEvaluatedAnswers)
                {
                    var questionIndexes = new List <int>();

                    foreach (var questionIndex in group)
                    {
                        questionIndexes.Add(questionIndex);
                    }

                    yield return(new PartOfKey
                    {
                        AnswerOptionIndexes = new List <int> {
                            group.Key.AnswerIndex
                        },
                        QuestionIndexes = questionIndexes.OrderBy(idx => idx),
                        Points = group.Key.Points
                    });
                }
            }
        }
Пример #3
0
 private IEnumerable <KeyEntity> GetKeyEntity(ProfessionalQualitiesDbContext dbContext,
                                              TestEntity testEntity, ScaleEntity scaleEntity)
 {
     foreach (var partOfKey in Key)
     {
         var keyEntities = partOfKey.ToEntities(dbContext, testEntity, scaleEntity);
         foreach (var keyEntity in keyEntities)
         {
             yield return(keyEntity);
         }
     }
 }
Пример #4
0
        public ScaleEntity ToEntity(ProfessionalQualitiesDbContext dbContext, TestEntity testEntity)
        {
            ScaleEntity scaleEntity = new ScaleEntity();

            if (dbContext.Scales.Any(se => se.Name == Name))
            {
                scaleEntity = dbContext.Scales
                              .Single(se => se.Name == Name);
            }
            else
            {
                scaleEntity.Name = Name;
                dbContext.Scales.Add(scaleEntity);
            }

            GetKeyEntity(dbContext, testEntity, scaleEntity).ToList();
            GetEvaluationMapEntity(dbContext, testEntity, scaleEntity).ToList();

            return(scaleEntity);
        }
Пример #5
0
        public Scale(ScaleEntity scaleEntity, TestEntity testEntity)
        {
            Id   = scaleEntity.Id;
            Name = scaleEntity.Name;

            Key = MakeKey(scaleEntity, testEntity);
            if (testEntity.AreAnswerOptionsUnique)
            {
                Key = Key.OrderBy(pok => pok.QuestionIndexes.First());
            }
            else
            {
                Key = Key.OrderBy(pok => pok.AnswerOptionIndexes.First());
            }

            EvaluationMap = testEntity.EvaluationMap
                            .Where(eme => eme.ScaleId == Id)
                            .Select(eme => new AppraisedRange(eme))
                            .OrderBy(ar => ar.LowerRangeValue)
                            .OrderBy(ar => ar.UpperRangeValue);
        }
Пример #6
0
 private IEnumerable <EvaluationMapEntity> GetEvaluationMapEntity(ProfessionalQualitiesDbContext dbContext,
                                                                  TestEntity testEntity, ScaleEntity scaleEntity)
 {
     foreach (var appraisedRange in EvaluationMap)
     {
         yield return(appraisedRange.ToEntity(dbContext, testEntity, scaleEntity));
     }
 }