/// <summary> /// 插入新调查问卷 /// </summary> /// <returns></returns> public ResultVO InsertSurvey(SurveyVO survey) { ResultVO result = new ResultVO() { Result = 0 }; try { using (TransactionScope trans = new TransactionScope()) { var surveyInfo = survey.SurveyInfo; var questionInfo = survey.QuestionInfo; var requireInfo = survey.RequiredInfo; var userInfo = _userInfoRepository.LoadEntities(u => u.UserName == survey.UserName && u.Deleted == false) .FirstOrDefault(); _unitOfWork.Commit(); surveyInfo.TmplId = survey.TemplateId; //初始化数据 surveyInfo.CreateTime = base.CurrentServerTime; surveyInfo.Deleted = false; surveyInfo.CreateId = userInfo.UserId; surveyInfo.StaticUrl = String.Format("{0}/{1}", "statics", CurrentServerTime.ToString("yyyyMMddHHmmss") + ".html"); surveyInfo.RequiredInfos = string.Join(",", survey.RequiredInfo.ToArray()); var insertedSurveyInfo = _surveyInfoRepository.Insert(surveyInfo); _unitOfWork.Commit(); var insertedQuestion = new QuestionInfo(); var insertedOpt = new OptionInfo(); questionInfo.ForEach(q => { var question = new QuestionInfo() { SurveyId = insertedSurveyInfo.SurveyId, QuestionTitle = q.QuestionTitle, IsOrientation = q.IsOrientation, QuestionOptionsCount = q.QuestionOptionsCount, RequiredOptionsCount = q.IsOrientation == false ? 0 : q.RequiredOptionsCount, Deleted = false }; insertedQuestion = _quesionInfoRepository.Insert(question); _unitOfWork.Commit(); q.Options.ForEach(o => { o.Deleted = false; o.QuesionId = insertedQuestion.QuestionId; insertedOpt = _optionInfoRepository.Insert(o); _unitOfWork.Commit(); }); }); var insertedQuestionList = _quesionInfoRepository.LoadEntities(q => q.SurveyId == insertedSurveyInfo.SurveyId).ToList(); var quesionList = new List <QuestionVO>(); insertedQuestionList.ForEach(q => quesionList.Add(new QuestionVO { QuesionId = q.QuestionId, QuestionTitle = q.QuestionTitle, IsOrientation = q.IsOrientation, QuestionOptionsCount = q.QuestionOptionsCount, RequiredOptionsCount = q.RequiredOptionsCount, Options = _optionInfoRepository.LoadEntities(o => o.QuesionId == q.QuestionId).ToList() })); var tmplInfo = _templateRepository.LoadEntities(t => t.TmplId == insertedSurveyInfo.TmplId).FirstOrDefault(); var arr = tmplInfo.StoredName.Split('\\'); var tmplFolder = arr[arr.Length - 1]; var surveyTmplObj = new { QuestionInfo = quesionList, SurveyInfo = insertedSurveyInfo, RequiredInfo = survey.RequiredInfo, TemplateFolderName = tmplFolder, isExample = 0 }; StaticPageHelper.GenerateHtml(surveyTmplObj, "wapTmpl.html", survey.SurveyInfo.StaticUrl.Split("/".ToCharArray())[1].Split('.')[0]); trans.Complete(); result.Result = 1; } } catch (Exception ex) { result.ErrorMsg = ex.Message; } return(result); }
/// <summary> /// 更新问卷信息 /// </summary> /// <param name="survey"></param> /// <returns></returns> public ResultVO UpdateSurveyInfo(SurveyVO survey) { ResultVO result = new ResultVO() { Result = 0 }; try { using (TransactionScope tran = new TransactionScope()) { survey.SurveyInfo.TmplId = survey.TemplateId; _surveyInfoRepository.Update(survey.SurveyInfo); _unitOfWork.Commit(); survey.QuestionInfo.ForEach(q => { var tmpQuestion = new QuestionInfo() { QuestionId = q.QuesionId, QuestionOptionsCount = q.QuestionOptionsCount, QuestionTitle = q.QuestionTitle, IsOrientation = q.IsOrientation, SurveyId = survey.SurveyInfo.SurveyId, RequiredOptionsCount = q.IsOrientation == false ? 0 : q.RequiredOptionsCount }; _quesionInfoRepository.Update(tmpQuestion); _unitOfWork.Commit(); q.Options.ForEach(o => { var tmpOpt = new OptionInfo() { QuesionId = q.QuesionId, OptionId = o.OptionId, OptionKey = o.OptionKey, OptionValue = o.OptionValue }; _optionInfoRepository.Update(tmpOpt); _unitOfWork.Commit(); }); }); var surveyInfo = _surveyInfoRepository.LoadEntities(s => s.SurveyId == survey.SurveyInfo.SurveyId) .FirstOrDefault(); var insertedQuestionList = _quesionInfoRepository.LoadEntities(q => q.SurveyId == survey.SurveyInfo.SurveyId).ToList(); var quesionList = new List <QuestionVO>(); insertedQuestionList.ForEach(q => quesionList.Add(new QuestionVO { QuesionId = q.QuestionId, QuestionTitle = q.QuestionTitle, QuestionOptionsCount = q.QuestionOptionsCount, RequiredOptionsCount = q.RequiredOptionsCount, Options = _optionInfoRepository.LoadEntities(o => o.QuesionId == q.QuestionId).ToList() })); var tmplInfo = _templateRepository.LoadEntities(t => t.TmplId == survey.SurveyInfo.TmplId).FirstOrDefault(); var arr = tmplInfo.StoredName.Split('\\'); var tmplFolder = arr[arr.Length - 1]; var surveyTmplObj = new { QuestionInfo = quesionList, SurveyInfo = surveyInfo, RequiredInfo = survey.SurveyInfo.RequiredInfos.Split(','), TemplateFolderName = tmplFolder, isExample = 0 }; StaticPageHelper.GenerateHtml(surveyTmplObj, "wapTmpl.html", survey.SurveyInfo.StaticUrl.Split("/".ToCharArray())[1].Split('.')[0]); tran.Complete(); result.Result = 1; } } catch (Exception ex) { result.ErrorMsg = ex.Message; } return(result); }