public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.Id) { return(BadRequest()); } _db.Entry(product).State = EntityState.Modified; try { _db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutQualityCheck(QualityCheck qualitycheck) { // return error when qualitycheck is empty if (qualitycheck == null) { return(InternalServerError()); } // getcorrect object from database by id QualityCheck ck = _db.QualityChecks.Find(qualitycheck.Id); // return error when qualitycheck does not excist if (ck == null) { return(InternalServerError()); } // update status for qualitycheck if (qualitycheck.Status != null) { ck.Status = qualitycheck.Status; if (qualitycheck.Status.Equals("Done")) { ck.EndDate = DateTime.Now; } } // update picture folder for qualitycheck if (qualitycheck.PictureFolderUrl != null) { ck.PictureFolderUrl = qualitycheck.PictureFolderUrl; } _db.Entry(ck).State = EntityState.Modified; _db.SaveChanges(); return(Ok()); }