コード例 #1
0
ファイル: QuestionController.cs プロジェクト: giautq1/PTTKPM
        public JsonResult Create(string Content, int Level, string AnswerA, string AnswerB, string AnswerC, string AnswerD, int IsResult)
        {
            ResData res = new ResData();

            if (String.IsNullOrEmpty(Content))
            {
                res.ID   = -1;
                res.Desc = "Nội dung câu hỏi không được để trống";
            }
            else if (String.IsNullOrEmpty(AnswerA) || String.IsNullOrEmpty(AnswerB) || String.IsNullOrEmpty(AnswerC) || String.IsNullOrEmpty(AnswerD))
            {
                res.ID   = -2;
                res.Desc = "Đáp án không được để trống";
            }
            else
            {
                res.ID = QuestionM.Create(Content, Level, AnswerA, AnswerB, AnswerC, AnswerD, IsResult);
                if (res.ID == 1)
                {
                    res.Desc = "Thêm mới thành công";
                }
                else
                {
                    res.Desc = "Thêm mới thất bại";
                }
            }

            return(Json(res));
        }
コード例 #2
0
        public HttpResponseMessage Create(ReqData req)
        {
            ResData res = new ResData();

            try
            {
                var data = JsonConvert.DeserializeObject <dynamic>(req.Content.ToString());
                //string Content, int Level, string AnswerA, string AnswerB, string AnswerC, string AnswerD, int IsResult
                string Content  = data.Content.ToString();
                string Level    = data.Level.ToString();
                string AnswerA  = data.AnswerA.ToString();
                string AnswerB  = data.AnswerB.ToString();
                string AnswerC  = data.AnswerC.ToString();
                string AnswerD  = data.AnswerD.ToString();
                string IsResult = data.IsResult.ToString();

                int check = QuestionM.Create(Content, Level, AnswerA, AnswerB, AnswerC, AnswerD, IsResult);

                res.Code       = 1;
                res.Message    = "Thành công";
                res.Detail     = check;
                res.StatusCode = HttpStatusCode.OK;
            }
            catch (Exception ex)
            {
                res.Code       = -99;
                res.Message    = ex.Message;
                res.StatusCode = HttpStatusCode.BadRequest;
            }

            return(Request.CreateResponse(res.StatusCode, res));
        }
コード例 #3
0
        public HttpResponseMessage GetQuestionLevel(ReqData req)
        {
            ResData res = new ResData();

            try
            {
                var Content = JsonConvert.DeserializeObject <dynamic>(req.Content.ToString());
                int Level   = int.Parse(Content.Level.ToString());

                QuestionM QM = QuestionM.GetQuestionLevel(Level);

                if (QM.QuestionID > 0)
                {
                    res.Code       = 1;
                    res.Message    = "Lấy dữ liệu OK";
                    res.Detail     = QM;
                    res.StatusCode = HttpStatusCode.OK;
                }
                else
                {
                    res.Code       = -1;
                    res.Message    = "Không có dữ liệu";
                    res.Detail     = QM;
                    res.StatusCode = HttpStatusCode.NonAuthoritativeInformation;
                }
            }
            catch (Exception ex)
            {
                res.Code       = -99;
                res.Message    = ex.Message;
                res.StatusCode = HttpStatusCode.BadRequest;
            }

            return(Request.CreateResponse(res.StatusCode, res));
        }
コード例 #4
0
ファイル: PlayController.cs プロジェクト: giautq1/PTTKPM
        public JsonResult GetQuestionLevel(int Level)
        {
            QuestionM q = QuestionM.GetQuestionLevel(Level);

            Session["DetailID"] = HistoryM.UpdateHistoryDetail("0", Session["HistoryID"].ToString(), q.QuestionID.ToString(), Level.ToString()); //Insert historyDetail

            return(Json(q, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
ファイル: AtCoderTester.cs プロジェクト: terry-u16/AtCoder
        public void QuestionMTest(string input, string output)
        {
            var outputs = SplitByNewLine(output);
            IAtCoderQuestion question = new QuestionM();

            var answers = question.Solve(input).Select(o => o.ToString()).ToArray();

            Assert.Equal(outputs, answers);
        }
コード例 #6
0
ファイル: AtCoderTester.cs プロジェクト: terry-u16/AtCoder
        public void QuestionMTest(string input, string output)
        {
            var outputs = SplitByNewLine(output);
            IAtCoderQuestion question = new QuestionM();

            var answers = SplitByNewLine(question.Solve(input).Trim());

            Assert.Equal(outputs, answers);
        }