예제 #1
0
        public void DeleteForm(int formId)
        {
            FormBL            formBL            = new FormBL(mapper, unitOfWork);
            QuestionBL        questionBL        = new QuestionBL(mapper, unitOfWork);
            AnswerBL          answerBL          = new AnswerBL(mapper, unitOfWork);
            AttributeBL       attributeBL       = new AttributeBL(mapper, unitOfWork);
            AttributeResultBL attributeResultBL = new AttributeResultBL(mapper, unitOfWork);

            var questionViewModels = questionBL.ReadAll().Where(i => i.FormId == formId).ToList();

            foreach (var questionViewModel in questionViewModels)
            {
                int questionId       = questionBL.GetId(questionViewModel);
                var answerViewModels = answerBL.ReadAll().Where(i => i.QuestionId == questionId).ToList();

                foreach (var answerViewModel in answerViewModels)
                {
                    answerBL.Delete(answerBL.GetId(answerViewModel));
                }

                var attributeViewModels = attributeBL.ReadAll().Where(i => i.QuestionId == questionId).ToList();
                foreach (var attributeViewModel in attributeViewModels)
                {
                    int attributeId = attributeBL.GetId(attributeViewModel);
                    AttributeResultViewModel attributeResultViewModel = attributeResultBL.ReadAll()
                                                                        .FirstOrDefault(i => i.AttributeId == attributeId);
                    attributeResultBL.Delete(attributeResultBL.GetId(attributeResultViewModel));
                    attributeBL.Delete(attributeId);
                }
                questionBL.Delete(questionId);
            }
            formBL.Delete(formId);
        }
예제 #2
0
        public List <QuestionCreateViewModel> GetQuestionGeneric(int formId)
        {
            List <QuestionCreateViewModel> listQuestionCreateViewModel = new List <QuestionCreateViewModel>();
            var questionViewModels = questionBL.ReadAll().Where(i => i.FormId == formId).ToList();

            foreach (var questionViewModel in questionViewModels)
            {
                QuestionCreateViewModel questionCreateViewModel = new QuestionCreateViewModel();
                int questionId = questionBL.GetId(questionViewModel);
                questionCreateViewModel.QuestionViewModel  = questionViewModel;
                questionCreateViewModel.ElementViewModel   = elementBL.Read(questionViewModel.ElementId);
                questionCreateViewModel.AnswerViewModel    = answerBL.ReadAll().Where(i => i.QuestionId == questionId).ToList();
                questionCreateViewModel.AttributeViewModel = attributeBL.ReadAll().Where(i => i.QuestionId == questionId).ToList();
                foreach (var attribute in questionCreateViewModel.AttributeViewModel)
                {
                    questionCreateViewModel.AttributeResultViewModel.Add(attributeResultBL.ReadAll()
                                                                         .FirstOrDefault(i => i.AttributeId == attributeBL.GetId(attribute)));
                }
            }
            return(listQuestionCreateViewModel);
        }