public void Create(DalQuestion entity) { if (entity != null) { context.Questions.Add(entity.ToOrmQuestion()); } }
public void CreateAndUpdateTestId(DalQuestion entity, int testId) { var question = entity.ToOrmQuestion(); var test = context.Set <Test>().FirstOrDefault(t => t.Id == testId); test.Questions.Add(question); context.Set <Question>().Add(question); }
public void Delete(DalQuestion entity) { var ormQuestion = entity.ToOrmQuestion(); var question = context.Set <Question>().FirstOrDefault(u => u.Id == ormQuestion.Id); context.Set <Question>().Attach(question); context.Set <Question>().Remove(question); context.Entry(question).State = System.Data.Entity.EntityState.Deleted; }
public void Update(DalQuestion entity) { var question = context.Questions.FirstOrDefault(x => x.Id == entity.Id); if (question != null) { question.QuantityPoint = entity.QuantityPoint; } }
public void Delete(DalQuestion e) { if (context.Database.Connection.State != ConnectionState.Open) { context.Database.Connection.Open(); } Questions question = context.Set <Questions>().FirstOrDefault(q => q.id == e.Id); context.Set <Questions>().Remove(question); }
public bool ExistAnswer(DalQuestion question, DalAnswer answer) { if (context.Database.Connection.State != ConnectionState.Open) { context.Database.Connection.Open(); } return(context.Set <Answers>() .Any(answers => answers.AnswerStructure == answer.AnswerStructure && answers.QuestionId == question.Id)); }
public static QuestionEntity ToBllQuestion(this DalQuestion dalQuestion) { return(new QuestionEntity { Id = dalQuestion.Id, QuestionContent = dalQuestion.Question, QuantityPoint = dalQuestion.QuantityPoint, TestId = dalQuestion.TestId }); }
public static QuestionEntity ToBllQuestion(this DalQuestion e) { return(new QuestionEntity() { Id = e.Id, QuestionNumberInTest = e.QuestionNumberInTest, QuestionStructure = e.QuestionStructure, TestId = e.TestId }); }
public static Question ToOrmQuestion(this DalQuestion question) { return(new Question { Id = question.Id, Content = question.Question, QuantityPoint = question.QuantityPoint, TestId = question.TestId }); }
/// <summary> /// Maps DalQuestion entity to Question entity. /// </summary> /// <param name="question"> DalQuestion instance.</param> /// <returns> Question instance.</returns> public static Question ToQuestion(this DalQuestion question) { return(new Question() { Id = question.Id, TestId = question.TestId, QuestionText = question.QuestionText, Answers = question.Answers.Select(a => a.ToAnswer()).ToList() }); }
public void Create(DalQuestion e) { if (e == null) { return; } var tmp = e.ToQuestion(); context.Set <Question>().Add(tmp); }
public void Update(DalQuestion entity) { if (entity != null) { var questionToUpdate = context.Set <Question>().FirstOrDefault(u => u.Id == entity.Id); var ormQuestion = entity.ToOrmQuestion(); context.Set <Question>().Attach(questionToUpdate); questionToUpdate.Text = ormQuestion.Text; context.Entry(questionToUpdate).State = System.Data.Entity.EntityState.Modified; } }
public void Delete(DalQuestion entity) { if (entity != null) { var question = context.Questions.FirstOrDefault(x => x.Id == entity.Id); if (question != null) { context.Questions.Remove(question); } } }
public void Update(DalQuestion entity) { var tmp = context.Set <Question>().SingleOrDefault(t => t.Id == entity.Id); if (tmp != null) { return; } tmp = entity.ToQuestion(); context.Entry(tmp).State = EntityState.Modified; }
public void Update(DalQuestion entity) { if (context.Database.Connection.State != ConnectionState.Open) { context.Database.Connection.Open(); } Questions question = context.Set <Questions>().FirstOrDefault(q => q.id == entity.Id); question.QuestionNumberInTest = entity.QuestionNumberInTest; question.QuestionStructure = entity.QuestionStructure; question.TestId = entity.TestId; }
public static QuestionEntity ToBll(this DalQuestion question) { var questionEntity = new QuestionEntity() { Id = question.Id, Description = question.Description, TestId = question.TestId, }; foreach (var q in question.Answers) { questionEntity.Answers.Add(q.ToBll()); } return(questionEntity); }
public static DalQuestion ToDal(this QuestionEntity question) { var dalQuastion = new DalQuestion() { Id = question.Id, Description = question.Description, TestId = question.TestId, }; foreach (var q in question.Answers) { dalQuastion.Answers.Add(q.ToDal()); } return(dalQuastion); }
public static Question ToQuestion(this DalQuestion question) { if (question == null) { return(null); } return(new Question() { //Id = question.Id, Content = question.Content, Cost = question.Cost, Number = question.Number, TestId = question.TestId }); }
/// <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)); }
public void Create(DalQuestion e) { if (context.Database.Connection.State != ConnectionState.Open) { context.Database.Connection.Open(); } Questions question = new Questions() { id = e.Id, QuestionNumberInTest = e.QuestionNumberInTest, TestId = e.TestId, QuestionStructure = e.QuestionStructure }; context.Set <Questions>().Add(question); }
public static Question ToOrmQuestion(this DalQuestion dalQuestion) { if (dalQuestion == null) { return(null); } var ormQuestion = new Question() { Id = dalQuestion.Id, ThemeId = dalQuestion.ThemeId, Text = dalQuestion.Text, TestId = dalQuestion.TestId, Answers = dalQuestion.Answers.Select(r => r.ToOrmAnswer()).ToList() }; return(ormQuestion); }
public static DalQuestion ToDalQuestion(this Question ormQuestion) { if (ormQuestion == null) { return(null); } var dalQuestion = new DalQuestion() { Id = ormQuestion.Id, ThemeId = ormQuestion.ThemeId, Text = ormQuestion.Text, TestId = ormQuestion.TestId, Answers = ormQuestion.Answers.Select(r => r.ToDalAnswer()).ToList() }; return(dalQuestion); }
public IEnumerable <DalAnswer> GetAllAnswers(DalQuestion question) { if (context.Database.Connection.State != ConnectionState.Open) { context.Database.Connection.Open(); } IEnumerable <Answers> ormanswers = context.Set <Answers>().Where(answers => answers.QuestionId == question.Id).AsEnumerable(); List <DalAnswer> result = new List <DalAnswer>(); foreach (Answers a in ormanswers) { result.Add(new DalAnswer() { AnswerStructure = a.AnswerStructure, AnswerValue = a.AnswerValue, Id = a.id, QuestionId = a.QuestionId }); } return(result); }
public static QuestionDS.QuestionDSDataTable SelectQuestion(Int32 questionId) { QuestionDS.QuestionDSDataTable dt = DalQuestion.SelectQuestion(questionId); return(processData(dt)); }
public static Int32 UpdateQuestion(Int32 questionId, Int32 typeId, string text) { return(DalQuestion.UpdateQuestion(questionId, typeId, text)); }
public static Int32 DeleteQuestion(Int32 questionId) { return(DalQuestion.DeleteQuestion(questionId)); }
public QuestionController(DalQuestion context) { this._dalQuestion = context; }
/// <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)); }
public static DalQuestion ToDalQuestion(this QuestionEntity question) { DalQuestion dalQuestion = new DalQuestion() { Id = question.Id, TestId = question.TestId, Text = question.Text, Options = new List<DalOption>() }; foreach (var option in question.Options) { dalQuestion.Options.Add(option.ToDalOption()); } return dalQuestion; }
public void Create(DalQuestion entity) { var question = entity.ToOrmQuestion(); context.Set <Question>().Add(question); }
public static Int32 InsertQuestion(Int32 typeId, string text) { return(DalQuestion.InsertQuestion(typeId, text)); }