Exemplo n.º 1
0
        public IHttpActionResult PutBuyer(int id, Buyer buyer)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != buyer.Id)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 2
0
        public IHttpActionResult PostBuyer(Buyer buyer)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Buyers.Add(buyer);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = buyer.Id }, buyer);
        }