public IActionResult Edit(int id, [Bind("Make,Color,PetName,Id,Timestamp")] Inventory inventory) { if (id != inventory.Id) { return(BadRequest()); } if (!ModelState.IsValid) { return(View(inventory)); } try { _repo.Update(inventory); } catch (DbUpdateConcurrencyException ex) { ModelState.AddModelError(string.Empty, $@"Unable to save the record. Another user has updated it. {ex.Message}"); return(View(inventory)); } catch (Exception ex) { ModelState.AddModelError(string.Empty, $@"Unable to save the record. {ex.Message}"); return(View(inventory)); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> PutInventory([FromRoute] int id, [FromBody] Inventory inventory) { if (!ModelState.IsValid) { return(BadRequest()); } if (id != inventory.Id) { return(BadRequest()); } try { _repo.Update(inventory); } catch (DbUpdateConcurrencyException) { if (!InventoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutInventory([FromRoute] int id, [FromBody] Inventory inventory) { if (id != inventory.Id) { return(BadRequest()); } _repo.Update(inventory); return(NoContent()); }
public IActionResult PutInventory([FromRoute] int id, [FromBody] Inventory inventory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != inventory.Id) { return(BadRequest()); } _repo.Update(inventory); return(NoContent()); }