Ejemplo n.º 1
0
        public IHttpActionResult PutNews(int id, Dal.Models.News news)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        // POST: api/News
        public IHttpActionResult PostNews(Dal.Models.News news)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.NewsesList.Add(news);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = news.NewsId }, news));
        }