Exemplo n.º 1
0
        /// <summary>
        /// 获取问卷信息
        /// </summary>
        /// <param name="pageId"></param>
        /// <returns></returns>
        public static async Task <OperationResult <GetQuestionnaireInfoResponse> > GetQuestionnaireInfoAsync(Guid pageId)
        {
            var      response     = new GetQuestionnaireInfoResponse();
            Question questionInfo = null;
            var      userInfo     = await DalUserQuestionnaireURL.GetUserQuestionnaireURLInfo(pageId);

            if (userInfo != null)
            {
                //有效期验证(投诉单问卷有效期为7天)
                if (userInfo.CreateDateTime.Date.AddDays(7) < DateTime.Now.Date)
                {
                    return(OperationResult.FromError <GetQuestionnaireInfoResponse>(nameof(Resource.Questionnaire_Overdue), string.Format(Resource.Questionnaire_Overdue)));
                }

                var questionnaireInfo = await DalQuestionnaire.GetQuestionnaireInfoByNo(userInfo.QuestionnaireNo);

                if (questionnaireInfo != null)
                {
                    //AutoMapper初始化配置文件
                    var config = new MapperConfiguration(cfg =>
                    {
                        cfg.CreateMap <QuestionnaireModel, GetQuestionnaireInfoResponse>();
                        cfg.CreateMap <QuestionModel, Question>();
                        cfg.CreateMap <QuestionOptionModel, QuestionOption>();
                    });
                    var mapper = config.CreateMapper();

                    response = mapper.Map <GetQuestionnaireInfoResponse>(questionnaireInfo);
                    response.QuestionList = new List <Question>();
                    var questionList = await DalQuestion.GetQuestionList(questionnaireInfo.QuestionnaireID);

                    var optionList = await DalQuestionOption.GetQuestionOptionList(questionnaireInfo.QuestionnaireID);

                    foreach (var item in questionList)
                    {
                        questionInfo = new Question();
                        questionInfo = mapper.Map <Question>(item);
                        questionInfo.QuestionOptionList = mapper.Map <List <QuestionOption> >(optionList.Where(t => t.QuestionID == questionInfo.QuestionID).ToList());
                        response.QuestionList.Add(questionInfo);
                    }
                }
            }
            else
            {
                return(OperationResult.FromError <GetQuestionnaireInfoResponse>(nameof(Resource.Questionnaire_NotExist), string.Format(Resource.Questionnaire_NotExist)));
            }
            return(OperationResult.FromResult(response));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 提交问卷
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static async Task <OperationResult <bool> > SubmitQuestionnaireAsync(Models.Requests.SubmitQuestionnaireRequest model)
        {
            bool result   = false;
            var  userInfo = await DalUserQuestionnaireURL.GetUserQuestionnaireURLInfo(model.PageID);

            if (userInfo != null)
            {
                //有效期验证(投诉单问卷有效期为7天)
                if (userInfo.CreateDateTime.Date.AddDays(7) < DateTime.Now.Date)
                {
                    return(OperationResult.FromError <bool>(nameof(Resource.Questionnaire_Overdue), string.Format(Resource.Questionnaire_Overdue)));
                }

                var questionnaireInfo = await DalQuestionnaire.GetQuestionnaireInfoByNo(userInfo.QuestionnaireNo);

                if (questionnaireInfo != null)
                {
                    var questionList = await DalQuestion.GetQuestionList(questionnaireInfo.QuestionnaireID);

                    var optionList = await DalQuestionOption.GetQuestionOptionList(questionnaireInfo.QuestionnaireID);

                    List <QuestionnaireAnswerRecordModel> answerRecordList = new List <QuestionnaireAnswerRecordModel>();
                    QuestionnaireAnswerRecordModel        answerRecord     = null;

                    #region 装载数据
                    foreach (var item in model.QuestionList)
                    {
                        // 验证数据
                        var questionInfo = questionList.Where(t => t.QuestionID == item.QuestionID).FirstOrDefault();
                        if (questionInfo != null)
                        {
                            var answerQuestionInfo = model.QuestionList.Where(t => t.QuestionID == item.QuestionID).FirstOrDefault();
                            if (answerQuestionInfo != null)
                            {
                                //是否必填验证
                                if (questionInfo.IsRequired == 1)
                                {
                                    if (answerQuestionInfo != null)
                                    {
                                        if (answerQuestionInfo.AnswerOptionList == null || !answerQuestionInfo.AnswerOptionList.Any())
                                        {
                                            return(OperationResult.FromError <bool>(nameof(Resource.ParameterError_IsRequired), string.Format(Resource.ParameterError_IsRequired, questionInfo.QuestionID)));
                                        }
                                    }
                                }
                                //最大字符验证
                                if (questionInfo.IsValidateMaxChar == 1)
                                {
                                    if (answerQuestionInfo != null)
                                    {
                                        foreach (var option in answerQuestionInfo.AnswerOptionList)
                                        {
                                            if (option.AnswerText.Length > questionInfo.MaxChar)
                                            {
                                                return(OperationResult.FromError <bool>(nameof(Resource.ParameterError_OverMaxChar), string.Format(Resource.ParameterError_OverMaxChar, questionInfo.QuestionID)));
                                            }
                                        }
                                    }
                                }
                                QuestionOptionModel optionInfo = null;
                                foreach (var option in item.AnswerOptionList)
                                {
                                    answerRecord        = new QuestionnaireAnswerRecordModel();
                                    answerRecord.UserID = userInfo.UserID;
                                    if (questionnaireInfo.QuestionnaireType < 2)    //售后问卷
                                    {
                                        answerRecord.ObjectID = userInfo.ComplaintsID;
                                    }
                                    else if (questionnaireInfo.QuestionnaireType == 2) //售前问卷
                                    {
                                        answerRecord.ObjectID = userInfo.OrderID;
                                    }
                                    answerRecord.QuestionnaireID   = questionnaireInfo.QuestionnaireID;
                                    answerRecord.QuestionnaireName = questionnaireInfo.QuestionnaireName;
                                    answerRecord.QuestionID        = item.QuestionID;

                                    answerRecord.QuestionName = questionInfo.QuestionTitle;
                                    answerRecord.QuestionType = questionInfo.QuestionType;
                                    answerRecord.AnswerText   = option.AnswerText;

                                    optionInfo = optionList.Where(t => t.OptionID == option.AnswerOptionID).FirstOrDefault();
                                    if (optionInfo != null)
                                    {
                                        answerRecord.AnswerOptionID      = optionInfo.OptionID;
                                        answerRecord.AnswerOptionContent = optionInfo.OptionContent;
                                    }
                                    answerRecordList.Add(answerRecord);
                                }
                            }
                        }
                    }
                    #endregion

                    await DalQuestionnaireAnswerRecord.SubmitQuestionnaire(answerRecordList);

                    result = true;
                }
            }
            else
            {
                return(OperationResult.FromError <bool>(nameof(Resource.Questionnaire_NotExist), string.Format(Resource.Questionnaire_NotExist)));
            }

            return(OperationResult.FromResult(result));
        }