Esempio n. 1
0
 public async Task <IHttpActionResult> PostInventory(Inventory inventory)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         await _repo.AddAsync(inventory);
     }
     catch (Exception ex)
     {
         //Production app should do more here
         throw;
     }
     return(CreatedAtRoute("DefaultApi", new { id = inventory.CarId }, inventory));
 }
Esempio n. 2
0
        public async Task <ActionResult> Create([Bind(Include = "Make,Color,PetName")] Inventory inventory)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "An error occurred in the data.  Please check all values and try again.");
                return(View(inventory));
            }
            try
            {
                await _repo.AddAsync(inventory);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, $"Unable to create record: {ex.Message}");
                return(View(inventory));
            }
        }