private Answer CreateAnswer(MyTaskViewModel model, Guid idAccount, MyTaskQuestionsViewModel question, MyTaskServicesDetailViewModel serviceDetail) { var answer = new Answer() { IdAccount = idAccount, IdMerchant = model.IdMerchant, IdQuestion = question.Id, IdServiceDetail = serviceDetail.Id, IdTask = model.IdTask, DateCreation = DateTime.Now, StatusRegister = CStatusRegister.Active }; answer = _answerDao.InsertOrUpdate(answer); return(answer); }
private void CreateAnswerDetail(Answer answer, MyTaskQuestionsViewModel question) { var answerDetail = new AnswerDetail() { DateCreation = DateTime.Now, IdAnswer = answer.Id, CopyNumber = question.CopyNumber, StatusRegister = CStatusRegister.Active }; if (question.IdQuestionDetail != Guid.Empty) { answerDetail.IdQuestionDetail = question.IdQuestionDetail; } if (question.CodeTypePoll == CTypePoll.Open) { answerDetail.AnswerValue = question.Answer; } _answerDetailDao.InsertOrUpdate(answerDetail); }
public List <MyTaskServicesDetailViewModel> GetAnsweredSections(List <MyTaskServicesDetailViewModel> model, List <Answer> answers) { int pos = 0; answers = answers.Distinct().ToList(); List <MyTaskServicesDetailViewModel> Section = new List <MyTaskServicesDetailViewModel>(); foreach (var answer in answers) { foreach (var answerDetail in answer.AnswerDetails) { //tomar todas las secciones lista para tomar todas las secciones duplicadas Section = model.Where(m => m.Id == answer.IdServiceDetail).ToList(); if (Section.Count == 0) { //buscar subsecciones foreach (var section in model) { foreach (var x in section.Sections) { if (x.Id == answer.IdServiceDetail) { Section.Add(x); } } } } //listado para tomar todas las preguntas porque lista porque toma las preguntas de las secciones duplicadas List <MyTaskQuestionsViewModel> questionList = new List <MyTaskQuestionsViewModel>(); MyTaskQuestionsViewModel pregunta = new MyTaskQuestionsViewModel(); foreach (var n in Section) { pregunta = new MyTaskQuestionsViewModel(); pregunta = n?.QuestionCollection.Where(q => q.Id == answer.IdQuestion).FirstOrDefault(); questionList.Add(pregunta); } //recorremos todas las preguntas lista porque puede existir varias preguntas con el mismo id int i = 0; var questionmodifica = questionList; for (i = 0; i < questionList.Count(); i++) { if (questionList[i] != null) { if (questionList.Count > 1) { answer.Question.sequence = i; } else { answer.Question.sequence = 0; } var question = Section[i]?.QuestionCollection.FirstOrDefault(q => q.Id == answer.IdQuestion); var answerquestion = answers.Where(x => x.IdQuestion == questionList[i].Id && (x.sequenceSection == i + 1 || x.sequenceSection == 0 || x.sequenceSection == null)).ToList(); if (answerquestion.Count() > 0) { var resp = answerquestion[0].AnswerDetails.ToList(); if (question != null) { switch (answer.Question.TypePoll.Code) { case CTypePoll.One: question.IdQuestionDetail = (Guid)resp[0].IdQuestionDetail; break; case CTypePoll.Open: question.Answer = resp[0].AnswerValue; break; } } } } } } } return(model); }