/// <summary> /// 提交问卷 /// </summary> /// <param name="resultVO"></param> /// <returns></returns> public ResultVO SubmitSurvey(SurveyResultVO resultVO) { ResultVO result = new ResultVO() { Result = 0 }; try { using (TransactionScope trans = new TransactionScope()) { RespondentInfo respondent = new RespondentInfo() { RespondentName = resultVO.Username, MobilePhone = resultVO.Mobile, Age = resultVO.Age, Gender = resultVO.Gender == 0 ? null : (resultVO.Gender == 1 ? "男" : "女"), EduBackground = string.IsNullOrEmpty(GetEduString(resultVO.Edu)) ? null : GetEduString(resultVO.Edu), Location = resultVO.Location, MaritalStatus = string.IsNullOrEmpty(GetMaritalString(resultVO.Marital)) ? null : GetMaritalString(resultVO.Marital), Referrer = resultVO.Refer, Suggestion = resultVO.Suggestion, CreateTime = CurrentServerTime, Deleted = false, Occupation = string.IsNullOrEmpty(GetPosString(resultVO.Position)) ? null : GetPosString(resultVO.Position) }; var insertedResp = _respondentInfoRepository.Insert(respondent); _unitOfWork.Commit(); var tmpOpt = resultVO.Options.Split(',').ToList().FindAll(o => o.Contains("#")); tmpOpt.ForEach(o => { var questionId = Convert.ToInt32(o.Split('#')[0]); var questionAns = o.Split('#')[1]; SurveyResult surveyResult = new SurveyResult() { SurveyId = resultVO.SurveyId, RespondentId = insertedResp.RespondentId, QuestionId = questionId, SelectedOptions = questionAns, CreateTime = CurrentServerTime }; _surveyResultRepository.Insert(surveyResult); _unitOfWork.Commit(); }); trans.Complete(); result.Result = 1; } } catch (Exception ex) { result.ErrorMsg = ex.Message; } return(result); }
public ResultVO SubmitSurvey(SurveyResultVO result) { var res = _surveyInfoService.SubmitSurvey(result); return(res); }