public IHttpActionResult PutPestCode_LU(string id, PestCode_LU pestCode_LU) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != pestCode_LU.PESTCODE) { return(BadRequest()); } db.Entry(pestCode_LU).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PestCode_LUExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutCellEdit([FromBody] EditCellReq req) { if (string.IsNullOrEmpty(req.rowkey)) { return(BadRequest("req.rowkey is empty")); } using (var db = new PDPEntities()) { short iPdpYear; int iSamplePk; double dVal; var asRowId = req.rowkey.Split('|'); if (asRowId.Length != 4) { return(BadRequest("Invalid number of columns in the key: " + asRowId.Length)); } //SAMPLE_PK int, PESTCODE string, PDP_YEAR short, COMMOD string if (!int.TryParse(asRowId[0], out iSamplePk)) { return(BadRequest("Invalid value for SamplePK:" + asRowId[0])); } if (!short.TryParse(asRowId[2], out iPdpYear)) { return(BadRequest("Invalid value for Pdp year:" + asRowId[2])); } var foundRec = db.ResultsDatas.Find(new object[] { iSamplePk, asRowId[1], iPdpYear, asRowId[3] }); if (null == foundRec) { return(BadRequest("record with the key {0} was not found")); } switch (req.col) { case "Concen": if (!double.TryParse(req.val, out dVal)) { return(BadRequest("Value of CONCEN can't be " + req.val)); } foundRec.CONCEN = dVal; break; case "LOD": if (!double.TryParse(req.val, out dVal)) { return(BadRequest("Value of LOD can't be " + req.val)); } foundRec.LOD = dVal; break; case "pp_": foundRec.CONUNIT = req.val; break; default: return(BadRequest("can't edit column " + req.col)); } try { db.SaveChanges(); }catch (Exception ex) { Logger.Error(ex); while (null != ex.InnerException) { ex = ex.InnerException; } return(InternalServerError(ex)); } } return(Ok()); }