Пример #1
0
        public IHttpActionResult UpdateStock(int id, Stock stock)
        {
            Stock stockToUpdate = this.Data.Stocks.Get(id);
            if (stockToUpdate == null)
            {
                return BadRequest(string.Format("Failed to update stock. No stock with id {0} found.", id));
            }

            stockToUpdate.Name = stock.Name;
            this.Data.SaveChanges();
            return Ok();
        }
Пример #2
0
        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.Data.Stocks.Add(stock);
            this.Data.SaveChanges();
            var addedStockId = this.Data.Stocks.GetAll().FirstOrDefault(s => s.Name == stock.Name);
            return Ok(addedStockId);
        }