public IHttpActionResult UpdateTraceInfo() { TraceInfoDetail tid = new TraceInfoDetail(); try { HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; String jsonBean = context.Request.Form["jsonBean"]; if (jsonBean == null) { tid.code = 101; tid.msg = "参数验证失败!"; return(Ok(tid)); //return BadRequest(ModelState); } view_trace_info ti = new view_trace_info(); ti = JsonConvert.DeserializeObject <view_trace_info>(jsonBean); int id = ti.sid; var traceInfo = db.trace_info.Find(id); if (traceInfo == null) { tid.code = 102; tid.msg = "找不到痕迹记录!"; return(Ok(tid)); } traceInfo.name = ti.name; traceInfo.barcode = ti.barcode; traceInfo.disp = ti.disp; traceInfo.image1 = ti.image1; traceInfo.tqbw = ti.tqbw; traceInfo.trace_type = ti.traceType; db.trace_info.Attach(traceInfo); var stateEntity = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(traceInfo); stateEntity.SetModifiedProperty("name"); stateEntity.SetModifiedProperty("barcode"); stateEntity.SetModifiedProperty("disp"); stateEntity.SetModifiedProperty("image1"); stateEntity.SetModifiedProperty("tqbw"); stateEntity.SetModifiedProperty("trace_type"); db.SaveChanges(); tid.code = 100; return(Ok(tid)); } catch (Exception e) { tid.code = 104; tid.msg = "更新痕迹失败: " + e.Message; return(Ok(tid)); } }
public IHttpActionResult AddTraceInfo() { TraceInfoDetail tid = new TraceInfoDetail(); try { HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; String jsonBean = context.Request.Form["jsonBean"]; if (jsonBean == null) { tid.code = 101; tid.msg = "参数验证失败!"; return(Ok(tid)); //return BadRequest(ModelState); } view_trace_info ti = new view_trace_info(); ti = JsonConvert.DeserializeObject <view_trace_info>(jsonBean); trace_info traceInfo = new trace_info(); traceInfo.name = ti.name; traceInfo.barcode = ti.barcode; traceInfo.disp = ti.disp; traceInfo.image1 = ti.image1; traceInfo.tqbw = ti.tqbw; traceInfo.trace_type = ti.traceType; traceInfo.create_id = ti.creatorId; traceInfo.create_time = DateTime.Now; db.trace_info.Add(traceInfo); db.SaveChanges(); tid.code = 100; return(Ok(tid)); } catch (Exception e) { tid.code = 104; tid.msg = "新增痕迹失败: " + e.Message; return(Ok(tid)); } }