You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1 KiB

3 years ago
using Microsoft.AspNetCore.Mvc;
using w230415_classes.Intf;
namespace w230415_webapi.Controllers
{
[ApiController]
[Route("v1/hall")]
public class HallController : ControllerBase
{
private readonly IHall _hall;
public HallController(IHall hall)
{
_hall = hall;
}
[HttpGet(Name = "GetNotBookedPlaces")]
public IEnumerable<IHallPlace> GetNotBooked()
{
return _hall.GetNotBookedPlaceList();
}
[HttpGet("seat/{iRow}/{iPosition}", Name = "GetPlace")]
public IHallPlace GetHallPlace(
int iRow,
int iPosition)
{
var place = _hall.ReadPlace(iRow, iPosition);
Response.StatusCode = place != null ? 200 : 404;
return place;
}
[HttpGet("seat", Name = "GetPlace by query params")]
public IHallPlace GetHallPlace2(
int iRow,
int iPosition)
{
var place = _hall.ReadPlace(iRow, iPosition);
Response.StatusCode = place != null ? 200 : 404;
return place;
}
[HttpPost("seat", Name = "Add place by form params")]
public void AddHallPlace(
[FromForm]
int iRow,
[FromForm]
int iPosition)
{
bool result = _hall.AddPlace(iRow, iPosition);
Response.StatusCode = result ? 200 : 500;
}
[HttpDelete("seat", Name = "Remove place by form params")]
public void RemoveHallPlace(
[FromHeader]
int iRow,
[FromHeader]
int iPosition)
{
bool result = _hall.DeletePlace(iRow, iPosition);
Response.StatusCode = result ? 200 : 500;
}
[HttpPatch("seat/booking/{iRow}/{iPosition}", Name = "Set booking status by params")]
public void SetBooking(
int iRow,
int iPosition)
{
bool result = _hall.BookPlace(iRow, iPosition);
Response.StatusCode = result ? 200 : 500;
}
}
}