first time include all file
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
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 AdminUserController : ControllerBase
|
||||
{
|
||||
private IAdminUser _adminUser;
|
||||
public AdminUserController(IAdminUser adminUser)
|
||||
{
|
||||
_adminUser = adminUser;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> AdminUser([FromBody] AdminUserDto model)
|
||||
{
|
||||
var currentUser = (User)HttpContext.Items["User"];
|
||||
if (null == currentUser)
|
||||
return Unauthorized(new { message = "Unauthorized" });
|
||||
_adminUser.SetCurrentUser(currentUser.Username);
|
||||
var response = await _adminUser.SaveAdminUserAsync(model);
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> AdminUser(bool onlyActive=true)
|
||||
{
|
||||
var retval = await _adminUser.LoadAdminUserAsync(onlyActive);
|
||||
return Ok(retval);
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
public async Task<IActionResult> AdminUser(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 _adminUser.LoadAdminUserByIdAsync(id);
|
||||
return Ok(retval);
|
||||
}
|
||||
[HttpDelete("{id:int}")]
|
||||
public async Task<IActionResult> DeleteAdminUser(int id)
|
||||
{
|
||||
var currentUser = (User)HttpContext.Items["User"];
|
||||
if (null == currentUser)
|
||||
return Unauthorized(new { message = "Unauthorized" });
|
||||
_adminUser.SetCurrentUser(currentUser.Username);
|
||||
var retval = await _adminUser.DeleteAdminUserAsync(id);
|
||||
return Ok(retval);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using CarParkValidationAPI.Authorization;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using CarParkValidationAPI.Repository;
|
||||
|
||||
namespace CarParkValidationAPI.Controllers
|
||||
{
|
||||
// [Authorize]
|
||||
[ApiController]
|
||||
[Route("api/v1/[controller]")]
|
||||
public class ConcessionValidationController : ControllerBase
|
||||
{
|
||||
private ConcessionValidationReportRepository _concessionValidationReport;
|
||||
|
||||
private IConcessionValidation _concessionValidation;
|
||||
private readonly FileExtensionContentTypeProvider _contentTypeProvider;
|
||||
|
||||
public ConcessionValidationController(IConcessionValidation concessionValidation,
|
||||
ConcessionValidationReportRepository concesionReportReport)
|
||||
{
|
||||
_concessionValidationReport = concesionReportReport;
|
||||
_concessionValidation = concessionValidation;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> ConcessionValidation([FromBody] ConcessionValidationDto model)
|
||||
{
|
||||
var currentUser = (User)HttpContext.Items["User"];
|
||||
if (null == currentUser)
|
||||
return Unauthorized(new { message = "Unauthorized" });
|
||||
_concessionValidation.SetCurrentUser(currentUser.Username);
|
||||
var response = await _concessionValidation.SaveConcessionValidationAsync(model);
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> ConcessionValidation(bool onlyActive=true)
|
||||
{
|
||||
var retval = await _concessionValidation.LoadConcessionValidationAsync(onlyActive);
|
||||
return Ok(retval);
|
||||
}
|
||||
|
||||
[HttpGet("[action]")]
|
||||
public async Task<IActionResult> ConcessionValidationByStaff(string staffLinkNo, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
var retval = await _concessionValidation.LoadConcessionValidationStaffLinkNoAsync(staffLinkNo, fromDate, toDate);
|
||||
return Ok(retval);
|
||||
}
|
||||
|
||||
[HttpGet("[action]")]
|
||||
public async Task<IActionResult> CheckConcessionValidationByStaff(string staffLinkNo, string concessionCard, DateTime currentDate, int id)
|
||||
{
|
||||
var retval = await _concessionValidation.CheckConcessionValidationStaffLinkNoAsync(staffLinkNo, concessionCard, currentDate, id);
|
||||
return Ok(retval);
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> ConcessionValidation(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 _concessionValidation.LoadConcessionValidationByIdAsync(id);
|
||||
return Ok(retval);
|
||||
}
|
||||
[HttpDelete("{id:int}")]
|
||||
public async Task<IActionResult> DeleteConcessionValidation(int id)
|
||||
{
|
||||
// only admins can access other user records
|
||||
var currentUser = (User)HttpContext.Items["User"];
|
||||
if (null == currentUser)
|
||||
return Unauthorized(new { message = "Unauthorized" });
|
||||
_concessionValidation.SetCurrentUser(currentUser.Username);
|
||||
var retval = await _concessionValidation.DeleteConcessionValidationAsync(id);
|
||||
return Ok(retval);
|
||||
}
|
||||
/* download the excel file */
|
||||
[HttpGet("[action]")]
|
||||
|
||||
public async Task<IActionResult> GetReportFile(DateTime fromDate , DateTime toDate)
|
||||
{
|
||||
// this.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
var result = await _concessionValidationReport.GetConcessionValidationReport(fromDate, toDate); // _concessionValidation.GetReport(fromDate, toDate);
|
||||
string fileContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; //Map(result.Data.FileName);
|
||||
return File(result.Data.Content, fileContentType, result.Data.FileName);
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
private string Map(string fileName)
|
||||
{
|
||||
if (!_contentTypeProvider.TryGetContentType(fileName, out string contentType))
|
||||
{
|
||||
contentType = "application/octet-stream";
|
||||
}
|
||||
return contentType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Controllers
|
||||
{
|
||||
public class FallbackController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
{
|
||||
return PhysicalFile(Path.Combine(Directory.GetCurrentDirectory(),
|
||||
"wwwroot", "index.html"), "text/HTML");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
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 LookupCodeController : ControllerBase
|
||||
{
|
||||
private readonly ILookupCode _lookupCodeService;
|
||||
|
||||
public LookupCodeController(ILookupCode lookupCode)
|
||||
{
|
||||
_lookupCodeService = lookupCode;
|
||||
}
|
||||
|
||||
[HttpGet("[action]")]
|
||||
public async Task<IActionResult> ConcessionTypes(bool onlyActive=true)
|
||||
{
|
||||
var retval = await _lookupCodeService.LoadConcessionTypeAsync(onlyActive);
|
||||
return Ok(retval);
|
||||
}
|
||||
[HttpGet("[action]")]
|
||||
public async Task<IActionResult> ValidationPoints(bool onlyActive= true)
|
||||
{
|
||||
var retval = await _lookupCodeService.LoadValidationPointAsync(onlyActive);
|
||||
return Ok(retval);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using CarParkValidationAPI.Authorization;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Models.Users;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using System.Threading.Tasks;
|
||||
using CarParkValidationAPI.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Identity.Data;
|
||||
|
||||
namespace CarParkValidationAPI.Controllers
|
||||
{
|
||||
// [Authorize]
|
||||
[ApiController]
|
||||
[Route("api/v1/[controller]")]
|
||||
public class UsersController : ControllerBase
|
||||
{
|
||||
private IUserService _userService;
|
||||
|
||||
public UsersController(IUserService userService)
|
||||
{
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Authenticate([FromBody] AuthenticateRequest model)
|
||||
{
|
||||
var response = _userService.Authenticate(model);
|
||||
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
[AllowAnonymous]
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> LoginAD([FromBody] AuthenticateRequest model)
|
||||
{
|
||||
var response = await _userService.LoginAD(model);
|
||||
// Configure cookie options
|
||||
var cookieOptions = new CookieOptions
|
||||
{
|
||||
HttpOnly = true, // Blocks client-side JavaScript reading/theft
|
||||
Secure = true, // Requires HTTPS connections
|
||||
SameSite = SameSiteMode.Unspecified, // Prevents CSRF attacks
|
||||
Expires = DateTimeOffset.UtcNow.AddDays(1), // Match your token lifespan
|
||||
Path = "/" // Accessible across entire domain structure
|
||||
};
|
||||
var jwttoken = response.Data.Token;
|
||||
// Write cookie into response headers
|
||||
Response.Cookies.Append("token", jwttoken, cookieOptions);
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
// 3. POST: api/auth/logout
|
||||
[HttpPost("[action]")]
|
||||
public IActionResult Logout()
|
||||
{
|
||||
// Erase cookie immediately by forcing an expired timestamp
|
||||
Response.Cookies.Delete("token", new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
SameSite = SameSiteMode.Unspecified,
|
||||
Path = "/"
|
||||
});
|
||||
|
||||
return Ok(new { message = "Logged out successfully" });
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> LoginApiAD([FromBody] AuthenticateRequest model)
|
||||
{
|
||||
var response = await _userService.LoginApiAD(model);
|
||||
// Configure cookie options
|
||||
var cookieOptions = new CookieOptions
|
||||
{
|
||||
HttpOnly = true, // Blocks client-side JavaScript reading/theft
|
||||
Secure = true, // Requires HTTPS connections
|
||||
SameSite = SameSiteMode.Unspecified, // Prevents CSRF attacks
|
||||
Expires = DateTimeOffset.UtcNow.AddDays(1), // Match your token lifespan
|
||||
Path = "/" // Accessible across entire domain structure
|
||||
};
|
||||
var jwttoken = response.Data.Token;
|
||||
// Write cookie into response headers
|
||||
Response.Cookies.Append("token", jwttoken, cookieOptions);
|
||||
return Ok(response);
|
||||
}
|
||||
[AllowAnonymous]
|
||||
[HttpGet("[action]")]
|
||||
public async Task<IActionResult> SearchApiStaff(string stafflinkNo)
|
||||
{
|
||||
var user = await _userService.SearchApiStaff(stafflinkNo);
|
||||
return Ok(user);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("[action]")]
|
||||
public async Task<ResultModel<User>> SearchADStaff(string stafflinkNo)
|
||||
{
|
||||
var user = await _userService.SearchADStaff(stafflinkNo);
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
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 ValidationPointController : ControllerBase
|
||||
{
|
||||
private IValidationPoint _validationPoint;
|
||||
|
||||
public ValidationPointController(IValidationPoint validationPoint)
|
||||
{
|
||||
_validationPoint = validationPoint;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> ValidationPoint([FromBody] ValidationPointDto model)
|
||||
{
|
||||
// Look for the cookie by its string key
|
||||
if (!Request.Cookies.TryGetValue("token", out string token))
|
||||
{
|
||||
return Unauthorized(new { message = "Not authenticated" });
|
||||
}
|
||||
|
||||
var currentUser = (User)HttpContext.Items["User"];
|
||||
if (null == currentUser)
|
||||
return Unauthorized(new { message = "Unauthorized" });
|
||||
_validationPoint.SetCurrentUser(currentUser.Username);
|
||||
var response = await _validationPoint.SaveValidationPointAsync(model);
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> ValidationPoint(bool onlyActive=true)
|
||||
{
|
||||
var retval = await _validationPoint.LoadValidationPointAsync(onlyActive);
|
||||
return Ok(retval);
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
public async Task<IActionResult> ValidationPoint(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 _validationPoint.LoadValidationPointByIdAsync(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 (null == currentUser)
|
||||
return Unauthorized(new { message = "Unauthorized" });
|
||||
_validationPoint.SetCurrentUser(currentUser.Username);
|
||||
var retval = await _validationPoint.DeleteValidationPointAsync(id);
|
||||
return Ok(retval);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user