コード例 #1
0
        public IHttpActionResult PostPersonel(Personel personel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Personel.Add(personel);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = personel.PersonelId }, personel);
        }
コード例 #2
0
        public IHttpActionResult PutPersonel(int id, Personel personel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != personel.PersonelId)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }