예제 #1
0
        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        public HttpResponseMessage Put(int id, [FromBody] TestApiModel value)
        {
            var old = peopleList.FirstOrDefault(i => i.Id == id);

            value.MapTo(old);
            return(new HttpResponseMessage {
                Content = new StringContent("操作成功")
            });
        }
예제 #2
0
 /// <summary>
 /// 添加对象
 /// </summary>
 /// <param name="value"></param>
 public HttpResponseMessage Post([FromBody] TestApiModel value)
 {
     try
     {
         //string result = Request.Content.ReadAsStringAsync().Result;
         //value.Id = peopleList.Max(i => i.Id) + 1;
         //peopleList.Add(value);
         return(new HttpResponseMessage {
             Content = new StringContent("操作成功")
         });
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #3
0
 public ActionResult Edit(int id, TestApiModel entity)
 {
     try
     {
         var response = HttpHelper.Put <TestApiModel>(UriAddress + id, entity);
         if (response.StatusCode == HttpStatusCode.OK)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("", "添加资料出现问题");
             return(View());
         }
     }
     catch
     {
         return(View());
     }
 }
예제 #4
0
        public ActionResult Create(TestApiModel entity)
        {
            try
            {
                //发post请求
                var response = HttpHelper.Post(UriAddress, entity.ToNameValueCollection());

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "添加资料出现问题," + response.StatusCode);
                    return(View());
                }
            }
            catch
            {
                return(View());
            }
        }
예제 #5
0
 public EmOperationDataSource(TestApiModel testApiModel)
 {
     this.testApiModel = testApiModel;
 }