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

            if (id != ethnicity.EthnicityId)
            {
                return BadRequest();
            }

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

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

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

            db.Ethnicities.Add(ethnicity);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = ethnicity.EthnicityId }, ethnicity);
        }