Esempio n. 1
0
        public async Task <IActionResult> PutBooking([FromRoute] int id, [FromBody] Booking booking)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != booking.MenuId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> Post([FromBody] MenuPostDto menu)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Menu newMenu = new Menu()
            {
                Name = menu.Name
            };

            await _context.Menus.AddAsync(newMenu);

            await _context.SaveChangesAsync();

            return(Ok(menu));
        }