コード例 #1
0
        public IHttpActionResult PostOffenders(Offenders offenders)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Offenders.Add(offenders);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (OffendersExists(offenders.OffendersId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = offenders.OffendersId }, offenders));
        }
コード例 #2
0
        public IHttpActionResult PutOffenders(int id, Offenders offenders)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != offenders.OffendersId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public IHttpActionResult GetOffenders(int id)
        {
            Offenders offenders = db.Offenders.Find(id);

            if (offenders == null)
            {
                return(NotFound());
            }

            return(Ok(offenders));
        }
コード例 #4
0
        public IHttpActionResult DeleteOffenders(int id)
        {
            Offenders offenders = db.Offenders.Find(id);

            if (offenders == null)
            {
                return(NotFound());
            }

            db.Offenders.Remove(offenders);
            db.SaveChanges();

            return(Ok(offenders));
        }