示例#1
0
        public IHttpActionResult PutTbNew(int id, TbNew tbNew)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        public IHttpActionResult GetTbNew(int id)
        {
            TbNew tbNew = db.TbNews.Find(id);

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

            return(Ok(tbNew));
        }
示例#3
0
        public IHttpActionResult PostTbNew(TbNew tbNew)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TbNews.Add(tbNew);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = tbNew.id }, tbNew));
        }
示例#4
0
        public IHttpActionResult DeleteTbNew(int id)
        {
            TbNew tbNew = db.TbNews.Find(id);

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

            db.TbNews.Remove(tbNew);
            db.SaveChanges();

            return(Ok(tbNew));
        }