public QuestionEntity ToEntity(ProfessionalQualitiesDbContext dbContext, int order, bool areAnswerOptionsUnique = true)
        {
            QuestionEntity entity = new QuestionEntity
            {
                Order       = order,
                Formulation = Formulation
            };

            if (areAnswerOptionsUnique)
            {
                var answerOptionEntities = AnswerOptions.Select(ao => ao.ToEntity(dbContext)).ToList();
                for (int i = 0; i < answerOptionEntities.Count; ++i)
                {
                    dbContext.QuestionsAnswerOptions.Add(new QuestionAnswerOption
                    {
                        Question     = entity,
                        AnswerOption = answerOptionEntities[i],
                        Order        = i
                    });
                }
            }
            dbContext.Questions.Add(entity);

            return(entity);
        }
        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);
                }
            }
        }
        public override TestEntity ToEntity(ProfessionalQualitiesDbContext dbContext)
        {
            var entity = base.ToEntity(dbContext);

            entity.Instruction            = Instruction;
            entity.AreAnswerOptionsUnique = GeneralAnswerOptions.Count() == 0;

            if (entity.AreAnswerOptionsUnique)
            {
                entity.Questions = Questions.Select((question, index) => question.ToEntity(dbContext, index)).ToList();
            }
            else
            {
                entity.Questions = Questions.Select((question, index) => question.ToEntity(dbContext, index, false)).ToList();
                var generalAnswerOptionEntities = GeneralAnswerOptions.Select(ao => ao.ToEntity(dbContext)).ToList();

                for (int i = 0; i < generalAnswerOptionEntities.Count; ++i)
                {
                    dbContext.TestsAnswerOptions.Add(new TestAnswerOption
                    {
                        Test         = entity,
                        Order        = i,
                        AnswerOption = generalAnswerOptionEntities[i]
                    });
                }
            }

            return(entity);
        }
Пример #4
0
        public UserEntity ToEntity(ProfessionalQualitiesDbContext dbContext)
        {
            var entity = new UserEntity
            {
                Id       = Id,
                Login    = Login,
                Password = Password,
                Role     = GetRoleEntity(dbContext),
                Deleted  = false,

                PersonalData = new PersonalDataEntity
                {
                    Name             = Name,
                    IsMale           = (Gender == Constants.MaleGenderString),
                    Birthday         = Birthday,
                    ExpertAssessment = ExpertAssessment
                }
            };

            if (ProfessionName != null && ProfessionName.Length > 0)
            {
                entity.PersonalData.Profession = GetProfessionEntity(dbContext);
            }
            else
            {
                entity.PersonalData.Profession = null;
            }

            return(entity);
        }
Пример #5
0
 private IEnumerable <EvaluationMapEntity> GetEvaluationMapEntity(ProfessionalQualitiesDbContext dbContext,
                                                                  TestEntity testEntity, ScaleEntity scaleEntity)
 {
     foreach (var appraisedRange in EvaluationMap)
     {
         yield return(appraisedRange.ToEntity(dbContext, testEntity, scaleEntity));
     }
 }
Пример #6
0
 private RoleEntity GetRoleEntity(ProfessionalQualitiesDbContext dbContext)
 {
     if (!dbContext.Roles.Any(re => re.Name == RoleName))
     {
         RoleName = Constants.DefaultRoleString;
     }
     return(dbContext.Roles.Single(re => re.Name == RoleName));
 }
Пример #7
0
        public override TestEntity ToEntity(ProfessionalQualitiesDbContext dbContext)
        {
            var entity = base.ToEntity(dbContext);

            foreach (var scale in Scales)
            {
                scale.ToEntity(dbContext, entity);
            }
            return(entity);
        }
Пример #8
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);
         }
     }
 }
        public AnswerOptionEntity ToEntity(ProfessionalQualitiesDbContext dbContext)
        {
            var entity = dbContext.AnswerOptions
                         .SingleOrDefault(aoe => aoe.Formulation == Formulation);

            if (entity == null)
            {
                entity = new AnswerOptionEntity
                {
                    Formulation = Formulation
                };
                dbContext.AnswerOptions.Add(entity);
                dbContext.SaveChanges();
            }

            return(entity);
        }
Пример #10
0
        private ProfessionEntity GetProfessionEntity(ProfessionalQualitiesDbContext dbContext)
        {
            var professionEntity = dbContext.Professions
                                   .SingleOrDefault(pe => pe.Name == ProfessionName);

            if (professionEntity == null)
            {
                professionEntity = new ProfessionEntity
                {
                    Name = ProfessionName
                };
                dbContext.Professions.Add(professionEntity);
                dbContext.SaveChanges();
            }

            return(professionEntity);
        }
Пример #11
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);
        }