Upload project.
This commit is contained in:
79
ThAmCo.Catering/Controllers/BookingsController.cs
Normal file
79
ThAmCo.Catering/Controllers/BookingsController.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
93
ThAmCo.Catering/Controllers/ValuesController.cs
Normal file
93
ThAmCo.Catering/Controllers/ValuesController.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
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
|
||||
{
|
||||
[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 IActionResult Put([Bind("Items,Price")] Menu food)
|
||||
{
|
||||
//If menu exists, edit the current entry.
|
||||
if (_context.Menus.Any(m => m.Id == food.Id) && ModelState.IsValid)
|
||||
{
|
||||
var menu = _context.Menus.First(m => m.Id == food.Id);
|
||||
|
||||
_context.Update(menu);
|
||||
_context.SaveChangesAsync();
|
||||
return Ok(menu);
|
||||
}
|
||||
//If menu doesn't exist, make a current entry.
|
||||
else if (ModelState.IsValid)
|
||||
{
|
||||
_context.Add(food);
|
||||
_context.SaveChangesAsync();
|
||||
return Ok();
|
||||
}
|
||||
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
// DELETE api/values/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user