Y2S1-Web_Apps_and_Services/ThAmCo.Catering/Controllers/BookingsController.cs

80 lines
2.1 KiB
C#
Raw Permalink Normal View History

2020-06-07 21:36:12 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using ThAmCo.Catering.Data;
using ThAmCo.Venues.Data;
namespace ThAmCo.Catering.Controllers
{
public class BookingsController
{
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
private readonly CateringDbContext _context;
public ValuesController(CateringDbContext context)
{
_context = context;
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<Menu>> Get()
{
return _context.Menus.ToArray();
}
// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
var menu = _context.Menus.FirstOrDefault(f => f.Id == id);
if (menu != null)
{
return Ok(menu);
}
return NotFound();
}
// POST api/values/
//Gives the function the menuid it wants to book.
[HttpPost]
public IActionResult Post([FromBody] int id)
{
if (_context.Menus.Any(m => m.Id == id))
{
FoodBooking fb = new FoodBooking
{
MenuId = id,
//Notes = notes,
};
var updatedFB = _context.Add(fb);
_context.SaveChangesAsync();
return Ok(updatedFB);
}
return BadRequest("MenuID was not found.");
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
}