public async Task <IHttpActionResult> PutWord(int id, Word word) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != word.WordID) { return(BadRequest()); } db.Entry(word).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WordExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// Update method public async Task Update(Word word) { // Update state of entity _context.Entry(word).State = EntityState.Modified; // Update entity in database await _context.SaveChangesAsync(); }
public ActionResult Edit([Bind(Include = "WordID,WordText")] Word word) { if (ModelState.IsValid) { db.Entry(word).State = EntityState.Modified; db.SaveChanges(); Log.Information($"The word with Id {word.WordID} has been edited."); return(RedirectToAction("Index")); } return(View(word)); }
public async Task <IActionResult> PutWord([FromRoute] int id, [FromBody] WordEntry word) { if (id != word.Id) { return(BadRequest()); } _context.Entry(word).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (_context.Words.Find(id) == null) { return(NotFound()); } throw; } return(NoContent()); }
public IHttpActionResult PutWordOrPhrase(int id, [FromBody] WordOrPhrase editedWordOrPhrase) { if (editedWordOrPhrase.Id != id) { return(BadRequest()); } db.Entry(editedWordOrPhrase).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!WordOrPhraseExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Update(User item) { db.Entry(item).State = EntityState.Modified; }