Esempio n. 1
0
        public IHttpActionResult PostCommodity(Commodity commodity)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Commodities.Add(commodity);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CommodityExists(commodity.ID))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtRoute("DefaultApi", new { id = commodity.ID }, commodity);
        }
Esempio n. 2
0
        public IHttpActionResult PutCommodity(Guid id, Commodity commodity)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != commodity.ID)
            {
                return BadRequest();
            }

            db.Entry(commodity).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommodityExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }