public async Task <IHttpActionResult> PutStock(int id, StockViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Stock stock = await Db.Stocks.FindAsync(id); if (stock == null) { return(NotFound()); } model.AssignTo(stock); Db.Entry(stock).State = EntityState.Modified; try { await Db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StockWithIdExists(id)) { return(NotFound()); } throw; } return(StatusCode(HttpStatusCode.NoContent)); }