69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using CarParkValidationAPI.Authorization;
|
|
using CarParkValidationAPI.Entities;
|
|
using CarParkValidationAPI.Models;
|
|
using CarParkValidationAPI.Interface;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CarParkValidationAPI.Controllers
|
|
{
|
|
//[Authorize]
|
|
[ApiController]
|
|
[Route("api/v1/[controller]")]
|
|
public class ConcessionTypeController : ControllerBase
|
|
{
|
|
private IConcessionType _concessionType;
|
|
|
|
public ConcessionTypeController(IConcessionType concessionType)
|
|
{
|
|
_concessionType = concessionType;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> ConcessionType([FromBody] ConcessionTypeDto model)
|
|
{
|
|
var currentUser = (User)HttpContext.Items["User"];
|
|
if (null == currentUser)
|
|
return Unauthorized(new { message = "Unauthorized" });
|
|
_concessionType.SetCurrentUser(currentUser.Username);
|
|
if (!ModelState.IsValid)
|
|
return BadRequest(ModelState);
|
|
var response = await _concessionType.SaveConcessionTypeAsync(model);
|
|
return Ok(response);
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> ConcessionType(bool onlyActive =true)
|
|
{
|
|
var retval = await _concessionType.LoadConcessionTypeAsync(onlyActive);
|
|
return Ok(retval);
|
|
}
|
|
|
|
[HttpGet("{id:int}")]
|
|
public async Task<IActionResult> ConcessionType(int id)
|
|
{
|
|
/*
|
|
// only admins can access other user records
|
|
var currentUser = (User)HttpContext.Items["User"];
|
|
if (id != currentUser.Id && currentUser.Role != Role.Admin)
|
|
return Unauthorized(new { message = "Unauthorized" });
|
|
*/
|
|
var retval = await _concessionType.LoadConcessionTypeByIdAsync(id);
|
|
return Ok(retval);
|
|
}
|
|
[HttpDelete("{id:int}")]
|
|
public async Task<IActionResult> DeleteConcessionType(int id)
|
|
{
|
|
/*
|
|
// only admins can access other user records
|
|
var currentUser = (User)HttpContext.Items["User"];
|
|
if (id != currentUser.Id && currentUser.Role != Role.Admin)
|
|
return Unauthorized(new { message = "Unauthorized" });
|
|
*/
|
|
var retval = await _concessionType.DeleteConcessionTypeAsync(id);
|
|
return Ok(retval);
|
|
}
|
|
}
|
|
}
|