コード例 #1
0
        public IHttpActionResult PutBairro(int id, Bairro bairro)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != bairro.cd_bairro)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #2
0
        public IHttpActionResult PostBairro(Bairro bairro)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Bairro.Add(bairro);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = bairro.cd_bairro }, bairro);
        }