Exemple #1
0
        public async Task <IActionResult> PutFoodMenu([FromRoute] int id, [FromBody] FoodMenu foodMenu)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            _context.Entry(foodMenu).State = EntityState.Modified;

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

            return(NoContent());
        }
Exemple #2
0
        public async Task <IActionResult> PostFoodMenu([FromBody] FoodMenu foodMenu)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Menus.Add(foodMenu);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFoodMenu", new { id = foodMenu.Id }, foodMenu));
        }