Exemple #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));
        }
Exemple #2
0
        public SurveyedDto InsertEntity(SurveyedDto request)
        {
            try
            {
                var entity = AutoMapper.Mapper.Map <Surveyed>(request);
                entity.AnswerList   = null;
                entity.BranchOffice = branchOfficeRepository.Get(entity.BranchOffice.Id);

                entity.PersonSurveyed = personSurveyedRepository.Insert(entity.PersonSurveyed);
                entity            = entityRepository.Insert(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 = answerRepository.Insert(answer);
                    entity.AnswerList.Add(answer);
                }

                return(AutoMapper.Mapper.Map <SurveyedDto>(entity));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #3
0
        public async Task <SurveyedDto> Delete(SurveyedDto request)
        {
            var entity = AutoMapper.Mapper.Map <Surveyed>(request);

            request.IsDeleted = true;

            var result = await entityRepository.UpdateAsync(entity);

            return(AutoMapper.Mapper.Map <SurveyedDto>(result));
        }