예제 #1
0
        public async Task<IHttpActionResult> PutDishCategory(int id, DishCategory dishCategory)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DishCategoryExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #2
0
        public async Task<IHttpActionResult> PostDishCategory(DishCategory dishCategory)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.DishCategories.Add(dishCategory);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = dishCategory.ID }, dishCategory);
        }