public ResponseMessageResult Post(TuWeiInfo TuWeiInfo) { try { string openid = HttpContext.Current.Request.Headers.GetValues("openid").First().ToString(); if (!string.IsNullOrEmpty(openid)) { var info = db.TuWeiInfo.Where(o => o.cTuWeiBianMa == TuWeiInfo.cTuWeiBianMa); if (info.Count() > 0) { model.message = "土尾编码不能重复"; model.status_code = 401; return(new ResponseMessageResult(Request.CreateResponse((HttpStatusCode)model.status_code, model))); } var db_web = ContextDB.Context(); TuWeiInfo.cTuWeiBianMa = db_web.QueryValue("exec PROC_GongDiCode 'TW'"); db.TuWeiInfo.Add(TuWeiInfo); try { db.SaveChanges(); model.message = "新增成功"; model.status_code = 200; } catch (Exception ex) { model.message = ex.Message; model.status_code = 401; } db_web.Dispose(); } else { model.message = "微信授权失败"; model.status_code = 401; } } catch (Exception ex) { model.message = ex.Message; model.status_code = 401; } return(new ResponseMessageResult(Request.CreateResponse((HttpStatusCode)model.status_code, model))); }
public ResponseMessageResult Put(TuWeiInfo TuWeiInfo) { string openid = HttpContext.Current.Request.Headers.GetValues("openid").First().ToString(); if (!string.IsNullOrEmpty(openid)) { var count = db.TuWeiInfo.Where(o => o.cTuWeiBianMa == TuWeiInfo.cTuWeiBianMa).Count();; if (count > 1) { model.message = "土尾编码不能重复"; model.status_code = 401; return(new ResponseMessageResult(Request.CreateResponse((HttpStatusCode)model.status_code, model))); } var info = db.TuWeiInfo.Find(TuWeiInfo.cTuWeiBianMa); info.longitude = TuWeiInfo.longitude; info.latitude = TuWeiInfo.latitude; info.cTuWeiDiZhi = TuWeiInfo.cTuWeiDiZhi; try { db.SaveChanges(); model.message = "新增成功"; model.status_code = 200; } catch (Exception ex) { model.message = ex.Message; model.status_code = 401; } } else { model.message = "微信授权失败"; model.status_code = 401; } return(new ResponseMessageResult(Request.CreateResponse((HttpStatusCode)model.status_code, model))); }