public async Task <ActionResult <Inventory> > PostInventory([FromBody] Inventory inventory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repo.Add(inventory); return(CreatedAtAction("DisplayRoute", new { id = inventory.Id }, inventory)); }
public ActionResult <Inventory> PostInventory(Inventory inventory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repo.Add(inventory); return(CreatedAtAction("GetInventory", new { id = inventory.Id }, inventory)); }
public IActionResult Create([Bind("Make,Color,PetName")] Inventory inventory) { if (!ModelState.IsValid) { return(View(inventory)); } try { _repo.Add(inventory); } catch (Exception ex) { ModelState.AddModelError(string.Empty, $@"Unable to create record: {ex.Message}"); return(View(inventory)); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Make,Color,PetName")] Inventory inventory) { if (!ModelState.IsValid) { return(View(inventory)); } try { _context.Add(inventory); } catch (Exception ex) { ModelState.AddModelError(string.Empty, $@"Unable to create the record: {ex.Message}"); return(View(inventory)); } //await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> PostInventory([FromBody] Inventory inventory) { _repo.Add(inventory); return(CreatedAtAction("GetInventory", new { id = inventory.Id }, inventory)); }