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)); }
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; } }
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)); }