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.
65 lines
1.6 KiB
65 lines
1.6 KiB
|
3 years ago
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using w230415_classes.Intf;
|
||
|
|
|
||
|
|
namespace w230415_casinoapi.Controllers
|
||
|
|
{
|
||
|
|
[ApiController]
|
||
|
|
[Route("v1/casino")]
|
||
|
|
public class CasinoControllerV1 : ControllerBase
|
||
|
|
{
|
||
|
|
private readonly ICasino _casino;
|
||
|
|
|
||
|
|
public CasinoControllerV1(ICasino casino)
|
||
|
|
{
|
||
|
|
_casino = casino;
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpGet("game", Name = "Get list")]
|
||
|
|
public IEnumerable<IGame> GetList()
|
||
|
|
{
|
||
|
|
return _casino.GetActiveList();
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("game", Name = "Add game")]
|
||
|
|
public void AddGame(
|
||
|
|
// [FromQuery]
|
||
|
|
string name,
|
||
|
|
// [FromQuery]
|
||
|
|
double cash)
|
||
|
|
{
|
||
|
|
bool bb = _casino.AddGame(name, cash);
|
||
|
|
Response.StatusCode = (bb ? 200 : 500);
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("gameForm", Name = "Add game form")]
|
||
|
|
public void AddGameForm(
|
||
|
|
[FromForm]
|
||
|
|
string name,
|
||
|
|
[FromForm]
|
||
|
|
double cash)
|
||
|
|
{
|
||
|
|
bool bb = _casino.AddGame(name, cash);
|
||
|
|
Response.StatusCode = (bb ? 200 : 500);
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpDelete("game/{uid}", Name = "Remove game")]
|
||
|
|
public void RemoveGame(
|
||
|
|
string uid
|
||
|
|
)
|
||
|
|
{
|
||
|
|
bool bb = _casino.RemoveGame(uid);
|
||
|
|
Response.StatusCode = (bb ? 200 : 404);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
[HttpPatch("game/{uid}", Name = "State game")]
|
||
|
|
public void StateGame(
|
||
|
|
string uid,
|
||
|
|
[FromHeader]
|
||
|
|
string flag)
|
||
|
|
{
|
||
|
|
bool bb = _casino.ChangeGameState(uid, flag == "1");
|
||
|
|
Response.StatusCode = (bb ? 200 : 404);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|