Exemplo n.º 1
0
        public void CreateQuestionGeneric(FormViewModel _formViewModel, List <QuestionCreateViewModel> _listQuestionCreateViewModel)
        {
            FormViewModel formViewModel = _formViewModel;
            List <QuestionCreateViewModel> listQuestionCreateViewModel = _listQuestionCreateViewModel;

            if (listQuestionCreateViewModel == null)
            {
                return;
            }

            foreach (var questionCreateViewModel in listQuestionCreateViewModel)
            {
                ElementViewModel elementViewModel = new ElementViewModel
                {
                    Name        = questionCreateViewModel.ElementViewModel.Name,
                    Description = questionCreateViewModel.ElementViewModel.Description
                };
                // elementBL.Create(elementViewModel); // ???

                QuestionViewModel questionViewModel = new QuestionViewModel
                {
                    Name      = questionCreateViewModel.QuestionViewModel.Name,
                    FormId    = formBL.GetId(formViewModel),
                    ElementId = elementBL.GetId(elementViewModel)
                };
                questionBL.Create(questionViewModel);
                int questionId = questionBL.GetId(questionViewModel);

                foreach (var answerViewModel in questionCreateViewModel.AnswerViewModel)
                {
                    AnswerViewModel answerVM = new AnswerViewModel
                    {
                        Name       = answerViewModel.Name,
                        QuestionId = questionId
                    };
                    answerBL.Create(answerVM);
                }

                foreach (var attributeViewModel in questionCreateViewModel.AttributeViewModel)
                {
                    attributeVM = new AttributeViewModel
                    {
                        Name        = attributeViewModel.Name,
                        DisplayName = attributeViewModel.DisplayName,
                        QuestionId  = questionId
                    };
                    attributeBL.Create(attributeVM);
                }

                foreach (var attributeResultViewModel in questionCreateViewModel.AttributeResultViewModel)
                {
                    AttributeResultViewModel attributeResult = new AttributeResultViewModel
                    {
                        Value       = attributeResultViewModel.Value,
                        AttributeId = attributeBL.GetId(attributeVM)
                    };
                    attributeResultBL.Create(attributeResult);
                }
            }
        }
Exemplo n.º 2
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);
        }