コード例 #1
0
ファイル: TestsController.cs プロジェクト: sergiygladkyy/mbo
        public Object GetQuestions(int id)
        {
            var bodyResponse = new WebJsonResponse();
            try
            {
                var test = _repository.GetTestById(id);
                IQuestionRepository repository = new KettelQuestionRepository();
                var parametrList = new List<Object>();

                switch (test.CodeName)
                {
                    case Constraints.KKettel12CodeName:
                        parametrList.Add(Constraints.KKettelFactor12);
                        repository = new KettelQuestionRepository();
                        break;

                    case Constraints.KKettel16ACodeName:
                        parametrList.Add(Constraints.KKettelFactor16);
                        parametrList.Add(Constraints.KKettelFormA);
                        repository = new KettelQuestionRepository();

                        break;

                    case Constraints.KKettel16BCodeName:
                        parametrList.Add(Constraints.KKettelFactor16);
                        parametrList.Add(Constraints.KKettelFormB);
                        repository = new KettelQuestionRepository();
                        break;

                    case Constraints.KKettel16CCodeName:
                        parametrList.Add(Constraints.KKettelFactor16);
                        parametrList.Add(Constraints.KKettelFormC);
                        repository = new KettelQuestionRepository();
                        break;

                    case Constraints.KSondiCodeName:
                        var responseMessage = new HttpResponseMessage(HttpStatusCode.NotImplemented);
                        return responseMessage;

                    case Constraints.KLusherCodeName:
                        var responseMessage2 = new HttpResponseMessage(HttpStatusCode.NotImplemented);
                        return responseMessage2;

                    case Constraints.KAccentCodeName:
                        repository = new AccentRepository();
                        break;

                    case Constraints.KKotCodeName:
                        KotController kotController = new KotController();
                        bodyResponse.Data = kotController.GetAllQuestions();
                        break;

                    case Constraints.KShutzCodeName:
                        ShutzController shutzController = new ShutzController();
                        bodyResponse.Data = shutzController.GetAllQuestions();
                        break;

                    case Constraints.KLusherPairCodeName:
                        var responseMessage3 = new HttpResponseMessage(HttpStatusCode.NotImplemented);
                        return responseMessage3;

                    default:
                        repository = null;
                        break;
                }

                if (String.Compare(test.CodeName, Constraints.KAccentCodeName, StringComparison.CurrentCulture) == 0)
                {
                    var accentController = new AccentController();
                    bodyResponse = accentController.GetQuestions();
                }
                else if (String.Equals(test.CodeName, Constraints.KSelfAppraisalCodeName, StringComparison.CurrentCulture))
                {
                    var selfAppraisalController = new SelfAppraisalController();
                    bodyResponse = selfAppraisalController.GetQuestions();
                }
                else if (String.Equals(test.CodeName, Constraints.KKettel16ACodeName, StringComparison.CurrentCulture)
                    || (String.Equals(test.CodeName, Constraints.KKettel16BCodeName, StringComparison.CurrentCulture)))
                {
                    var listQuestion = (repository.GetAllQuestions()) as List<KettelQuestion>;
                    var sortedListQuestion = listQuestion.Where(
                        x => x.KettelFactor == (int)parametrList[0] && x.KettelForm == (String)parametrList[1]);

                    var webListQuestion = Mapper.Map<IEnumerable<KettelQuestion>, IEnumerable<WebKettelQuestion>>(sortedListQuestion);
                    bodyResponse.Data = webListQuestion;
                }
                else if (String.Equals(test.CodeName, Constraints.KMmpiCodeName, StringComparison.CurrentCulture))
                {
                    var mmpiController = new MmpiController();
                    bodyResponse = mmpiController.GetQuestions();
                }

                bodyResponse.Status = true;

            }
            catch (Exception exception)
            {
                bodyResponse.Error = exception.Message;
            }

            return bodyResponse;
        }
コード例 #2
0
ファイル: TestsController.cs プロジェクト: sergiygladkyy/mbo
        public WebJsonResponse GetQuestionsById(int id, int id2)
        {
            var bodyResponse = new WebJsonResponse();
            try
            {
                var test = _repository.GetTestById(id);
                IQuestionRepository repository;
                switch (test.CodeName)
                {
                    case Constraints.KKettel12CodeName:
                    case Constraints.KKettel16ACodeName:
                    case Constraints.KKettel16BCodeName:
                    case Constraints.KKettel16CCodeName:
                        repository = new KettelQuestionRepository();
                        break;
                    default:
                        repository = null;
                        break;
                }

                var question = repository.GetAllQuestions().First(x => x.Id == id2) as KettelQuestion;
                var webQuestion = AutoMapper.Mapper.Map<KettelQuestion, WebKettelQuestion>(question);

                bodyResponse.Status = true;
                bodyResponse.Data = webQuestion;
            }
            catch (Exception exception)
            {
                bodyResponse.Error = exception.Message;
            }
            return bodyResponse;
        }