public IHttpActionResult UpdateStock(int id, Stock stock) { Stock stockToUpdate = this.db.Stocks.FirstOrDefault(s => s.Id == id); if (stockToUpdate == null) { return BadRequest(string.Format("Failed to update stock. No stock with id {0} found.", id)); } stockToUpdate.Name = stock.Name; this.db.SaveChanges(); return Ok(); }
public IHttpActionResult AddStock(Stock stock) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (stock == null) { return BadRequest("You must provide an entry of type 'Stock', 'NULL' provided."); } this.db.Stocks.Add(stock); this.db.SaveChanges(); var addedStockId = this.db.Stocks.FirstOrDefault(s => s.Name == stock.Name); return Ok(addedStockId); }