コード例 #1
0
        protected void btnWrite_Click(object sender, EventArgs e)
        {
            Maxim maxim = new Maxim();

            maxim.Name    = txtName.Text;
            maxim.Content = txtContent.Text;

            MaximServiceRepository repo = new MaximServiceRepository();

            maxim.Id = repo.AddMaxim(maxim).Id;

            lblDisplay.Text = maxim.Id.ToString() + "번 데이터가 입력되었습니다.";
        }
コード例 #2
0
        public JsonResult Post([FromBody] Maxim maxim)
        {
            if (ModelState.IsValid)
            {
                // 데이터 입력
                repo.AddMaxim(maxim);

                Response.StatusCode = (int)HttpStatusCode.Created;
                return(Json(maxim));
            }
            else
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { Message = "실패", ModelState = ModelState }));
            }
        }
コード例 #3
0
        //POST: api/MaximService
        public HttpResponseMessage Post([FromBody] Maxim maxim)
        {
            if (ModelState.IsValid)
            {
                //데이터 입력
                repo.AddMaxim(maxim);

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, maxim); //상태코드와 데이터가 포함된 HTTP응답 메시지
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = maxim.Id }));   //지정된 경로에 대한 링크 반환
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));  //400(모델 상태의 오류)
            }
        }
コード例 #4
0
        ///// <summary>
        ///// 상세 보기 전용 Web API 코드 샘플
        ///// </summary>
        //public HttpResponseMessage Get(string boardName, int boardNum)
        //{
        //    var model = _repository.GetById(boardName, boardNum);

        //    if (model == null)
        //    {
        //        return Request.CreateErrorResponse(
        //            HttpStatusCode.NotFound, "항목이 없습니다.");
        //    }

        //    return Request.CreateResponse(HttpStatusCode.OK, model);
        //}

        // POST: api/MaximService
        public HttpResponseMessage Post([FromBody] Maxim maxim)
        {
            if (ModelState.IsValid)
            {
                // 데이터 입력
                repo.AddMaxim(maxim);

                HttpResponseMessage response =
                    Request.CreateResponse(HttpStatusCode.Created, maxim);
                response.Headers.Location =
                    new Uri(Url.Link("DefaultApi", new { id = maxim.Id }));
                //new Uri(Request.RequestUri + maxim.Id.ToString());
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.BadRequest, ModelState));
            }
        }
コード例 #5
0
        public ActionResult Create(Maxim model)
        {
            repo.AddMaxim(model);

            return(RedirectToAction("Index", "Maxim"));
        }