コード例 #1
0
 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));
 }
コード例 #2
0
        public ActionResult <Inventory> PostInventory(Inventory inventory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            _repo.Add(inventory);

            return(CreatedAtAction("GetInventory", new { id = inventory.Id }, inventory));
        }
コード例 #3
0
 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)));
 }
コード例 #4
0
 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)));
 }
コード例 #5
0
        public async Task <IActionResult> PostInventory([FromBody] Inventory inventory)
        {
            _repo.Add(inventory);

            return(CreatedAtAction("GetInventory", new { id = inventory.Id }, inventory));
        }