예제 #1
0
        private IHttpActionResult PostBlogCategory(BlogCategory BlogCategory)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.BlogCategories.Add(BlogCategory);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = BlogCategory.Id }, BlogCategory);
        }
예제 #2
0
        private IHttpActionResult PutBlogCategory(int id, BlogCategory BlogCategory)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }