Ejemplo n.º 1
0
        private void CopyDataRelImage(RelQuestionImageDto dto, RelQuestionImage entity)
        {
            RelQuestionImageDto dtoSource         = dto;
            RelQuestionImage    entityDestination = entity;

            entityDestination.IdQuestion = dtoSource.IdQuestion;
            entityDestination.IdImage    = dtoSource.IdImage;
        }
Ejemplo n.º 2
0
        protected virtual void CreateMockQuestion(ApplicationDbContext context, int id, IList <Tag> tags)
        {
            Question question = new Question()
            {
                Explanation = $"Explanation{id}",
                Text        = $"Text{id}",
                User        = new CranUser()
                {
                    UserId = $"UserId{id}",
                },
                Container = new Container()
                {
                },
                Status       = QuestionStatus.Released,
                Language     = Language.De,
                QuestionType = QuestionType.MultipleChoice,
            };

            context.Questions.Add(question);

            //Options
            for (int i = 1; i <= 4; i++)
            {
                QuestionOption option = new QuestionOption()
                {
                    IdQuestion = question.Id,
                    Text       = $"OptionText{i}",
                    IsTrue     = i % 2 == 0,
                    Question   = question,
                };
                question.Options.Add(option);
                context.QuestionOptions.Add(option);
            }

            //Tags
            foreach (Tag tag in tags.Where(x => x.TagType == TagType.Standard))
            {
                RelQuestionTag relTag = new RelQuestionTag
                {
                    Question = question,
                    Tag      = tag,
                };
                context.RelQuestionTags.Add(relTag);
            }

            //Binary
            for (int i = 1; i <= 3; i++)
            {
                Binary binary = new Binary()
                {
                    ContentType        = "image/png",
                    FileName           = $"Filename{i + id * 1000}",
                    ContentDisposition = $"form-data; name=\"files\"; filename=\"Untitled.png\"",
                    Length             = 20618,
                };
                context.Binaries.Add(binary);

                Image image = new Image()
                {
                    Binary = binary,
                    Height = 300,
                };
                context.Images.Add(image);

                RelQuestionImage relQuestionImage = new RelQuestionImage
                {
                    Question = question,
                    Image    = image,
                };
                context.RelQuestionImages.Add(relQuestionImage);
            }

            context.SaveChanges();
        }
Ejemplo n.º 3
0
 protected virtual void CopyData(object dto, CranEntity entity)
 {
     if (dto is QuestionOptionDto && entity is QuestionOption)
     {
         QuestionOptionDto dtoSource         = (QuestionOptionDto)dto;
         QuestionOption    entityDestination = (QuestionOption)entity;
         entityDestination.IsTrue     = dtoSource.IsTrue;
         entityDestination.Text       = dtoSource.Text ?? string.Empty;
         entityDestination.IdQuestion = dtoSource.IdQuestion;
     }
     else if (dto is QuestionDto && entity is Question)
     {
         QuestionDto dtoSource         = (QuestionDto )dto;
         Question    entityDestination = (Question)entity;
         entityDestination.Title        = dtoSource.Title;
         entityDestination.Text         = dtoSource.Text ?? string.Empty;
         entityDestination.Explanation  = dtoSource.Explanation;
         entityDestination.QuestionType = dtoSource.QuestionType;
         entityDestination.Language     = Enum.Parse <Language>(dtoSource.Language);
     }
     else if (dto is RelQuestionTagDto && entity is RelQuestionTag)
     {
         RelQuestionTagDto dtoSource         = (RelQuestionTagDto)dto;
         RelQuestionTag    entityDestination = (RelQuestionTag)entity;
         entityDestination.IdQuestion = dtoSource.IdQuestion;
         entityDestination.IdTag      = dtoSource.IdTag;
     }
     else if (dto is RelQuestionImageDto && entity is RelQuestionImage)
     {
         RelQuestionImageDto dtoSource         = (RelQuestionImageDto)dto;
         RelQuestionImage    entityDestination = (RelQuestionImage)entity;
         entityDestination.IdQuestion = dtoSource.IdQuestion;
         entityDestination.IdImage    = dtoSource.IdImage;
     }
     else if (dto is ImageDto && entity is Image)
     {
         ImageDto dtoSource         = (ImageDto)dto;
         Image    entityDestination = (Image)entity;
         entityDestination.Width  = dtoSource.Width;
         entityDestination.Height = dtoSource.Height;
         entityDestination.Full   = dtoSource.Full;
     }
     else if (dto is CourseDto && entity is Course)
     {
         CourseDto dtoSource         = (CourseDto)dto;
         Course    entityDestination = (Course)entity;
         entityDestination.Title             = dtoSource.Title;
         entityDestination.Language          = Enum.Parse <Language>(dtoSource.Language);
         entityDestination.NumQuestionsToAsk = dtoSource.NumQuestionsToAsk;
         entityDestination.Description       = dtoSource.Description;
     }
     else if (dto is RelCourseTagDto && entity is RelCourseTag)
     {
         RelCourseTagDto dtoSource         = (RelCourseTagDto)dto;
         RelCourseTag    entityDestination = (RelCourseTag)entity;
         entityDestination.IdCourse = dtoSource.IdCourse;
         entityDestination.IdTag    = dtoSource.IdTag;
     }
     else
     {
         throw new NotImplementedException();
     }
 }