first time include all file
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "5.0.9",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using System;
|
||||
|
||||
namespace CarParkValidationAPI.Authorization
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class AllowAnonymousAttribute : Attribute
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace CarParkValidationAPI.Models.Users
|
||||
{
|
||||
public class AuthenticateRequest
|
||||
{
|
||||
[Required]
|
||||
public string Username { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using CarParkValidationAPI.Entities;
|
||||
|
||||
|
||||
public class AuthenticateResponse
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string Username { get; set; }
|
||||
public int? Role { get; set; }
|
||||
public int ValidationPointId { get; set; }
|
||||
public string Token { get; set; }
|
||||
public string Email { get; set; }
|
||||
public AuthenticateResponse(User user, string token)
|
||||
{
|
||||
Id = user.Id;
|
||||
FirstName = user.FirstName;
|
||||
LastName = user.LastName;
|
||||
Username = user.Username;
|
||||
Email = user.Email;
|
||||
Role = user.Role;
|
||||
Token = token;
|
||||
ValidationPointId = user.ValidationPointId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Models;
|
||||
|
||||
namespace CarParkValidationAPI.Authorization
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
||||
public class AuthorizeAttribute : Attribute, IAuthorizationFilter
|
||||
{
|
||||
private readonly IList<AdminRole> _roles;
|
||||
|
||||
public AuthorizeAttribute(params AdminRole[] roles)
|
||||
{
|
||||
_roles = roles ?? new AdminRole[] { };
|
||||
}
|
||||
|
||||
public void OnAuthorization(AuthorizationFilterContext context)
|
||||
{
|
||||
// skip authorization if action is decorated with [AllowAnonymous] attribute
|
||||
var allowAnonymous = context.ActionDescriptor.EndpointMetadata.OfType<AllowAnonymousAttribute>().Any();
|
||||
if (allowAnonymous)
|
||||
return;
|
||||
|
||||
// authorization
|
||||
var user = (User)context.HttpContext.Items["User"];
|
||||
|
||||
if (user == null || (_roles.Any() && !_roles.Contains((AdminRole)user.Role)))
|
||||
{
|
||||
// not logged in or role not authorized
|
||||
context.Result = new JsonResult(new { message = "Unauthorized" }) { StatusCode = StatusCodes.Status401Unauthorized };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Interface;
|
||||
|
||||
|
||||
namespace CarParkValidationAPI.Authorization
|
||||
{
|
||||
public class JwtMiddleware(RequestDelegate next, IOptions<AppSettings> appSettings)
|
||||
{
|
||||
private readonly AppSettings _appSettings = appSettings.Value;
|
||||
|
||||
public async Task Invoke(HttpContext context, IUserService userService, IJwtUtils jwtUtils)
|
||||
{
|
||||
|
||||
string? token = context.Request.Headers.Authorization.FirstOrDefault()?.Split(" ").Last();
|
||||
if (null == token)
|
||||
context.Request.Cookies.TryGetValue("token", out token);
|
||||
|
||||
var user = jwtUtils.ValidateJwtToken(token);
|
||||
if (user != null)
|
||||
{
|
||||
// attach user to context on successful jwt validation
|
||||
//here to put in the real user
|
||||
//TODO if you want to add information for User
|
||||
context.Items["User"] = user;
|
||||
}
|
||||
|
||||
await next(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using CarParkValidationAPI.Models;
|
||||
|
||||
namespace CarParkValidationAPI.Authorization
|
||||
{
|
||||
|
||||
|
||||
public class JwtUtils : IJwtUtils
|
||||
{
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public JwtUtils(IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
public string GenerateJwtToken(User user)
|
||||
{
|
||||
// generate token that is valid for 2 days
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes(_appSettings.Secret);
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
Subject = new ClaimsIdentity(new[] {
|
||||
new Claim("id", user.Id.ToString()),
|
||||
new Claim("subject", user.Username)
|
||||
|
||||
//add more if we need it
|
||||
}
|
||||
),
|
||||
Expires = DateTime.UtcNow.AddDays(2),
|
||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
|
||||
};
|
||||
var token = tokenHandler.CreateToken(tokenDescriptor);
|
||||
return tokenHandler.WriteToken(token);
|
||||
}
|
||||
// get back id and username. in subject
|
||||
public User? ValidateJwtToken(string token)
|
||||
{
|
||||
if (token == null)
|
||||
return null;
|
||||
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes(_appSettings.Secret);
|
||||
try
|
||||
{
|
||||
tokenHandler.ValidateToken(token, new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(key),
|
||||
ValidateIssuer = false,
|
||||
ValidateAudience = false,
|
||||
// set clockskew to zero so tokens expire exactly at token expiration time (instead of 5 minutes later)
|
||||
ClockSkew = TimeSpan.Zero
|
||||
}, out SecurityToken validatedToken);
|
||||
|
||||
var jwtToken = (JwtSecurityToken)validatedToken;
|
||||
// var userId = int.Parse(jwtToken.Claims.First(x => x.Type == "id").Value); //old
|
||||
int userId = 0;
|
||||
string username = "";
|
||||
Claim claim;
|
||||
for (int i = 0; i< jwtToken.Claims.Count(); i++)
|
||||
{
|
||||
claim = jwtToken.Claims.ElementAt(i);
|
||||
if (claim.Type == "id")
|
||||
{
|
||||
userId = int.Parse(claim.Value);
|
||||
}
|
||||
else if (claim.Type == "subject")
|
||||
{
|
||||
username = claim.Value;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(username) && userId > 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
User user = new();
|
||||
user.Id = userId;
|
||||
user.Username = username;
|
||||
|
||||
// return user id from JWT token if validation successful
|
||||
return user;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// return null if validation fails
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
|
||||
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
<LangVersion>14</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.Core" Version="1.56.0" />
|
||||
<PackageReference Include="Azure.Identity" Version="1.21.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.8" />
|
||||
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.8" />
|
||||
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.18.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.1" />
|
||||
<PackageReference Include="SpreadsheetLight" Version="3.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="10.0.8" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.18.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CommonAD\CommonAD.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
//using Microsoft.Data.SqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using Microsoft.OpenApi.Reader;
|
||||
|
||||
namespace CarParkValidationAPI.Datas;
|
||||
|
||||
public class DataContext : DbContext
|
||||
{
|
||||
// public DbSet<User> Users { get; set; }
|
||||
public DbSet<AdminUser> AdminUsers { get; set; }
|
||||
public DbSet<ValidationPoint> Validations { get; set; }
|
||||
public DbSet<ConcessionValidation> ConcessionValidations { get; set; }
|
||||
public DbSet<ConcessionType> ConcessionTypes { get; set; }
|
||||
private readonly IConfiguration Configuration;
|
||||
private IOptions<AppSettings> _appSettings;
|
||||
|
||||
public DataContext(IConfiguration configuration, IOptions<AppSettings> appSettings, DbContextOptions<DataContext> options): base(options)
|
||||
{
|
||||
Configuration = configuration;
|
||||
_appSettings = appSettings;
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<ValidationPoint>().ToTable("ValidationPoint");
|
||||
modelBuilder.Entity<ConcessionValidation>().ToTable("ConcessionValidation");
|
||||
modelBuilder.Entity<ConcessionType>().ToTable("ConcessionType");
|
||||
modelBuilder.Entity<AdminUser>().ToTable("AdminUser");
|
||||
// Forces EF Core to map all DateTime properties to 'timestamp without time zone'
|
||||
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
||||
{
|
||||
var properties = entityType.GetProperties()
|
||||
.Where(p => p.ClrType == typeof(DateTime) || p.ClrType == typeof(DateTime?));
|
||||
|
||||
foreach (var property in properties)
|
||||
{
|
||||
property.SetColumnType("timestamp without time zone");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||
//{
|
||||
// in memory database used for simplicity, change to a real db for production applications
|
||||
// options.UseInMemoryDatabase("TestDb");
|
||||
// options.UseSqlServer(_appSettings.Value.SQLConnectionString);
|
||||
// options.UseSqlServer(Configuration.GetValue<string>("AppSettings:SQLConnectionString"));
|
||||
//}
|
||||
|
||||
private ConcessionValidationExtDto PopulateItem(IDataReader reader)
|
||||
{
|
||||
ConcessionValidationExtDto item = new ConcessionValidationExtDto();
|
||||
object myobj;
|
||||
myobj = reader["ValidationID"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.Id = (int)myobj;
|
||||
|
||||
myobj = reader["ValidateDate"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.ValidateDate = (DateTime)myobj;
|
||||
|
||||
myobj = reader["ConcessionCard"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.ConcessionCard = (string)myobj;
|
||||
|
||||
myobj = reader["ConcessionHolder"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.ConcessionHolder = (string)myobj;
|
||||
|
||||
myobj = reader["ConcessionExpiry"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.ConcessionExpiry = (bool)myobj;
|
||||
/*
|
||||
myobj = reader["ConcessionTypeID"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.ConcessionTypeId = (int)myobj;
|
||||
*/
|
||||
myobj = reader["StafflinkNo"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.StafflinkNo = (string)myobj;
|
||||
|
||||
myobj = reader["ConcessionType"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.ConcessionType = (string)myobj;
|
||||
myobj = reader["ValidationPoint"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.ValidationPoint = (string)myobj;
|
||||
|
||||
myobj = reader["StaffFirstName"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.StaffFirstName = (string)myobj;
|
||||
|
||||
myobj = reader["StaffLastName"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.StaffLastName = (string)myobj;
|
||||
|
||||
myobj = reader["StaffEmail"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.StaffEmail = (string)myobj;
|
||||
/*
|
||||
myobj = reader["ValidationPointID"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.ValidationPointId = (int)myobj;
|
||||
*/
|
||||
myobj = reader["Active"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
item.Active = (bool)myobj;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public async Task<List<ConcessionValidationExtDto>> SelectConcessionValidationByStaffId(bool activeOnly,
|
||||
string stafflinkNo, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
using (var command = this.Database.GetDbConnection().CreateCommand())
|
||||
{
|
||||
var pfromDate = command.CreateParameter();
|
||||
|
||||
pfromDate.ParameterName = "FromDate";
|
||||
pfromDate.Value = fromDate.Date;
|
||||
|
||||
var pToDate = command.CreateParameter();
|
||||
|
||||
pToDate.ParameterName = "toDate";
|
||||
pToDate.Value = toDate.Date;
|
||||
|
||||
var pStaffLink = command.CreateParameter();
|
||||
|
||||
pStaffLink.ParameterName = "StaffLinkNo";
|
||||
pStaffLink.Value = stafflinkNo;
|
||||
|
||||
|
||||
|
||||
ConcessionValidationExtDto item;
|
||||
List<ConcessionValidationExtDto> result = new List<ConcessionValidationExtDto>();
|
||||
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
command.CommandText = ("capv_ConValidation_Sel");
|
||||
command.Parameters.Add(pfromDate);
|
||||
command.Parameters.Add(pToDate);
|
||||
command.Parameters.Add(pStaffLink);
|
||||
this.Database.OpenConnection();
|
||||
using (DbDataReader reader = await command.ExecuteReaderAsync())
|
||||
{
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
item = PopulateItem(reader);
|
||||
result.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<int>> SelectCheckConcessionValidationAsync(DateTime fromDate, string concessionCard,
|
||||
string staffLinkNo)
|
||||
{
|
||||
using (var command = this.Database.GetDbConnection().CreateCommand())
|
||||
{
|
||||
var pfromDate = command.CreateParameter();
|
||||
|
||||
pfromDate.ParameterName = "FromDate";
|
||||
pfromDate.Value = fromDate.Date;
|
||||
|
||||
|
||||
var pStaffLink = command.CreateParameter();
|
||||
|
||||
pStaffLink.ParameterName = "StaffLinkNo";
|
||||
pStaffLink.Value = staffLinkNo;
|
||||
|
||||
|
||||
var pConcessionCard = command.CreateParameter();
|
||||
pConcessionCard.ParameterName = "ConcessionCard";
|
||||
pConcessionCard.Value = concessionCard;
|
||||
|
||||
|
||||
ConcessionValidationExtDto item;
|
||||
List<int> result = new List<int>();
|
||||
object myobj;
|
||||
int id;
|
||||
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
command.CommandText = ("capv_CheckConValidation_Sel");
|
||||
command.Parameters.Add(pfromDate);
|
||||
command.Parameters.Add(pStaffLink);
|
||||
command.Parameters.Add(pConcessionCard);
|
||||
this.Database.OpenConnection();
|
||||
using (DbDataReader reader = await command.ExecuteReaderAsync())
|
||||
{
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
myobj = reader["ValidationID"];
|
||||
if (myobj != System.DBNull.Value)
|
||||
{
|
||||
id = (int)myobj;
|
||||
result.Add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<ConcessionValidationExtDto>> SelectConcessionValidationByDate(bool activeOnly,
|
||||
DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
using (var command = this.Database.GetDbConnection().CreateCommand())
|
||||
{
|
||||
var pfromDate = command.CreateParameter();
|
||||
|
||||
pfromDate.ParameterName = "FromDate";
|
||||
pfromDate.Value = fromDate.Date;
|
||||
|
||||
var pToDate = command.CreateParameter();
|
||||
|
||||
pToDate.ParameterName = "toDate";
|
||||
pToDate.Value = toDate.Date;
|
||||
|
||||
ConcessionValidationExtDto item;
|
||||
List<ConcessionValidationExtDto> result = new List<ConcessionValidationExtDto>();
|
||||
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
command.CommandText = ("capv_ConValidationDate_Sel");
|
||||
command.Parameters.Add(pfromDate);
|
||||
command.Parameters.Add(pToDate);
|
||||
|
||||
this.Database.OpenConnection();
|
||||
using (DbDataReader reader = await command.ExecuteReaderAsync())
|
||||
{
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
item = PopulateItem(reader);
|
||||
result.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
result.Sort((x, y) => x.ValidateDate.Date.CompareTo(y.ValidateDate.Date));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
|
||||
#For more information, please see https://aka.ms/containercompat
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["CarParkValidationAPI/CarParkValidationAPI.csproj", "CarParkValidationAPI/"]
|
||||
COPY ["CommonAD/CommonAD.csproj", "CommonAD/"]
|
||||
RUN dotnet restore "CarParkValidationAPI/CarParkValidationAPI.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/CarParkValidationAPI"
|
||||
RUN dotnet build "CarParkValidationAPI.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "CarParkValidationAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
WORKDIR /app
|
||||
ENV ASPNETCORE_HTTP_PORTS=80
|
||||
EXPOSE 80
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "CarParkValidationAPI.dll"]
|
||||
@@ -0,0 +1,55 @@
|
||||
using CarParkValidationAPI.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Entities
|
||||
{
|
||||
public class AdminUserDto
|
||||
{
|
||||
#region public Member
|
||||
public int Id { get; set; }
|
||||
public string StafflinkNo { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string? LastName { get; set; }
|
||||
|
||||
public string? Email { get; set; }
|
||||
|
||||
public string? AddedOn { get; set; }
|
||||
|
||||
public bool? Active { get; set; }
|
||||
|
||||
public int? RoleType { get; set; }
|
||||
|
||||
public int? ValidationPointId { get; set; }
|
||||
#endregion
|
||||
}
|
||||
public class AdminUserViewDto
|
||||
{
|
||||
#region public Member
|
||||
public int Id { get; set; }
|
||||
public string StafflinkNo { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string? LastName { get; set; }
|
||||
|
||||
public string? Email { get; set; }
|
||||
|
||||
public string? AddedOn { get; set; }
|
||||
|
||||
public bool? Active { get; set; }
|
||||
|
||||
public int? RoleType { get; set; }
|
||||
|
||||
public string ValidationPoint { get; set; }
|
||||
public int ValidationPointId { get; set; }
|
||||
[JsonIgnore]
|
||||
public string PasswordHash { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Entities
|
||||
{
|
||||
public class ApiException
|
||||
{
|
||||
public ApiException(int statusCode, string message = null, string details = null)
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
Message = message;
|
||||
Details = details;
|
||||
}
|
||||
|
||||
public int StatusCode { get; set; }
|
||||
public string Message { get; set; }
|
||||
public string Details { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Entities
|
||||
{
|
||||
public class ConcessionTypeDto
|
||||
{
|
||||
#region public Member
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
public string Display { get; set; }
|
||||
|
||||
public bool Active { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Entities
|
||||
{
|
||||
public class ConcessionValidationExtDto: ConcessionValidationDto
|
||||
{
|
||||
public string ConcessionType { get; set; }
|
||||
public string ValidationPoint { get; set; }
|
||||
|
||||
|
||||
}
|
||||
public partial class ConcessionValidationDto
|
||||
{
|
||||
#region public Member
|
||||
|
||||
public int Id { get; set; }
|
||||
public DateTime ValidateDate { get; set; }
|
||||
|
||||
public string ConcessionCard { get; set; }
|
||||
|
||||
public string ConcessionHolder { get; set; }
|
||||
|
||||
public bool ConcessionExpiry { get; set; }
|
||||
|
||||
public int ConcessionTypeId { get; set; }
|
||||
|
||||
public string StafflinkNo { get; set; }
|
||||
|
||||
public int ValidationPointId { get; set; }
|
||||
|
||||
public bool Active { get; set; }
|
||||
|
||||
public string StaffFirstName { get; set; }
|
||||
public string StaffLastName { get; set; }
|
||||
public string StaffEmail { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Entities
|
||||
{
|
||||
public class FileContent
|
||||
{
|
||||
public byte[] Content { get; set; }
|
||||
public string FileName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Entities
|
||||
{
|
||||
public class LookupCodeDto
|
||||
{
|
||||
public int Id
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public string Description
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Models
|
||||
{
|
||||
public class ResultModel<T>
|
||||
{
|
||||
public T Data { get; set; }
|
||||
public int StatusCode { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace CarParkValidationAPI.Entities
|
||||
{
|
||||
public enum Role
|
||||
{
|
||||
Admin,
|
||||
User
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CarParkValidationAPI.Entities;
|
||||
|
||||
public enum AdminRole
|
||||
{
|
||||
Normal = 1,
|
||||
Admin = 2
|
||||
}
|
||||
public class User
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Username { get; set; }
|
||||
public int? Role { get; set; }
|
||||
public int ValidationPointId { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public string PasswordHash { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Entities
|
||||
{
|
||||
public class ValidationPointDto
|
||||
{
|
||||
|
||||
#region public Member
|
||||
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Description { get; set; }
|
||||
|
||||
public string Display { get; set; }
|
||||
|
||||
public bool? Active { get; set; }
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using CarParkValidationAPI.Entities;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Helpers
|
||||
{
|
||||
public class ErrorHandlerMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly ILogger<ErrorHandlerMiddleware> _logger;
|
||||
private readonly IHostEnvironment _env;
|
||||
|
||||
public ErrorHandlerMiddleware(RequestDelegate next,
|
||||
ILogger<ErrorHandlerMiddleware> logger, IHostEnvironment env)
|
||||
{
|
||||
_next = next;
|
||||
_logger = logger;
|
||||
_env = env;
|
||||
}
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _next(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var response = context.Response;
|
||||
response.ContentType = "application/json";
|
||||
_logger.LogError(ex, ex.Message);
|
||||
/*
|
||||
switch (ex)
|
||||
{
|
||||
// case Exception e:
|
||||
// // custom application error
|
||||
// response.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
// break;
|
||||
case KeyNotFoundException:
|
||||
// not found error
|
||||
response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
break;
|
||||
default:
|
||||
// unhandled error
|
||||
response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||
break;
|
||||
} */
|
||||
response.StatusCode = ex switch
|
||||
{
|
||||
// case Exception e:
|
||||
// // custom application error
|
||||
// response.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
// break;
|
||||
KeyNotFoundException => (int)HttpStatusCode.NotFound,// not found error
|
||||
_ => (int)HttpStatusCode.InternalServerError,// unhandled error
|
||||
};
|
||||
//response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||
var res = _env.IsDevelopment() ?
|
||||
new ApiException(response.StatusCode, ex.Message, ex.StackTrace?.ToString())
|
||||
: new ApiException(response.StatusCode, "Internal Server Error");
|
||||
|
||||
var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
|
||||
var json = JsonSerializer.Serialize(res, options);
|
||||
await response.WriteAsync(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace CarParkValidationAPI.Helpers;
|
||||
|
||||
public class Helper
|
||||
{
|
||||
public static string DateToStr(DateTime? date)
|
||||
{
|
||||
string result = "";
|
||||
if (date != null)
|
||||
result = date?.ToString("yyyy-MM-dd");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static DateTime StrToDate(string date)
|
||||
{
|
||||
DateTime result = DateTime.Today;
|
||||
if (DateTime.TryParse(date, out var dt))
|
||||
{
|
||||
result = dt;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace CarParkValidationAPI.Interface
|
||||
{
|
||||
public interface IAdminUser
|
||||
{
|
||||
Task<ResultModel<List<AdminUserViewDto>>> LoadAdminUserAsync(bool OnlyActive);
|
||||
Task<ResultModel<bool>> CheckAdminUserByStaffLinkNoAsync(string staffLinkNo);
|
||||
Task<ResultModel<int>> SaveAdminUserAsync(AdminUserDto item);
|
||||
Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id);
|
||||
Task<ResultModel<bool>> DeleteAdminUserAsync(int id);
|
||||
void SetCurrentUser(string username);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace CarParkValidationAPI.Interface
|
||||
{
|
||||
public interface IConcessionType
|
||||
{
|
||||
Task<ResultModel<List<ConcessionTypeDto>>> LoadConcessionTypeAsync(bool OnlyActive);
|
||||
Task<ResultModel<int>> SaveConcessionTypeAsync(ConcessionTypeDto item);
|
||||
Task<ResultModel<ConcessionTypeDto>> LoadConcessionTypeByIdAsync(int id);
|
||||
Task<ResultModel<bool>> DeleteConcessionTypeAsync(int id);
|
||||
void SetCurrentUser(string username);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace CarParkValidationAPI.Interface
|
||||
{
|
||||
public interface IConcessionValidation
|
||||
{
|
||||
Task<ResultModel<List<ConcessionValidationExtDto>>> LoadConcessionValidationAsync(bool OnlyActive);
|
||||
Task<ResultModel<List<ConcessionValidationExtDto>>> LoadConcessionValidationStaffLinkNoAsync(string staffLinkNo, DateTime currentDate, DateTime toDate);
|
||||
Task<ResultModel<int>> CheckConcessionValidationStaffLinkNoAsync(string staffLinkNo, string concessionCard, DateTime currentDate, int id);
|
||||
Task<ResultModel<int>> SaveConcessionValidationAsync(ConcessionValidationDto item);
|
||||
Task<ResultModel<ConcessionValidationDto>> LoadConcessionValidationByIdAsync(int id);
|
||||
Task<ResultModel<bool>> DeleteConcessionValidationAsync(int id);
|
||||
Task<ResultModel<FileContent>> GetReport(DateTime fromDate, DateTime toDate);
|
||||
void SetCurrentUser(string username);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using CarParkValidationAPI.Entities;
|
||||
|
||||
|
||||
namespace CarParkValidationAPI.Interface
|
||||
{
|
||||
public interface IJwtUtils
|
||||
{
|
||||
public string GenerateJwtToken(User user);
|
||||
public User? ValidateJwtToken(string token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace CarParkValidationAPI.Interface
|
||||
{
|
||||
public interface ILookupCode
|
||||
{
|
||||
Task<ResultModel<List<LookupCodeDto>>> LoadConcessionTypeAsync(bool OnlyActive);
|
||||
Task<ResultModel<List<LookupCodeDto>>> LoadValidationPointAsync(bool OnlyActive);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using CarParkValidationAPI.Models.Users;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CarParkValidationAPI.Models;
|
||||
|
||||
namespace CarParkValidationAPI.Interface
|
||||
{
|
||||
public interface IUserService
|
||||
{
|
||||
AuthenticateResponse Authenticate(AuthenticateRequest model);
|
||||
Task<ResultModel<AuthenticateResponse>> LoginApiAD(AuthenticateRequest model);
|
||||
Task<ResultModel<AuthenticateResponse>> LoginAD(AuthenticateRequest model);
|
||||
|
||||
Task<ResultModel<User>> SearchApiStaff(string staffLinkNo);
|
||||
Task<ResultModel<User>> SearchADStaff(string staffLinkNo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace CarParkValidationAPI.Interface
|
||||
{
|
||||
public interface IValidationPoint
|
||||
{
|
||||
Task<ResultModel<List<ValidationPointDto>>> LoadValidationPointAsync(bool OnlyActive);
|
||||
Task<ResultModel<int>> SaveValidationPointAsync(ValidationPointDto item);
|
||||
Task<ResultModel<ValidationPointDto>> LoadValidationPointByIdAsync(int id);
|
||||
Task<ResultModel<bool>> DeleteValidationPointAsync(int id);
|
||||
void SetCurrentUser(string username);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CarParkValidationAPI.Models
|
||||
{
|
||||
|
||||
public partial class AdminUserCriteria
|
||||
{
|
||||
public AdminUserCriteria()
|
||||
{
|
||||
}
|
||||
#region public Member
|
||||
|
||||
public int? Id { get; set; }
|
||||
|
||||
public int? StafflinkNo { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string AddedBy { get; set; }
|
||||
|
||||
|
||||
public bool? Active { get; set; }
|
||||
|
||||
public int? RoleType { get; set; }
|
||||
#endregion
|
||||
}
|
||||
[Table("AdminUser")]
|
||||
public partial class AdminUser
|
||||
{
|
||||
public AdminUser()
|
||||
{
|
||||
}
|
||||
#region public Member
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string StafflinkNo { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string? LastName { get; set; }
|
||||
|
||||
public string? Email { get; set; }
|
||||
|
||||
public DateTime? AddedOn { get; set; }
|
||||
|
||||
public bool? Active { get; set; }
|
||||
|
||||
public int? RoleType { get; set; }
|
||||
|
||||
public int? ValidationPointId { get; set; }
|
||||
public DateTime? LastModified { get; set; }
|
||||
public string? LastModifiedId { get; set; }
|
||||
[JsonIgnore]
|
||||
public string PasswordHash { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace CarParkValidationAPI.Models
|
||||
{
|
||||
public class AppSettings
|
||||
{
|
||||
public string Secret { get; set; }
|
||||
public string SQLConnectionString { get; set; }
|
||||
public string LDAPPath { get; set; }
|
||||
public string LDAPUser { get; set; }
|
||||
public string LDAPPassword { get; set; }
|
||||
|
||||
public string LoginWebAPI { get; set; }
|
||||
/// <summary>
|
||||
/// for convert to time. use GetADTimeOut
|
||||
/// TimeSpan.FromSeconds(Convert.ToDouble(ConfigurationManager.AppSettings["ADTimeOut"]));
|
||||
public string ADTimeOut { get; set; }
|
||||
|
||||
public TimeSpan GetADTimeOut()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(ADTimeOut))
|
||||
return TimeSpan.FromSeconds(Convert.ToDouble(ADTimeOut));
|
||||
else
|
||||
return TimeSpan.FromSeconds(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace CarParkValidationAPI.Models
|
||||
{
|
||||
public partial class ConcessionType
|
||||
{
|
||||
public ConcessionType()
|
||||
{
|
||||
}
|
||||
#region public Member
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string ConcessionDesc { get; set; }
|
||||
|
||||
public string ConcessionDisplay { get; set; }
|
||||
|
||||
public bool Active { get; set; }
|
||||
public DateTime? LastModified { get; set; }
|
||||
public string? LastModifiedId { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace CarParkValidationAPI.Models
|
||||
{
|
||||
[NotMapped]
|
||||
public class ConcessionValidationExt: ConcessionValidation
|
||||
{
|
||||
#region public Member
|
||||
public string ConcessionType { get; set; }
|
||||
public string ValidationPiont { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
public partial class ConcessionValidation
|
||||
{
|
||||
public ConcessionValidation()
|
||||
{
|
||||
}
|
||||
|
||||
#region public Member
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public DateTime ValidateDate { get; set; }
|
||||
|
||||
public string ConcessionCard { get; set; }
|
||||
|
||||
public string ConcessionHolder { get; set; }
|
||||
|
||||
public bool ConcessionExpiry { get; set; }
|
||||
|
||||
public int ConcessionTypeID { get; set; }
|
||||
|
||||
public string StafflinkNo { get; set; }
|
||||
|
||||
public int ValidationPointID { get; set; }
|
||||
|
||||
public bool Active { get; set; }
|
||||
public string StaffFirstName { get; set; }
|
||||
public string StaffLastName { get; set; }
|
||||
public string StaffEmail { get; set; }
|
||||
public DateTime? CreatedDate { get; set; }
|
||||
public string? CreatedId { get; set; }
|
||||
public DateTime? LastModified { get; set; }
|
||||
public string? LastModifiedId{ get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace CarParkValidationAPI.Models
|
||||
{
|
||||
|
||||
|
||||
public class ValidationPoint
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
public string? DisplayName { get; set; }
|
||||
|
||||
public bool? Active { get; set; }
|
||||
|
||||
public DateTime? LastModified { get; set; }
|
||||
public string? LastModifiedId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CarParkValidationAPI.Authorization;
|
||||
using CarParkValidationAPI.Datas;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Repository;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
// Define cross-origin sharing policy name
|
||||
var myAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
#region Services
|
||||
var services = builder.Services;
|
||||
services.AddCors();
|
||||
/*
|
||||
services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy(name: myAllowSpecificOrigins,
|
||||
policy =>
|
||||
{
|
||||
policy.WithOrigins("http://localhost:3000") // 👈 Your React app location
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials(); // 👈 MANDATORY: Permits cookie exchange
|
||||
});
|
||||
});
|
||||
*/
|
||||
services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
services.AddEndpointsApiExplorer();
|
||||
services.AddSwaggerGen();
|
||||
|
||||
var appSettingsSection = builder.Configuration.GetSection("AppSettings");
|
||||
services.Configure<AppSettings>(appSettingsSection);
|
||||
var appSettings = appSettingsSection.Get<AppSettings>();
|
||||
var key = Encoding.ASCII.GetBytes(appSettings.Secret);
|
||||
|
||||
services.AddAuthentication(x =>
|
||||
{
|
||||
|
||||
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
})
|
||||
.AddJwtBearer(x =>
|
||||
{
|
||||
x.RequireHttpsMetadata = false;
|
||||
x.SaveToken = true;
|
||||
x.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(key),
|
||||
ValidateIssuer = false,
|
||||
ValidateAudience = false
|
||||
};
|
||||
});
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
//services.AddScoped<ImportPersonRepository>();
|
||||
services.AddDbContext<DataContext>(options =>
|
||||
{
|
||||
|
||||
// options.LogTo(s => Console.WriteLine(s));
|
||||
//options.UseNpgsql(appSettings.SQLConnectionString);
|
||||
string? conn = builder.Configuration.GetValue<string>("AppSettings:SQLConnectionString");
|
||||
// options.UseSqlServer(conn);
|
||||
if (!string.IsNullOrEmpty(conn))
|
||||
options.UseNpgsql(conn);
|
||||
// options.LogTo(s => Console.WriteLine(s));
|
||||
// if (conn != null)
|
||||
// options.UseNpgsql(conn);
|
||||
});
|
||||
/*
|
||||
services.AddGraphQLServer()
|
||||
.AddFiltering()
|
||||
.AddSorting()
|
||||
.AddProjections()
|
||||
// .RegisterDbContextFactory<FamilyTreeDBContext>()
|
||||
|
||||
//.AddQueryType<QueryFamilyTree>();
|
||||
|
||||
*/
|
||||
|
||||
services.AddHttpContextAccessor();
|
||||
services.AddScoped<IJwtUtils, JwtUtils>();
|
||||
services.AddScoped<IConcessionType, ConcessionTypeRepository>();
|
||||
services.AddScoped<IValidationPoint, ValidationPointRepository>();
|
||||
services.AddScoped<IAdminUser, AdminUserRepository>();
|
||||
services.AddScoped<IUserService, UserServiceFakeRepository>();
|
||||
services.AddScoped<IConcessionValidation, ConcessionValidationRepository>();
|
||||
services.AddScoped<ILookupCode, LookupCodeRepository>();
|
||||
services.AddScoped(typeof(ConcessionValidationReportRepository));
|
||||
services.AddScoped<Seed>();
|
||||
/*
|
||||
|
||||
// services.AddScoped<IUserService, UserRepository>();
|
||||
|
||||
|
||||
/*
|
||||
|
||||
public FamilyTreeDBContext(DbContextOptions<FamilyTreeDBContext> options)
|
||||
: base(options)
|
||||
{
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
}
|
||||
services.AddScoped<IAdminUser, AdminUserRepository>();
|
||||
|
||||
services.AddScoped<IMotorVehicles, MotorVehiclesRepository>();
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region app
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
try
|
||||
{
|
||||
var context = scope.ServiceProvider.GetRequiredService<DataContext>();
|
||||
var db = context.Database;
|
||||
if (db != null)
|
||||
{
|
||||
/*
|
||||
try
|
||||
{
|
||||
using var cts = new CancellationTokenSource();
|
||||
CancellationToken cancellationToken = cts.Token;
|
||||
await db.MigrateAsync(cancellationToken);
|
||||
db.EnsureCreated();
|
||||
}
|
||||
catch
|
||||
{
|
||||
//continue
|
||||
}
|
||||
*/
|
||||
var staff = scope.ServiceProvider.GetService<Seed>();
|
||||
int id = staff.InsertOneUser();
|
||||
if (id < 0)
|
||||
{
|
||||
var databaseCreator = (context.GetService<IDatabaseCreator>() as RelationalDatabaseCreator);
|
||||
if (databaseCreator != null)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
if (!databaseCreator.Exists())
|
||||
databaseCreator.Create();
|
||||
databaseCreator.CreateTables();
|
||||
}
|
||||
catch
|
||||
{
|
||||
//continue
|
||||
}
|
||||
|
||||
}
|
||||
id = staff.InsertOneUser();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
app.UseMiddleware<JwtMiddleware>();
|
||||
// Configure the HTTP request pipeline.
|
||||
//if (app.Environment.IsDevelopment())//
|
||||
//{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
//}
|
||||
// global cors policy
|
||||
|
||||
app.UseCors(x => x
|
||||
.SetIsOriginAllowed(origin => true)
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
|
||||
.WithExposedHeaders("Content-Disposition")
|
||||
.AllowCredentials()); // 👈 MANDATORY: Permits cookie exchange
|
||||
|
||||
//app.UseCors(myAllowSpecificOrigins);
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
app.Run();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
/*
|
||||
https://www.youtube.com/watch?v=WQFx2m5Ub9M
|
||||
|
||||
|
||||
https://csharptotypescript.azurewebsites.net/
|
||||
\ services.AddDbContext<BloggingContext>(options =>
|
||||
options.UseNpgsql(Configuration.GetConnectionString("BloggingContext")));
|
||||
dotnet ef dbcontext scaffold "host=postgresdb;port=5432;Database=carparkvalidationdb;Username=postgres;password=Positive~1" Npgsql.EntityFrameworkCore.PostgreSQL -Schemas schema1 --output-dir Models
|
||||
PM> Scaffold-DbContext "Host=postgresdb;Port=5432;database=carparkvalidationdb;user id=postgres;Password=Positive~1" Npgsql.EntityFrameworkCore.PostgreSQL -OutputDir Models
|
||||
*/
|
||||
|
||||
/*
|
||||
graphql
|
||||
https://www.youtube.com/watch?v=HnXA8RI7Tvc
|
||||
|
||||
query {
|
||||
persons {
|
||||
nodes{
|
||||
id
|
||||
firstName
|
||||
sex
|
||||
email
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"CarParkValidationAPI": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": "true",
|
||||
"applicationUrl": "http://localhost:5100"
|
||||
},
|
||||
"Docker": {
|
||||
"commandName": "Docker",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
|
||||
"publishAllPorts": true
|
||||
}
|
||||
},
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iis": {
|
||||
"applicationUrl": "http://localhost/CarParkValidationAPI",
|
||||
"sslPort": 0
|
||||
},
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:61744",
|
||||
"sslPort": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
//using BCryptNet = BCrypt.Net.BCrypt;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Options;
|
||||
using CarParkValidationAPI.Authorization;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Helpers;
|
||||
using CarParkValidationAPI.Models.Users;
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Datas;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
public class AdminUserRepository : IAdminUser
|
||||
{
|
||||
private DataContext _context;
|
||||
private string _currentUser = "";
|
||||
private readonly AppSettings _appSettings;
|
||||
private Dictionary<int, string> _ValidationPointDic = null;
|
||||
|
||||
|
||||
public AdminUserRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
public void SetCurrentUser(string username)
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
private string GetValidtionPointDesc(int id)
|
||||
{
|
||||
string result = "";
|
||||
if (_ValidationPointDic != null && _ValidationPointDic.ContainsKey(id))
|
||||
result = _ValidationPointDic[id];
|
||||
return result;
|
||||
}
|
||||
private AdminUserViewDto FillAdminUserViewDto(AdminUser model)
|
||||
{
|
||||
AdminUserViewDto dto = new AdminUserViewDto();
|
||||
dto.Id = model.Id;
|
||||
dto.FirstName = model.FirstName;
|
||||
dto.RoleType = (int) model.RoleType;
|
||||
dto.StafflinkNo = model.StafflinkNo;
|
||||
dto.Active = model.Active;
|
||||
dto.LastName = model.LastName;
|
||||
dto.AddedOn = Helper.DateToStr(model.AddedOn);
|
||||
dto.ValidationPoint = GetValidtionPointDesc(model.ValidationPointId??0);
|
||||
dto.ValidationPointId = model.ValidationPointId ?? 0;
|
||||
return dto;
|
||||
}
|
||||
private AdminUserDto FillAdminUserDto(AdminUser model)
|
||||
{
|
||||
AdminUserDto dto = new AdminUserDto();
|
||||
dto.Id = model.Id;
|
||||
dto.FirstName = model.FirstName;
|
||||
dto.RoleType = model.RoleType;
|
||||
dto.StafflinkNo = model.StafflinkNo;
|
||||
dto.Active = model.Active;
|
||||
dto.LastName = model.LastName;
|
||||
dto.AddedOn = Helper.DateToStr(model.AddedOn);
|
||||
dto.ValidationPointId = model.ValidationPointId ?? 0;
|
||||
return dto;
|
||||
}
|
||||
|
||||
private AdminUser FillAdminUser(AdminUserDto dto, AdminUser model)
|
||||
{
|
||||
if (dto.Id > 0)
|
||||
model.Id = dto.Id;
|
||||
model.FirstName = dto.FirstName;
|
||||
model.RoleType = (int) dto.RoleType;
|
||||
model.StafflinkNo = dto.StafflinkNo;
|
||||
model.Active = dto.Active ?? false;
|
||||
model.LastName = dto.LastName;
|
||||
model.AddedOn = Helper.StrToDate(dto.AddedOn);
|
||||
model.ValidationPointId = dto.ValidationPointId;
|
||||
return model;
|
||||
}
|
||||
|
||||
public async Task<ResultModel<List<AdminUserViewDto>>> LoadAdminUserAsync(bool onlyActive)
|
||||
{
|
||||
List<AdminUserViewDto> resultList = new List<AdminUserViewDto>();
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
_ValidationPointDic = await _context.Validations.Where(x => x.Active == true).ToDictionaryAsync((x) => x.Id, y => y.Description);
|
||||
|
||||
//var list = await _context.AdminUsers.Where(x => x.Active == onlyActive).ToListAsync();
|
||||
var list = await _context.AdminUsers.AsQueryable().ToListAsync();
|
||||
|
||||
AdminUserViewDto dto;
|
||||
AdminUser user;
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
user = list[i];
|
||||
dto = FillAdminUserViewDto(user);
|
||||
resultList.Add(dto);
|
||||
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<List<AdminUserViewDto>>()
|
||||
{
|
||||
Data = resultList,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<bool>> CheckAdminUserByStaffLinkNoAsync(string staffLinkNo)
|
||||
{
|
||||
bool result = false;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(staffLinkNo))
|
||||
{
|
||||
var list = await _context.AdminUsers.Where( x=> x.StafflinkNo == staffLinkNo).ToListAsync();
|
||||
if (list.Count > 0)
|
||||
{
|
||||
result = true;
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id)
|
||||
{
|
||||
AdminUserDto result = null;
|
||||
int statuscode = -1;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
AdminUser model = await _context.AdminUsers.FindAsync(id);
|
||||
result = FillAdminUserDto(model);
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<AdminUserDto>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<int>> SaveAdminUserAsync(AdminUserDto item)
|
||||
{
|
||||
int result = default(int);
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
AdminUser model;
|
||||
if (item.Id > 0)
|
||||
{
|
||||
model = await _context.AdminUsers.FindAsync(item.Id);
|
||||
model = FillAdminUser(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
await _context.SaveChangesAsync();
|
||||
result = model.Id;
|
||||
statuscode = 1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
ResultModel<bool> found = await CheckAdminUserByStaffLinkNoAsync(item.StafflinkNo);
|
||||
|
||||
if (!found.Data)
|
||||
{
|
||||
model = new AdminUser();
|
||||
model = FillAdminUser(item, model);
|
||||
_context.AdminUsers.Add(model);
|
||||
await _context.SaveChangesAsync();
|
||||
result = model.Id;
|
||||
statuscode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
error = "staff link No '" + item.StafflinkNo + "' already in admin user";
|
||||
statuscode = 0;
|
||||
result = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = -1;
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<bool>> DeleteAdminUserAsync(int id)
|
||||
{
|
||||
bool result = true;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
AdminUser model = await _context.AdminUsers.FindAsync(id);
|
||||
model.Active = false;
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
result = false;
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
//using BCryptNet = BCrypt.Net.BCrypt;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Options;
|
||||
using CarParkValidationAPI.Authorization;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Helpers;
|
||||
using CarParkValidationAPI.Models.Users;
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Datas;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
|
||||
namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
public class ConcessionTypeRepository : IConcessionType
|
||||
{
|
||||
private DataContext _context;
|
||||
private string _currentUser = "";
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public ConcessionTypeRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
public void SetCurrentUser(string username)
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
private ConcessionTypeDto FillConcessionTypeDto(ConcessionType model)
|
||||
{
|
||||
ConcessionTypeDto dto = new ConcessionTypeDto();
|
||||
dto.Active = model.Active;
|
||||
dto.Description = model.ConcessionDesc;
|
||||
dto.Display = model.ConcessionDisplay;
|
||||
dto.Id = model.Id;
|
||||
return dto;
|
||||
}
|
||||
private ConcessionType FillConcessionType(ConcessionTypeDto dto, ConcessionType model)
|
||||
{
|
||||
model.Active = dto.Active;
|
||||
model.ConcessionDesc = dto.Description.Trim();
|
||||
if (!string.IsNullOrEmpty(dto.Display))
|
||||
model.ConcessionDisplay = dto.Display.Trim();
|
||||
|
||||
return model;
|
||||
}
|
||||
public async Task<ResultModel<List<ConcessionTypeDto>>> LoadConcessionTypeAsync(bool onlyActive)
|
||||
{
|
||||
List<ConcessionTypeDto> result = null;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
|
||||
result = await _context.ConcessionTypes.Select(
|
||||
x => new ConcessionTypeDto()
|
||||
{
|
||||
Id = x.Id,
|
||||
Description = x.ConcessionDesc,
|
||||
Display = x.ConcessionDisplay,
|
||||
Active = x.Active
|
||||
}).ToListAsync();
|
||||
|
||||
statuscode = 1;
|
||||
result.Sort((x, y) => x.Description.CompareTo(y.Description));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<List<ConcessionTypeDto>>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<ConcessionTypeDto>> LoadConcessionTypeByIdAsync(int id)
|
||||
{
|
||||
ConcessionType? result;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
ConcessionTypeDto dto =new();
|
||||
try
|
||||
{
|
||||
result = await _context.ConcessionTypes.FindAsync(id);
|
||||
if (result != null)
|
||||
{
|
||||
dto = FillConcessionTypeDto(result);
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
|
||||
}
|
||||
return new ResultModel<ConcessionTypeDto>()
|
||||
{
|
||||
Data = dto,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<int>> SaveConcessionTypeAsync(ConcessionTypeDto item)
|
||||
{
|
||||
int result = default(int);
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
ConcessionType model;
|
||||
if (item.Id > 0)
|
||||
{
|
||||
model = await _context.ConcessionTypes.FindAsync(item.Id);
|
||||
model = FillConcessionType(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
await _context.SaveChangesAsync();
|
||||
result = item.Id;
|
||||
}
|
||||
else //new record
|
||||
{
|
||||
model = new ConcessionType();
|
||||
model = FillConcessionType(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
_context.ConcessionTypes.Add(model);
|
||||
var id = await _context.SaveChangesAsync();
|
||||
result = model.Id;
|
||||
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
|
||||
}
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<bool>> DeleteConcessionTypeAsync(int id)
|
||||
{
|
||||
bool result = true;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
ConcessionType model;
|
||||
if (id > 0)
|
||||
{
|
||||
model = await _context.ConcessionTypes.FindAsync(id);
|
||||
model.Active = false;
|
||||
//_context.ConcessionTypes.Remove(model);
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
|
||||
}
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
using CarParkValidationAPI.Datas;
|
||||
using CarParkValidationAPI.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using SpreadsheetLight;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using System.IO;
|
||||
|
||||
namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
public class ConcessionValidationReportRepository
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
private readonly IOptions<AppSettings> _appSettings;
|
||||
const string DateFormat = "dd-MM-yyyy HH:mm";
|
||||
const string dateFormat = "dd-MM-yyyyy";
|
||||
public ConcessionValidationReportRepository(
|
||||
DataContext context, IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings;
|
||||
}
|
||||
|
||||
public async Task<ResultModel<FileContent>> GetConcessionValidationReport(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
//excel SLDocument sl = new SLDocument();
|
||||
int statusCode = 1;
|
||||
ConcessionValidationExtDto item;
|
||||
int col = 1;
|
||||
int row = 1;
|
||||
SLDocument sl = new SLDocument();
|
||||
|
||||
|
||||
//first sheetName
|
||||
sl.RenameWorksheet(SLDocument.DefaultFirstSheetName, "ConcessionValidation");
|
||||
SLStyle style = sl.CreateStyle();
|
||||
style.SetFontUnderline(DocumentFormat.OpenXml.Spreadsheet.UnderlineValues.Single);
|
||||
style.SetFontBold(true);
|
||||
style.SetFont("Arial Black", 16);
|
||||
sl.SetCellStyle(1, 5, style);
|
||||
sl.SetRowHeight(1, 1, 25);
|
||||
sl.SetCellValue(row++, 5, "The Concession Validation Report");
|
||||
sl.SetCellValue(row, 3, "Date Range: " + fromDate.ToString(dateFormat) + " - " + toDate.ToString(dateFormat) );
|
||||
sl.SetCellValue(1, 6, " " + DateTime.Now.ToString("ddd dd/MM/yyyy HH:mm"));
|
||||
|
||||
int startTitleRow = 3;
|
||||
row = startTitleRow;
|
||||
//make the title bold
|
||||
style = sl.CreateStyle();
|
||||
style.Font.Bold = true;
|
||||
sl.SetRowStyle(startTitleRow, style);
|
||||
//set it height
|
||||
sl.SetRowHeight(startTitleRow, startTitleRow, 25);
|
||||
// add the title first
|
||||
sl.SetCellValue(row, col++, "Date");
|
||||
sl.SetCellValue(row, col++, "Concession Card Number");
|
||||
sl.SetCellValue(row, col++, "Concession Holder Name");
|
||||
sl.SetCellValue(row, col++, "Expiry date checked");
|
||||
sl.SetCellValue(row, col++, "ConcessionType");
|
||||
sl.SetCellValue(row, col++, "Validation Piont");
|
||||
// sl.SetCellValue(row, col++, "StaffLink No");
|
||||
sl.SetCellValue(row, col++, "Enter by");
|
||||
// sl.SetCellValue(row, col++, "Staff Last name");
|
||||
// sl.SetCellValue(row, col++, "Staff Email");
|
||||
sl.FreezePanes(row, col - 1); //frozen the row.
|
||||
//wrap text on is concession Expiry
|
||||
style = sl.CreateStyle();
|
||||
style.SetWrapText(true);
|
||||
sl.SetColumnStyle(4, style);
|
||||
|
||||
//format date
|
||||
|
||||
style = sl.CreateStyle();
|
||||
style.FormatCode = "dd/MM/yyyy HH:MM";
|
||||
sl.SetColumnStyle(1, style);
|
||||
//make column width
|
||||
sl.SetColumnWidth(1, 20);
|
||||
sl.SetColumnWidth(2, 18);
|
||||
sl.SetColumnWidth(3, 25);
|
||||
sl.SetColumnWidth(4, 20);
|
||||
sl.SetColumnWidth(5, 50);
|
||||
sl.SetColumnWidth(6, 40);
|
||||
sl.SetColumnWidth(7, 40);
|
||||
// sl.SetColumnWidth(8, 20);
|
||||
// sl.SetColumnWidth(9, 20);
|
||||
// sl.SetColumnWidth(10, 20);
|
||||
int startRowFrom = startTitleRow+1;
|
||||
var list = await _context.SelectConcessionValidationByDate(true, fromDate.ToLocalTime(), toDate.ToLocalTime());
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
col = 1;
|
||||
item = list[i];
|
||||
row = i + startRowFrom;
|
||||
sl.SetCellValue(row, col++, item.ValidateDate);
|
||||
sl.SetCellValue(row, col++, item.ConcessionCard);
|
||||
sl.SetCellValue(row, col++, item.ConcessionHolder);
|
||||
sl.SetCellValue(row, col++, item.ConcessionExpiry ? "Yes": "No");
|
||||
sl.SetCellValue(row, col++, item.ConcessionType);
|
||||
sl.SetCellValue(row, col++, item.ValidationPoint);
|
||||
// sl.SetCellValue(row, col++, item.StafflinkNo);
|
||||
sl.SetCellValue(row, col++, item.StaffFirstName + " " + item.StaffLastName);
|
||||
// sl.SetCellValue(row, col++, item.StaffLastName);
|
||||
// sl.SetCellValue(row, col++, item.StaffEmail);
|
||||
}
|
||||
byte[] array;
|
||||
// sl.SaveAs("C:\\Temp\\Report\\ConcessionValidationDate" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xlsx");
|
||||
using (MemoryStream ws = new MemoryStream())
|
||||
{
|
||||
sl.SaveAs(ws);
|
||||
array = ws.ToArray();
|
||||
/*
|
||||
using (FileStream fs = new FileStream("c:\\temp\\Report\\conReport.xlsx",FileMode.Create,FileAccess.Write))
|
||||
{
|
||||
ws.WriteTo(fs);
|
||||
fs.Close();
|
||||
}
|
||||
*/
|
||||
ws.Close();
|
||||
}
|
||||
|
||||
var result = new FileContent
|
||||
{
|
||||
Content = array,
|
||||
FileName = "ConcessionValidation" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm")+ ".xlsx",
|
||||
|
||||
};
|
||||
|
||||
return new ResultModel<FileContent>
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statusCode
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,371 @@
|
||||
//using BCryptNet = BCrypt.Net.BCrypt;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Options;
|
||||
using CarParkValidationAPI.Authorization;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Helpers;
|
||||
using CarParkValidationAPI.Models.Users;
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Datas;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
public class ConcessionValidationRepository : IConcessionValidation
|
||||
{
|
||||
private DataContext _context;
|
||||
private string _currentUser = "";
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public ConcessionValidationRepository(
|
||||
DataContext context,
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
public void SetCurrentUser(string username)
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
private ConcessionValidationDto FillConcessionValidationDto(ConcessionValidation model)
|
||||
{
|
||||
ConcessionValidationDto dto = new ConcessionValidationDto();
|
||||
dto.Active = model.Active;
|
||||
dto.ConcessionCard = model.ConcessionCard;
|
||||
dto.ConcessionExpiry = model.ConcessionExpiry;
|
||||
dto.ConcessionHolder = model.ConcessionHolder;
|
||||
dto.ConcessionTypeId = model.ConcessionTypeID;
|
||||
dto.Id = model.Id;
|
||||
dto.StafflinkNo = model.StafflinkNo;
|
||||
dto.ValidateDate = model.ValidateDate;
|
||||
dto.ValidationPointId = model.ValidationPointID;
|
||||
dto.StaffFirstName = model.StaffFirstName;
|
||||
dto.StaffLastName = model.StaffLastName;
|
||||
dto.StaffEmail = model.StaffEmail;
|
||||
return dto;
|
||||
}
|
||||
|
||||
private ConcessionValidationExtDto FillConcessionValidationExtDto(ConcessionValidation model)
|
||||
{
|
||||
ConcessionValidationExtDto dto = new ConcessionValidationExtDto();
|
||||
dto.Active = model.Active;
|
||||
dto.ConcessionCard = model.ConcessionCard;
|
||||
dto.ConcessionExpiry = model.ConcessionExpiry;
|
||||
dto.ConcessionHolder = model.ConcessionHolder;
|
||||
dto.ConcessionTypeId = model.ConcessionTypeID;
|
||||
dto.Id = model.Id;
|
||||
dto.StaffFirstName = model.StaffFirstName;
|
||||
dto.StaffLastName = model.StaffLastName;
|
||||
dto.StaffEmail = model.StaffEmail;
|
||||
dto.ValidateDate = model.ValidateDate;
|
||||
dto.ValidationPointId = model.ValidationPointID;
|
||||
return dto;
|
||||
}
|
||||
|
||||
private ConcessionValidation FillConcessionValidation(ConcessionValidationDto dto, ConcessionValidation model)
|
||||
{
|
||||
model.Active = dto.Active;
|
||||
model.ConcessionCard = dto.ConcessionCard.Trim();
|
||||
model.ConcessionExpiry = dto.ConcessionExpiry;
|
||||
model.ConcessionHolder = dto.ConcessionHolder.Trim();
|
||||
model.ConcessionTypeID = dto.ConcessionTypeId;
|
||||
|
||||
model.StafflinkNo = dto.StafflinkNo;
|
||||
model.StaffFirstName = dto.StaffFirstName.Trim();
|
||||
model.StaffLastName = dto.StaffLastName.Trim();
|
||||
model.StaffEmail = dto.StaffEmail.Trim();
|
||||
model.ValidateDate = dto.ValidateDate.ToLocalTime();
|
||||
model.ValidationPointID = dto.ValidationPointId;
|
||||
return model;
|
||||
}
|
||||
public async Task<ResultModel<List<ConcessionValidationExtDto>>> LoadConcessionValidationAsync(bool onlyActive)
|
||||
{
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
List<ConcessionValidationExtDto> result = new List<ConcessionValidationExtDto>();
|
||||
|
||||
ConcessionValidationExtDto dto;
|
||||
ConcessionValidation model;
|
||||
try
|
||||
{
|
||||
List<ConcessionValidation> clist = await _context.ConcessionValidations.Where(x => x.Active == true).ToListAsync();
|
||||
for (int i = 0; i < clist.Count; i++)
|
||||
{
|
||||
model = clist[i];
|
||||
dto = FillConcessionValidationExtDto(model);
|
||||
result.Add(dto);
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
statuscode = -1;
|
||||
error = ex.ToString();
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<List<ConcessionValidationExtDto>>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<List<ConcessionValidationExtDto>>> LoadConcessionValidationStaffLinkNoAsync(string staffLinkNo, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
List<ConcessionValidationExtDto> result = new List<ConcessionValidationExtDto>();
|
||||
// ConcessionValidationExtDto dto;
|
||||
// ConcessionValidation model;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
//List<ConcessionValidation> clist = await _context.ConcessionValidations.Where(x =>
|
||||
// x.Active == true
|
||||
// && x.StafflinkNo == staffLinkNo
|
||||
// && x.ValidateDate.Date == currentDate.Date
|
||||
//).ToListAsync();
|
||||
result = await _context.SelectConcessionValidationByStaffId(true, staffLinkNo, fromDate, toDate);
|
||||
/*
|
||||
//var clist = await _context.SPSelectValidation(true, staffLinkNo, currentDate);
|
||||
for (int i = 0; i < clist.Count; i++)
|
||||
{
|
||||
model = clist[i];
|
||||
dto = FillConcessionValidationExtDto(model);
|
||||
result.Add(dto);
|
||||
}
|
||||
*/
|
||||
statuscode = 1;
|
||||
result.Sort((x, y) => x.ValidateDate.CompareTo(y.ValidateDate));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
statuscode = -1;
|
||||
error = ex.ToString();
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<List<ConcessionValidationExtDto>>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<int>> CheckConcessionValidationStaffLinkNoAsync(string staffLinkNo, string concessionCard, DateTime currentDate, int id)
|
||||
{
|
||||
int statuscode = 1;
|
||||
int result = 1;
|
||||
int number = id < 1 ? 0 : 1; // if insert check > 0 . if modify > 1
|
||||
string message = "warning you already add concession card on this date!";
|
||||
try
|
||||
{
|
||||
var anyRecord = await _context.SelectCheckConcessionValidationAsync(currentDate.ToLocalTime().Date, concessionCard.Trim(), staffLinkNo.Trim());
|
||||
|
||||
if (anyRecord.Count > number)
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 1; //test
|
||||
message = "test OK just one time";
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
message = "Error " + ex.ToString();
|
||||
statuscode = -1;
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = message,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public async Task<ResultModel<int>> CheckConcessionValidationStaffLinkNoAsync_old(string staffLinkNo, string concessionCard, DateTime currentDate)
|
||||
{
|
||||
int statuscode = 1;
|
||||
int result = 1;
|
||||
string concard = concessionCard.Trim();
|
||||
string message = "warning you already add concession card on this date!";
|
||||
try
|
||||
{
|
||||
var anyRecord = await _context.ConcessionValidations.Where(x =>
|
||||
x.StafflinkNo == staffLinkNo
|
||||
&& x.ConcessionCard == concard
|
||||
&& x.Active == true
|
||||
&& x.ValidateDate.Date == currentDate.ToLocalTime().Date
|
||||
).ToListAsync();
|
||||
if (anyRecord.Count > 0)
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 1; //test
|
||||
message = "test OK just one time";
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
message = "Error " + ex.ToString();
|
||||
statuscode = -1;
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = message,
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<ConcessionValidationDto>> LoadConcessionValidationByIdAsync(int id)
|
||||
{
|
||||
ConcessionValidationDto result = null;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
ConcessionValidation model = await _context.ConcessionValidations.FindAsync(id);
|
||||
result = FillConcessionValidationDto(model);
|
||||
statuscode = 1;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
statuscode = -1;
|
||||
error = ex.ToString();
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<ConcessionValidationDto>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<int>> SaveConcessionValidationAsync(ConcessionValidationDto item)
|
||||
{
|
||||
int result = default(int);
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
//_currentUser = item.StafflinkNo;
|
||||
try
|
||||
{
|
||||
ConcessionValidation model;
|
||||
if (item.Id > 0)
|
||||
{
|
||||
model = await _context.ConcessionValidations.FindAsync(item.Id);
|
||||
model = FillConcessionValidation(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
result = await _context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new ConcessionValidation();
|
||||
model = FillConcessionValidation(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
model.CreatedDate = DateTime.Now;
|
||||
model.CreatedId = _currentUser;
|
||||
_context.ConcessionValidations.Add(model);
|
||||
result = await _context.SaveChangesAsync();
|
||||
result = model.Id;
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
statuscode = -1;
|
||||
error = ex.ToString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public async Task<ResultModel<bool>> DeleteConcessionValidationAsync(int id)
|
||||
{
|
||||
bool result = true;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
ConcessionValidation model = await _context.ConcessionValidations.FindAsync(id);
|
||||
model.Active = false;
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
//_context.ConcessionValidations.Remove(model);
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = false;
|
||||
statuscode = -1;
|
||||
error = ex.ToString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<FileContent>> GetReport(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
int statusCode = 1;
|
||||
string fileContext = "filecontain as string this is file contain in string format";
|
||||
//await this._concessionValidationReport.GetConcessionValidationReport(DateTime.Today.AddDays(-30), DateTime.Today.AddDays(30));
|
||||
var result = new FileContent
|
||||
{
|
||||
Content = Convert.FromBase64String(fileContext),
|
||||
FileName = "excel extension"
|
||||
};
|
||||
var task = await Task.Run(() => 1);
|
||||
return new ResultModel<FileContent>
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statusCode
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
//using BCryptNet = BCrypt.Net.BCrypt;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Options;
|
||||
using CarParkValidationAPI.Authorization;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Helpers;
|
||||
using CarParkValidationAPI.Models.Users;
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Datas;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace CarParkValidationAPI.Repository;
|
||||
|
||||
|
||||
public class LookupCodeRepository: ILookupCode
|
||||
{
|
||||
private DataContext _context;
|
||||
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public LookupCodeRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
public async Task<ResultModel<List<LookupCodeDto>>> LoadConcessionTypeAsync(bool onlyActive)
|
||||
{
|
||||
List<LookupCodeDto> result = null;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
result = await _context.ConcessionTypes.Where(x => x.Active == onlyActive).Select(
|
||||
x => new LookupCodeDto()
|
||||
{
|
||||
Id = x.Id,
|
||||
Description = x.ConcessionDesc,
|
||||
|
||||
}).ToListAsync();
|
||||
statuscode = 1;
|
||||
result.Sort((x,y) => x.Description.CompareTo(y.Description));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
statuscode = -1;
|
||||
error = ex.ToString();
|
||||
|
||||
}
|
||||
return new ResultModel<List<LookupCodeDto>>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<List<LookupCodeDto>>> LoadValidationPointAsync(bool onlyActive)
|
||||
{
|
||||
List<LookupCodeDto> result = null;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
|
||||
result = await _context.Validations.Where(x => x.Active == onlyActive).Select(
|
||||
x => new LookupCodeDto()
|
||||
{
|
||||
Id = x.Id,
|
||||
Description = x.Description
|
||||
}).ToListAsync();
|
||||
result.Sort((x, y) => x.Description.CompareTo(y.Description));
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
statuscode = -1;
|
||||
error = ex.ToString();
|
||||
|
||||
}
|
||||
return new ResultModel<List<LookupCodeDto>>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Linq;
|
||||
using CarParkValidationAPI.Datas;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace CarParkValidationAPI.Repository;
|
||||
|
||||
public class Seed
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
public Seed(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public int InsertOneUser()
|
||||
{
|
||||
int id = -1;
|
||||
//password = password
|
||||
string txt = " INSERT INTO \"AdminUser\" ( " +
|
||||
" \"StafflinkNo\", \"FirstName\",\"LastName\", \"Email\", \"AddedOn\", \"RoleType\",\"Active\") " +
|
||||
"VALUES" +
|
||||
" ( '60249360','kham', 'vilaythong', 'kham.vilaythong@gmail.com','2025-09-01', 1, TRUE), " +
|
||||
" ( '60249362', 'Sy', 'vilaythong','sy.vilaythong@gmail.com','2025-09-01', 1, TRUE), " +
|
||||
" ( '60249363', 'Hung', 'Nguyen', 'hung.nguyen@gmail.com', '2025-09-01', 1, TRUE); ";
|
||||
string validationPoint = "INSERT INTO \"ValidationPoint\" (" +
|
||||
"\"DisplayName\", \"Description\",\"Active\" )" +
|
||||
"VALUES" +
|
||||
"('Y', 'MAIN Gate', TRUE), " +
|
||||
"('Y', 'NORTH Gate', TRUE), " +
|
||||
"('Y', 'SOUTH Gate', TRUE) ";
|
||||
|
||||
string concessType = "INSERT INTO \"ConcessionType\" (" +
|
||||
"\"ConcessionDesc\", \"ConcessionDisplay\", \"Active\")" +
|
||||
"VALUES ('Senior Card', 'Y', TRUE)," +
|
||||
"('Student Card', 'Y', TRUE)," +
|
||||
"('Pensioners Card', 'Y', TRUE)," +
|
||||
"('Yunior Card', 'Y', TRUE)";
|
||||
try
|
||||
{
|
||||
int count = _context.AdminUsers.Count();
|
||||
if (count < 1)
|
||||
{
|
||||
var conn = _context.Database.GetDbConnection();
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
var command = conn.CreateCommand();
|
||||
command.CommandText = txt;
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
command.ExecuteNonQuery();
|
||||
command.CommandText = validationPoint;
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
command.ExecuteNonQuery();
|
||||
command.CommandText = concessType;
|
||||
command.CommandType = System.Data.CommandType.Text;
|
||||
command.ExecuteNonQuery();
|
||||
id = 9;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
id = -1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
id = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
id = -10;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
//using BCryptNet = BCrypt.Net.BCrypt;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Options;
|
||||
using CarParkValidationAPI.Authorization;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Helpers;
|
||||
using CarParkValidationAPI.Models.Users;
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Datas;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using CommonAD.Models;
|
||||
using CommonAD;
|
||||
|
||||
namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
public class UserServiceFakeRepository : IUserService
|
||||
{
|
||||
private DataContext _context;
|
||||
private IJwtUtils _jwtUtils;
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public UserServiceFakeRepository(
|
||||
DataContext context,
|
||||
IJwtUtils jwtUtils,
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_jwtUtils = jwtUtils;
|
||||
_appSettings = appSettings.Value;
|
||||
|
||||
}
|
||||
public AuthenticateResponse Authenticate(AuthenticateRequest model)
|
||||
{
|
||||
int statuscode = -1;
|
||||
User myUser = new User();
|
||||
|
||||
//now check the adminuser table
|
||||
var user = _context.AdminUsers.
|
||||
SingleOrDefault(x => x.StafflinkNo == model.Username
|
||||
&& x.Active == true);
|
||||
if (user != null)
|
||||
{
|
||||
myUser.Role = (int) user.RoleType;
|
||||
myUser.Id = user.Id;
|
||||
myUser.ValidationPointId = user.ValidationPointId??0;
|
||||
statuscode = 1;
|
||||
}
|
||||
else //not allow
|
||||
{
|
||||
statuscode = 0;
|
||||
myUser.Role = (int) AdminRole.Normal;
|
||||
}
|
||||
|
||||
// authentication successful so generate jwt token
|
||||
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
|
||||
|
||||
return new AuthenticateResponse(myUser, jwtToken);
|
||||
}
|
||||
public async Task<ResultModel<AuthenticateResponse>> LoginApiAD(AuthenticateRequest model)
|
||||
{
|
||||
User user = new User();
|
||||
int statusCode = 1;
|
||||
if (model.Username.ToLower() == "admin")
|
||||
{
|
||||
user.FirstName = model.Username;
|
||||
user.LastName = "LS Test";
|
||||
user.Role = (int)AdminRole.Admin;
|
||||
user.Username = model.Username;
|
||||
user.Email = "admin@mail.com";
|
||||
user.ValidationPointId = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
var userdb = _context.AdminUsers.SingleOrDefault(x => x.StafflinkNo == model.Username);
|
||||
if (userdb != null)
|
||||
{
|
||||
user.Username = model.Username;
|
||||
user.FirstName = userdb.FirstName;
|
||||
user.LastName = " LS Normal";
|
||||
user.Email = userdb.Email;
|
||||
user.Role = userdb.RoleType;
|
||||
user.ValidationPointId = userdb.ValidationPointId ?? 1;
|
||||
}
|
||||
}
|
||||
|
||||
// authentication successful so generate jwt token
|
||||
var jwtToken = _jwtUtils.GenerateJwtToken(user);
|
||||
|
||||
var retval = await Task.Run(() => new AuthenticateResponse(user, jwtToken));
|
||||
return new ResultModel<AuthenticateResponse>()
|
||||
{
|
||||
Data = retval,
|
||||
StatusCode = statusCode
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<AuthenticateResponse>> NLoginApiAD(AuthenticateRequest model)
|
||||
{
|
||||
User myUser = null;
|
||||
AuthenticateResponse retval = null;
|
||||
int statuscode = 0;
|
||||
string webAPIUrl = _appSettings.LoginWebAPI;
|
||||
|
||||
var loginInfo = await CommonAD.WebAPIUtil.GetLoginADAsync(webAPIUrl, "CheckADCredentials", model.Username, model.Password);
|
||||
if (loginInfo != null && loginInfo.result)
|
||||
{
|
||||
myUser = new User();
|
||||
myUser.Email = loginInfo.email;
|
||||
myUser.FirstName = loginInfo.firstName;
|
||||
myUser.LastName = loginInfo.lastName;
|
||||
myUser.Username = loginInfo.stafflinkNo;
|
||||
//now check the adminuser table
|
||||
var user = _context.AdminUsers.SingleOrDefault(x => x.StafflinkNo == model.Username);
|
||||
if (user != null)
|
||||
{
|
||||
myUser.Role = user.RoleType;
|
||||
myUser.Id = user.Id;
|
||||
}
|
||||
else
|
||||
myUser.Role = (int) AdminRole.Normal;
|
||||
|
||||
// validate
|
||||
// if (user == null || !BCryptNet.Verify(model.Password, user.PasswordHash))
|
||||
|
||||
// authentication successful so generate jwt token
|
||||
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
|
||||
statuscode = 1;
|
||||
retval = new AuthenticateResponse(myUser, jwtToken);
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<AuthenticateResponse>()
|
||||
{
|
||||
Data = retval,
|
||||
StatusCode = statuscode
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<AuthenticateResponse>> LoginAD(AuthenticateRequest model)
|
||||
{
|
||||
User myUser = null;
|
||||
AuthenticateResponse retval = null;
|
||||
int statuscode = 0;
|
||||
ADConfig adConfig = new ADConfig()
|
||||
{
|
||||
LDAPPassword = _appSettings.LDAPPassword,
|
||||
LDAPPath = _appSettings.LDAPPath,
|
||||
LDAPUser = _appSettings.LDAPUser,
|
||||
ADTimeOutStr = _appSettings.ADTimeOut
|
||||
};
|
||||
myUser = await Task.Run(() => LoginADStaff(adConfig,model.Username, model.Password));
|
||||
if (!string.IsNullOrEmpty(myUser.Username))
|
||||
{
|
||||
statuscode = 1;
|
||||
// authentication successful so generate jwt token
|
||||
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
|
||||
|
||||
retval = new AuthenticateResponse(myUser, jwtToken);
|
||||
}
|
||||
return new ResultModel<AuthenticateResponse>()
|
||||
{
|
||||
Data = retval,
|
||||
StatusCode = statuscode
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public async Task<ResultModel<User>> SearchApiStaff(string staffLinkNo)
|
||||
{
|
||||
User myUser = null;
|
||||
int statuscode = 0;
|
||||
myUser = new User();
|
||||
myUser.Email = "Facky";
|
||||
myUser.FirstName = "";
|
||||
myUser.LastName = "";
|
||||
myUser.Username = staffLinkNo;
|
||||
statuscode = 0;
|
||||
/*
|
||||
string webAPIUrl = _appSettings.LoginWebAPI;
|
||||
var loginInfo = await CommonAD.WebAPIUtil.SearchStaffAsync(webAPIUrl, "SearchStaff", staffLinkNo);
|
||||
if (loginInfo != null && loginInfo.result)
|
||||
{
|
||||
myUser = new User();
|
||||
myUser.Email = loginInfo.email;
|
||||
myUser.FirstName = loginInfo.firstName;
|
||||
myUser.LastName = loginInfo.lastName;
|
||||
myUser.Username = loginInfo.stafflinkNo;
|
||||
statuscode = 1;
|
||||
}*/
|
||||
|
||||
return new ResultModel<User>()
|
||||
{
|
||||
Data = myUser,
|
||||
StatusCode = statuscode
|
||||
};
|
||||
// return myUser;
|
||||
|
||||
}
|
||||
|
||||
public async Task<ResultModel<User>> SearchADStaff(string staffLinkNo)
|
||||
{
|
||||
int statuscode = 0;
|
||||
ADConfig adConfig = new ADConfig()
|
||||
{
|
||||
LDAPPassword = _appSettings.LDAPPassword,
|
||||
LDAPPath = _appSettings.LDAPPath,
|
||||
LDAPUser = _appSettings.LDAPUser,
|
||||
ADTimeOutStr = _appSettings.ADTimeOut
|
||||
};
|
||||
User myUser = await Task.Run(() => SearchADStaff(adConfig, staffLinkNo));
|
||||
if (!string.IsNullOrEmpty(myUser.Username))
|
||||
statuscode = 1;
|
||||
return new ResultModel<User>()
|
||||
{
|
||||
Data = myUser,
|
||||
StatusCode = statuscode
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
private User SearchADStaff(ADConfig adConfig, string username)
|
||||
{
|
||||
|
||||
|
||||
MyADObject myADObj = new() ;
|
||||
User user = new()
|
||||
{
|
||||
Username = myADObj.stafflinkNo,
|
||||
Email = myADObj.email,
|
||||
FirstName = myADObj.firstName,
|
||||
LastName = myADObj.lastName
|
||||
};
|
||||
// myADObj.JobTitle;
|
||||
return user;
|
||||
|
||||
// return null;
|
||||
}
|
||||
private User LoginADStaff(ADConfig adConfig, string username, string password)
|
||||
{
|
||||
|
||||
|
||||
MyADObject myADObj = new();
|
||||
User user = new()
|
||||
{
|
||||
Username = username,
|
||||
Email = "email",
|
||||
FirstName = username,
|
||||
LastName = "Fake"
|
||||
};
|
||||
// myADObj.JobTitle;
|
||||
return user;
|
||||
|
||||
// return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
//using BCryptNet = BCrypt.Net.BCrypt;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Options;
|
||||
using CarParkValidationAPI.Authorization;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Helpers;
|
||||
using CarParkValidationAPI.Models.Users;
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Datas;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using CommonAD.Models;
|
||||
using CommonAD;
|
||||
|
||||
namespace CarParkValidationAPI.Repository;
|
||||
|
||||
public class UserServiceRepository : IUserService
|
||||
{
|
||||
private DataContext _context;
|
||||
private IJwtUtils _jwtUtils;
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public UserServiceRepository(
|
||||
DataContext context,
|
||||
IJwtUtils jwtUtils,
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_jwtUtils = jwtUtils;
|
||||
_appSettings = appSettings.Value;
|
||||
|
||||
}
|
||||
|
||||
public AuthenticateResponse Authenticate(AuthenticateRequest model)
|
||||
{
|
||||
User myUser = new();
|
||||
var adminUser = _context.AdminUsers.SingleOrDefault(x => x.StafflinkNo == model.Username);
|
||||
if (adminUser != null)
|
||||
{
|
||||
myUser.Id = adminUser.Id;
|
||||
myUser.Email = adminUser.Email;
|
||||
myUser.FirstName = adminUser.FirstName;
|
||||
myUser.LastName = adminUser.LastName;
|
||||
myUser.Role = adminUser.RoleType;
|
||||
}
|
||||
// validate
|
||||
// if (user == null || !BCryptNet.Verify(model.Password, user.PasswordHash))
|
||||
// if (adminUser == null || (model.Password != adminUser.PasswordHash))
|
||||
// throw new System.Exception("Username or password is incorrect");
|
||||
|
||||
// authentication successful so generate jwt token
|
||||
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
|
||||
|
||||
return new AuthenticateResponse(myUser, jwtToken);
|
||||
}
|
||||
|
||||
public async Task<ResultModel<AuthenticateResponse>> LoginApiAD(AuthenticateRequest model)
|
||||
{
|
||||
User myUser = null;
|
||||
AuthenticateResponse retval = null;
|
||||
int statuscode = 0;
|
||||
string webAPIUrl = _appSettings.LoginWebAPI;
|
||||
|
||||
|
||||
myUser = new User();
|
||||
|
||||
//now check the adminuser table
|
||||
var user = _context.AdminUsers.
|
||||
SingleOrDefault(x => x.StafflinkNo == model.Username
|
||||
&& x.Active == true);
|
||||
if (user != null)
|
||||
{
|
||||
myUser.Role = (int) user.RoleType;
|
||||
myUser.Id = user.Id;
|
||||
myUser.ValidationPointId = user.ValidationPointId??0;
|
||||
statuscode = 1;
|
||||
}
|
||||
else //not allow
|
||||
{
|
||||
statuscode = 0;
|
||||
myUser.Role = (int) AdminRole.Normal;
|
||||
}
|
||||
// validate
|
||||
// if (user == null || !BCryptNet.Verify(model.Password, user.PasswordHash))
|
||||
|
||||
// authentication successful so generate jwt token
|
||||
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
|
||||
//statuscode = 1;
|
||||
retval = new AuthenticateResponse(myUser, jwtToken);
|
||||
|
||||
|
||||
|
||||
return new ResultModel<AuthenticateResponse>()
|
||||
{
|
||||
Data = retval,
|
||||
StatusCode = statuscode
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<AuthenticateResponse>> LoginApiAD_old(AuthenticateRequest model)
|
||||
{
|
||||
User myUser = null;
|
||||
AuthenticateResponse retval = null;
|
||||
int statuscode = 0;
|
||||
string webAPIUrl = _appSettings.LoginWebAPI;
|
||||
|
||||
var loginInfo = await CommonAD.WebAPIUtil.PostLoginADAsync(webAPIUrl, "CheckCredentials", model.Username, model.Password);
|
||||
if (loginInfo != null && loginInfo.result)
|
||||
{
|
||||
myUser = new User();
|
||||
myUser.Email = loginInfo.email;
|
||||
myUser.FirstName = loginInfo.firstName;
|
||||
myUser.LastName = loginInfo.lastName;
|
||||
myUser.Username = loginInfo.stafflinkNo;
|
||||
//now check the adminuser table
|
||||
var user = _context.AdminUsers.
|
||||
SingleOrDefault(x => x.StafflinkNo == model.Username
|
||||
&& x.Active == true);
|
||||
if (user != null)
|
||||
{
|
||||
myUser.Role = (int) user.RoleType;
|
||||
myUser.Id = user.Id;
|
||||
myUser.ValidationPointId = user.ValidationPointId ?? 0;
|
||||
statuscode = 1;
|
||||
}
|
||||
else //not allow
|
||||
{
|
||||
statuscode = 0;
|
||||
myUser.Role = (int) AdminRole.Normal;
|
||||
}
|
||||
// validate
|
||||
// if (user == null || !BCryptNet.Verify(model.Password, user.PasswordHash))
|
||||
|
||||
// authentication successful so generate jwt token
|
||||
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
|
||||
//statuscode = 1;
|
||||
retval = new AuthenticateResponse(myUser, jwtToken);
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<AuthenticateResponse>()
|
||||
{
|
||||
Data = retval,
|
||||
StatusCode = statuscode
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<AuthenticateResponse>> LoginAD(AuthenticateRequest model)
|
||||
{
|
||||
User myUser = null;
|
||||
AuthenticateResponse retval = null;
|
||||
int statuscode = 0;
|
||||
ADConfig adConfig = new ADConfig()
|
||||
{
|
||||
LDAPPassword = _appSettings.LDAPPassword,
|
||||
LDAPPath = _appSettings.LDAPPath,
|
||||
LDAPUser = _appSettings.LDAPUser,
|
||||
ADTimeOutStr = _appSettings.ADTimeOut
|
||||
};
|
||||
myUser = await Task.Run(() => LoginADStaff(adConfig,model.Username, model.Password));
|
||||
if (!string.IsNullOrEmpty(myUser.Username))
|
||||
{
|
||||
statuscode = 1;
|
||||
// authentication successful so generate jwt token
|
||||
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
|
||||
|
||||
retval = new AuthenticateResponse(myUser, jwtToken);
|
||||
}
|
||||
return new ResultModel<AuthenticateResponse>()
|
||||
{
|
||||
Data = retval,
|
||||
StatusCode = statuscode
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public async Task<ResultModel<User>> SearchApiStaff(string staffLinkNo)
|
||||
{
|
||||
User myUser = null;
|
||||
int statuscode = 0;
|
||||
string webAPIUrl = _appSettings.LoginWebAPI;
|
||||
var loginInfo = await CommonAD.WebAPIUtil.SearchStaffAsync(webAPIUrl, "SearchStaff", staffLinkNo);
|
||||
if (loginInfo != null && loginInfo.result)
|
||||
{
|
||||
myUser = new User();
|
||||
myUser.Email = loginInfo.email;
|
||||
myUser.FirstName = loginInfo.firstName;
|
||||
myUser.LastName = loginInfo.lastName;
|
||||
myUser.Username = loginInfo.stafflinkNo;
|
||||
statuscode = 1;
|
||||
}
|
||||
|
||||
return new ResultModel<User>()
|
||||
{
|
||||
Data = myUser,
|
||||
StatusCode = statuscode
|
||||
};
|
||||
// return myUser;
|
||||
|
||||
}
|
||||
|
||||
public async Task<ResultModel<User>> SearchADStaff(string staffLinkNo)
|
||||
{
|
||||
int statuscode = 0;
|
||||
ADConfig adConfig = new ADConfig()
|
||||
{
|
||||
LDAPPassword = _appSettings.LDAPPassword,
|
||||
LDAPPath = _appSettings.LDAPPath,
|
||||
LDAPUser = _appSettings.LDAPUser,
|
||||
ADTimeOutStr = _appSettings.ADTimeOut
|
||||
};
|
||||
User myUser = await Task.Run(() => SearchADStaff(adConfig, staffLinkNo));
|
||||
if (!string.IsNullOrEmpty(myUser.Username))
|
||||
statuscode = 1;
|
||||
return new ResultModel<User>()
|
||||
{
|
||||
Data = myUser,
|
||||
StatusCode = statuscode
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
private User SearchADStaff(ADConfig adConfig, string username)
|
||||
{
|
||||
|
||||
|
||||
MyADObject myADObj = new();
|
||||
User user = new()
|
||||
{
|
||||
Username = myADObj.stafflinkNo,
|
||||
Email = myADObj.email,
|
||||
FirstName = myADObj.firstName,
|
||||
LastName = myADObj.lastName
|
||||
};
|
||||
// myADObj.JobTitle;
|
||||
return user;
|
||||
|
||||
// return null;
|
||||
}
|
||||
private User LoginADStaff(ADConfig adConfig, string username, string password)
|
||||
{
|
||||
|
||||
|
||||
MyADObject myADObj = new();
|
||||
User user = new()
|
||||
{
|
||||
Username = myADObj.stafflinkNo,
|
||||
Email = myADObj.email,
|
||||
FirstName = myADObj.firstName,
|
||||
LastName = myADObj.lastName
|
||||
};
|
||||
// myADObj.JobTitle;
|
||||
return user;
|
||||
|
||||
// return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
using CarParkValidationAPI.Datas;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using CarParkValidationAPI.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
public class ValidationPointRepository : IValidationPoint
|
||||
{
|
||||
private DataContext _context;
|
||||
|
||||
private readonly AppSettings _appSettings;
|
||||
private string _currentUser = "";
|
||||
private List<ValidationPointDto> _list = new List<ValidationPointDto>();
|
||||
|
||||
public ValidationPointRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
public void SetCurrentUser(string username)
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
private ValidationPointDto FillValidationDto(ValidationPoint item)
|
||||
{
|
||||
ValidationPointDto dto = new ValidationPointDto();
|
||||
dto.Active = item.Active;
|
||||
dto.Description = item.Description;
|
||||
dto.Display = item.DisplayName;
|
||||
dto.Id = item.Id;
|
||||
return dto;
|
||||
}
|
||||
|
||||
private ValidationPoint FillValidationModel(ValidationPointDto item, ValidationPoint model) {
|
||||
|
||||
model.Active = item.Active;
|
||||
model.Description = item.Description.Trim();
|
||||
if (!string.IsNullOrEmpty(item.Display))
|
||||
model.DisplayName = item.Display.Trim();
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public async Task<ResultModel<List<ValidationPointDto>>> LoadValidationPointAsync(bool onlyActive)
|
||||
{
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
var it = await _context.Validations.ToListAsync();
|
||||
|
||||
ValidationPointDto dto;
|
||||
for (int i = 0; i < it.Count; i++)
|
||||
{
|
||||
dto = FillValidationDto(it[i]);
|
||||
_list.Add(dto);
|
||||
}
|
||||
_list.Sort((x, y) => x.Description.CompareTo(y.Description));
|
||||
statuscode = 1;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
|
||||
}
|
||||
return new ResultModel<List<ValidationPointDto>>()
|
||||
{
|
||||
Data = _list,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<ValidationPointDto>> LoadValidationPointByIdAsync(int id)
|
||||
{
|
||||
ValidationPoint result = null;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
ValidationPointDto dto = null;
|
||||
try
|
||||
{
|
||||
result = await _context.Validations.FindAsync(id);
|
||||
dto = FillValidationDto(result);
|
||||
//result = _list.Find(x => x.Id == id);
|
||||
//var dto = await Task.Run(() => result);
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
}
|
||||
return new ResultModel<ValidationPointDto>()
|
||||
{
|
||||
Data = dto,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<int>> SaveValidationPointAsync(ValidationPointDto item)
|
||||
{
|
||||
int result = default(int);
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
ValidationPoint model;
|
||||
if (item.Id > 0)
|
||||
{
|
||||
model = await _context.Validations.FindAsync(item.Id);
|
||||
model = FillValidationModel(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
await _context.SaveChangesAsync();
|
||||
result = item.Id;
|
||||
}
|
||||
else //new record
|
||||
{
|
||||
model = new ValidationPoint();
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
model = FillValidationModel(item, model);
|
||||
_context.Validations.Add(model);
|
||||
var id = await _context.SaveChangesAsync();
|
||||
result = model.Id;
|
||||
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
}
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<bool>> DeleteValidationPointAsync(int id)
|
||||
{
|
||||
bool result = true;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
ValidationPoint model;
|
||||
if (id > 0)
|
||||
{
|
||||
model = await _context.Validations.FindAsync(id);
|
||||
model.Active = false;
|
||||
//_context.Validations.Remove(model);
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = -1;
|
||||
|
||||
}
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
/*
|
||||
"SQLConnectionString": "Server=NEPHICT-040931L;Initial Catalog=CarParkValidation;Persist Security Info=False;User ID=bids_admin;Password=Password4BI;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;",
|
||||
user id=bids_admin;password=Password4BI;
|
||||
Server=tcp:10.60.207.82,1433;
|
||||
*/
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"AppSettings": {
|
||||
"Secret": "Nepean Blue Mountain Super Secret SIGN AND VERIFY JWT TOKENS, BEARER TOKEN USE WHEN CALLING THIS API.",
|
||||
"SQLConnectionString_SQL": "Server=127.0.0.1,1433;Initial Catalog=CarParkValidation;User Id=sa;Password=Positive@2022;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;",
|
||||
"SQLConnectionString": "host=localhost;port=5432;database=CarParkValidation;username=postgres;password=Positive~1;",
|
||||
"LDAPPath": "",
|
||||
"LDAPUser": "S",
|
||||
"LDAPPassword": "",
|
||||
"ADTimeOut": "30",
|
||||
"LoginWebAPI": "http://NEPHMDB-SQL007/CommonWebApiAD/api/AD"
|
||||
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
|
||||
"AllowedHosts": "*"
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,16 @@
|
||||
services:
|
||||
sqlserver:
|
||||
image: mcr.microsoft.com/mssql/server:2022-latest
|
||||
container_name: sqlserver
|
||||
hostname: mydocker-sqlserver
|
||||
environment:
|
||||
- ACCEPT_EULA=Y
|
||||
- MSSQL_SA_PASSWORD=YourStrong!Passw0rdd
|
||||
- MSSQL_PID=Express
|
||||
ports:
|
||||
- "1433:1433"
|
||||
volumes:
|
||||
- mssql_data:/var/opt/mssql/data
|
||||
|
||||
volumes:
|
||||
mssql_data:
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<location path="." inheritInChildApplications="false">
|
||||
<system.webServer>
|
||||
<handlers>
|
||||
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
|
||||
</handlers>
|
||||
<aspNetCore processPath="bin\Debug\net5.0\CarParkValidationAPI.exe" arguments="" stdoutLogEnabled="false" hostingModel="InProcess">
|
||||
<environmentVariables>
|
||||
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
|
||||
</environmentVariables>
|
||||
</aspNetCore>
|
||||
</system.webServer>
|
||||
</location>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user