/// <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("操作成功") }); }
/// <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; } }
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()); } }
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()); } }
public EmOperationDataSource(TestApiModel testApiModel) { this.testApiModel = testApiModel; }