Ejemplo n.º 1
0
        public IHttpActionResult PutBlogModel(int id, BlogsData blogModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public IHttpActionResult GetBlogModel(int id)
        {
            BlogsData blogModel = db.BlogsDatas.Find(id);

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

            return(Ok(blogModel));
        }
Ejemplo n.º 3
0
        public IHttpActionResult DeleteBlogModel(int id)
        {
            BlogsData blogModel = db.BlogsDatas.Find(id);

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

            db.BlogsDatas.Remove(blogModel);
            db.SaveChanges();

            return(Ok(blogModel));
        }
Ejemplo n.º 4
0
        public IHttpActionResult PostBlogModel(BlogsData blogModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (blogModel.Id == 0)
            {
                db.BlogsDatas.Add(blogModel);
            }
            else
            {
                db.Entry(blogModel).State = EntityState.Modified;
            }
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = blogModel.Id }, blogModel));
        }