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); }
public MainQuestionBL(IMapper _mapper, IUnitOfWork _unitOfWork) { // unitOfWork = new UnitOfWork(); unitOfWork = _unitOfWork; mapper = _mapper; formBL = new FormBL(mapper, unitOfWork); questionBL = new QuestionBL(mapper, unitOfWork); elementBL = new ElementBL(mapper, unitOfWork); answerBL = new AnswerBL(mapper, unitOfWork); attributeBL = new AttributeBL(mapper, unitOfWork); attributeResultBL = new AttributeResultBL(mapper, unitOfWork); }