Exemplo n.º 1
0
        public async Task <SurveyedDto> Insert(SurveyedDto request)
        {
            var entity = AutoMapper.Mapper.Map <Surveyed>(request);

            entity.AnswerList   = null;
            entity.BranchOffice = branchOfficeRepository.Get(entity.BranchOffice.Id);

            entity.PersonSurveyed = await personSurveyedRepository.InsertAsync(entity.PersonSurveyed);

            entity = await entityRepository.InsertAsync(entity);

            entity.AnswerList = new List <Answer>();

            foreach (var answerDto in request.AnswerList)
            {
                var answer = AutoMapper.Mapper.Map <Answer>(answerDto);
                answer.Surveyed       = entity;
                answer.Question       = questionRepository.Get(answer.Question.Id);
                answer.QuestionOption = questionOptionRepository.Get(answer.QuestionOption.Id);
                answer.QuestionType   = questionTypeRepository.Get(answer.QuestionType.Id);

                answer = await answerRepository.InsertAsync(answer);

                entity.AnswerList.Add(answer);
            }

            return(AutoMapper.Mapper.Map <SurveyedDto>(entity));
        }
Exemplo n.º 2
0
        public int Add(Question item)
        {
            if (string.IsNullOrEmpty(item.Text))
            {
                return(0);
            }
            if (item.Text.Count() > 300)
            {
                return(0);
            }

            var questionType = _qtrepository.Get(item.QuestionTypeId);

            if (questionType == null)
            {
                return(0);
            }

            int id = _repository.Add(item);

            return(id);
        }
Exemplo n.º 3
0
 public QuestionType Get(int id)
 {
     return(_repository.Get(id));
 }