public async Task <UnifyResponseDto> Post(CreateSurveyDTO model) { if (await _service.CreateSureveyAsync(model)) { return(UnifyResponseDto.Sucess("添加成功")); } return(UnifyResponseDto.Fail()); }
public ActionResult AddSurvey(CreateSurveyDTO survey) { var newSurvey = _mapper.Map <Survey>(survey); newSurvey.SetCreationDateNow(); _surveyRepository.Insert(newSurvey); _surveyRepository.Save(); _surveyRepository.GetById(newSurvey.Id); return(CreatedAtAction(nameof(GetSurvey), new { id = newSurvey.Id }, _mapper.Map <SurveyDTO>(newSurvey))); }
public async Task <bool> CreateSureveyAsync(CreateSurveyDTO surveyDTO) { Survey survey = _mapper.Map <Survey>(surveyDTO); IList <Subject> subjects = _mapper.Map <List <Subject> >(surveyDTO.SubjectDTOs); survey.Subjects = subjects; foreach (var subject in subjects) { subject.Options = _mapper.Map <List <Option> >(surveyDTO.OptionDTOs.Where(x => x.SubjectIndex == subject.Index).ToList()); } await _repository.InsertAsync(survey); return(await _unitOfWork.CommitAsync()); }