Ejemplo n.º 1
0
        public IHttpActionResult PostPostCategory(PostCategory postCategory)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.PostCategories.Add(postCategory);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = postCategory.Id }, postCategory);
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutPostCategory(int id, PostCategory postCategory)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }