Add project files.
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,38 @@
|
||||
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(user.Role)))
|
||||
{
|
||||
// not logged in or role not authorized
|
||||
context.Result = new JsonResult(new { message = "Unauthorized" }) { StatusCode = StatusCodes.Status401Unauthorized };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Repository;
|
||||
using CarParkValidationAPI.Interface;
|
||||
namespace CarParkValidationAPI.Authorization
|
||||
{
|
||||
public class JwtMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public JwtMiddleware(RequestDelegate next, IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_next = next;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context, IUserService userService, IJwtUtils jwtUtils)
|
||||
{
|
||||
var token = context.Request.Headers["Authorization"].FirstOrDefault()?.Split(" ").Last();
|
||||
var userId = jwtUtils.ValidateJwtToken(token);
|
||||
if (userId != null)
|
||||
{
|
||||
// attach user to context on successful jwt validation
|
||||
context.Items["User"] = userService.GetById(userId.Value);
|
||||
}
|
||||
|
||||
await _next(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
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())
|
||||
//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);
|
||||
}
|
||||
|
||||
public int? 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);
|
||||
|
||||
// return user id from JWT token if validation successful
|
||||
return userId;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// return null if validation fails
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.9" />
|
||||
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.12.0" />
|
||||
<PackageReference Include="SpreadsheetLight" Version="3.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.5" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CommonAD\CommonAD.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,60 @@
|
||||
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 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)
|
||||
{
|
||||
/*
|
||||
// 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.DeleteAdminUserAsync(id);
|
||||
return Ok(retval);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 ConcessionTypeController : ControllerBase
|
||||
{
|
||||
private IConcessionType _concessionType;
|
||||
|
||||
public ConcessionTypeController(IConcessionType concessionType)
|
||||
{
|
||||
_concessionType = concessionType;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> ConcessionType([FromBody] ConcessionTypeDto model)
|
||||
{
|
||||
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,91 @@
|
||||
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;
|
||||
|
||||
namespace CarParkValidationAPI.Controllers
|
||||
{
|
||||
// [Authorize]
|
||||
[ApiController]
|
||||
[Route("api/v1/[controller]")]
|
||||
public class ConcessionValidationController : ControllerBase
|
||||
{
|
||||
private IConcessionValidation _concessionValidation;
|
||||
private readonly FileExtensionContentTypeProvider _contentTypeProvider;
|
||||
public ConcessionValidationController(IConcessionValidation concessionValidation)
|
||||
{
|
||||
_concessionValidation = concessionValidation;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> ConcessionValidation([FromBody] ConcessionValidationDto model)
|
||||
{
|
||||
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 currentDate)
|
||||
{
|
||||
var retval = await _concessionValidation.LoadConcessionValidationStaffLinkNoAsync(staffLinkNo, currentDate);
|
||||
return Ok(retval);
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
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 (id != currentUser.Id && currentUser.Role != Role.Admin)
|
||||
return Unauthorized(new { message = "Unauthorized" });
|
||||
*/
|
||||
var retval = await _concessionValidation.DeleteConcessionValidationAsync(id);
|
||||
return Ok(retval);
|
||||
}
|
||||
/* download the excel file */
|
||||
[HttpGet("[action]")]
|
||||
|
||||
public async Task<IActionResult> GetReportFile(DateTime fromDate , DateTime toDate)
|
||||
{
|
||||
var result = await _concessionValidation.GetReport(fromDate, toDate);
|
||||
string fileContentType = 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,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,82 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using CarParkValidationAPI.Authorization;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Models.Users;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using System.Threading.Tasks;
|
||||
using CarParkValidationAPI.Models;
|
||||
|
||||
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(AuthenticateRequest model)
|
||||
{
|
||||
var response = _userService.Authenticate(model);
|
||||
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
[AllowAnonymous]
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> LoginAD(AuthenticateRequest model)
|
||||
{
|
||||
var response = await _userService.LoginAD(model);
|
||||
return Ok(response);
|
||||
}
|
||||
[AllowAnonymous]
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> LoginApiAD(AuthenticateRequest model)
|
||||
{
|
||||
var response = await _userService.LoginApiAD(model);
|
||||
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;
|
||||
}
|
||||
|
||||
[Authorize(AdminRole.Admin)]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAllUsers()
|
||||
{
|
||||
var users = await _userService.GetAllUsers();
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
public async Task<IActionResult> GetById(int id)
|
||||
{
|
||||
// only admins can access other user records
|
||||
var currentUser = (User)HttpContext.Items["User"];
|
||||
if (id != currentUser.Id && currentUser.Role != AdminRole.Admin)
|
||||
return Unauthorized(new { message = "Unauthorized" });
|
||||
|
||||
var user = await _userService.GetById(id);
|
||||
return Ok(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
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)
|
||||
{
|
||||
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 (id != currentUser.Id && currentUser.Role != Role.Admin)
|
||||
return Unauthorized(new { message = "Unauthorized" });
|
||||
*/
|
||||
var retval = await _validationPoint.DeleteValidationPointAsync(id);
|
||||
return Ok(retval);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
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");
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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.ValidationPiont = (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)
|
||||
{
|
||||
var pfromDate = new SqlParameter
|
||||
{
|
||||
ParameterName = "fromDate",
|
||||
Value = fromDate.Date
|
||||
};
|
||||
var pStaffLink = new SqlParameter
|
||||
{
|
||||
ParameterName = "StafflinkNo",
|
||||
Value = stafflinkNo
|
||||
};
|
||||
|
||||
var pToDate = new SqlParameter
|
||||
{
|
||||
ParameterName = "toDate",
|
||||
Value = toDate.Date
|
||||
};
|
||||
ConcessionValidationExtDto item;
|
||||
List<ConcessionValidationExtDto> result = new List<ConcessionValidationExtDto>();
|
||||
using (var command = this.Database.GetDbConnection().CreateCommand())
|
||||
{
|
||||
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<ConcessionValidationExtDto>> SelectConcessionValidationByDate(bool activeOnly, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
var pfromDate = new SqlParameter
|
||||
{
|
||||
ParameterName = "fromDate",
|
||||
Value = fromDate.Date
|
||||
};
|
||||
|
||||
|
||||
var pToDate = new SqlParameter
|
||||
{
|
||||
ParameterName = "toDate",
|
||||
Value = toDate.Date
|
||||
};
|
||||
ConcessionValidationExtDto item;
|
||||
List<ConcessionValidationExtDto> result = new List<ConcessionValidationExtDto>();
|
||||
using (var command = this.Database.GetDbConnection().CreateCommand())
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using CarParkValidationAPI.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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 Name { get; set; }
|
||||
|
||||
public string AddedBy { get; set; }
|
||||
|
||||
public DateTime AddedOn { get; set; }
|
||||
|
||||
public bool Active { get; set; }
|
||||
|
||||
public AdminRole RoleType { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -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,37 @@
|
||||
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 ValidationPiont { 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; }
|
||||
#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,8 @@
|
||||
namespace CarParkValidationAPI.Entities
|
||||
{
|
||||
public enum Role
|
||||
{
|
||||
Admin,
|
||||
User
|
||||
}
|
||||
}
|
||||
@@ -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,51 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
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;
|
||||
|
||||
public ErrorHandlerMiddleware(RequestDelegate next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _next(context);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
var response = context.Response;
|
||||
response.ContentType = "application/json";
|
||||
|
||||
switch(error)
|
||||
{
|
||||
// case Exception e:
|
||||
// // custom application error
|
||||
// response.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
// break;
|
||||
case KeyNotFoundException e:
|
||||
// not found error
|
||||
response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
break;
|
||||
default:
|
||||
// unhandled error
|
||||
response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||
break;
|
||||
}
|
||||
|
||||
var result = JsonSerializer.Serialize(new { message = error?.Message });
|
||||
await response.WriteAsync(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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<AdminUserDto>>> LoadAdminUserAsync(bool OnlyActive);
|
||||
Task<ResultModel<int>> SaveAdminUserAsync(AdminUserDto item);
|
||||
Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id);
|
||||
Task<ResultModel<bool>> DeleteAdminUserAsync(int id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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 IConcessionValidation
|
||||
{
|
||||
Task<ResultModel<List<ConcessionValidationExtDto>>> LoadConcessionValidationAsync(bool OnlyActive);
|
||||
Task<ResultModel<List<ConcessionValidationExtDto>>> LoadConcessionValidationStaffLinkNoAsync(string staffLinkNo, DateTime currentDate);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using CarParkValidationAPI.Models;
|
||||
|
||||
|
||||
namespace CarParkValidationAPI.Interface
|
||||
{
|
||||
public interface IJwtUtils
|
||||
{
|
||||
public string GenerateJwtToken(User user);
|
||||
public int? 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,21 @@
|
||||
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<List<User>>> GetAllUsers();
|
||||
Task<ResultModel<User>> GetById(int id);
|
||||
Task<ResultModel<User>> SearchApiStaff(string staffLinkNo);
|
||||
Task<ResultModel<User>> SearchADStaff(string staffLinkNo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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;
|
||||
|
||||
namespace CarParkValidationAPI.Models
|
||||
{
|
||||
public enum AdminRole
|
||||
{
|
||||
Normal = 1,
|
||||
Admin = 2
|
||||
}
|
||||
public partial class AdminUserCriteria
|
||||
{
|
||||
public AdminUserCriteria()
|
||||
{
|
||||
}
|
||||
#region public Member
|
||||
|
||||
public int? UserID { get; set; }
|
||||
|
||||
public int? StafflinkNo { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string AddedBy { get; set; }
|
||||
|
||||
public DateTime? AddedOn { 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 UserID { get; set; }
|
||||
public string StafflinkNo { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string AddedBy { get; set; }
|
||||
|
||||
public DateTime AddedOn { get; set; }
|
||||
|
||||
public bool Active { get; set; }
|
||||
|
||||
public AdminRole RoleType { 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,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 partial class ConcessionType
|
||||
{
|
||||
public ConcessionType()
|
||||
{
|
||||
}
|
||||
#region public Member
|
||||
[Key]
|
||||
public int ConcessionTypeID { get; set; }
|
||||
public string ConcessionDesc { get; set; }
|
||||
|
||||
public string ConcessionDisplay { get; set; }
|
||||
|
||||
public bool Active { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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 ValidationID { 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; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -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,17 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CarParkValidationAPI.Models
|
||||
{
|
||||
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 AdminRole Role { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public string PasswordHash { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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,24 @@
|
||||
using CarParkValidationAPI.Entities;
|
||||
|
||||
namespace CarParkValidationAPI.Models.Users
|
||||
{
|
||||
public class AuthenticateResponse
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string Username { get; set; }
|
||||
public AdminRole Role { get; set; }
|
||||
public string Token { get; set; }
|
||||
|
||||
public AuthenticateResponse(User user, string token)
|
||||
{
|
||||
Id = user.Id;
|
||||
FirstName = user.FirstName;
|
||||
LastName = user.LastName;
|
||||
Username = user.Username;
|
||||
Role = user.Role;
|
||||
Token = token;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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 ValidationPointID { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
public bool Active { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
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.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iis": {
|
||||
"applicationUrl": "http://localhost/CarParkValidationAPI",
|
||||
"sslPort": 0
|
||||
},
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:61744",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "api/v1/LookupCode/ConcessionTypes",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"CarParkValidationAPI": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": "true",
|
||||
"applicationUrl": "http://localhost:5100"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
//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 AdminUserFakeRepository : IAdminUser
|
||||
{
|
||||
private DataContext _context;
|
||||
List<AdminUserDto> _resultList = new List<AdminUserDto>();
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
|
||||
public AdminUserFakeRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
private AdminUserDto FillAdminUserDto(AdminUser model)
|
||||
{
|
||||
AdminUserDto dto = new AdminUserDto();
|
||||
dto.Id = model.UserID;
|
||||
dto.Name = model.Name;
|
||||
dto.RoleType = model.RoleType;
|
||||
dto.StafflinkNo = model.StafflinkNo;
|
||||
dto.Active = model.Active;
|
||||
dto.AddedBy = model.AddedBy;
|
||||
dto.AddedOn = model.AddedOn;
|
||||
return dto;
|
||||
}
|
||||
|
||||
private AdminUser FillAdminUser(AdminUserDto dto, AdminUser model)
|
||||
{
|
||||
|
||||
model.UserID = dto.Id;
|
||||
model.Name = dto.Name;
|
||||
model.RoleType = dto.RoleType;
|
||||
model.StafflinkNo = dto.StafflinkNo;
|
||||
model.Active = dto.Active;
|
||||
model.AddedBy = dto.AddedBy;
|
||||
model.AddedOn = dto.AddedOn;
|
||||
return model;
|
||||
}
|
||||
|
||||
public async Task<ResultModel<List<AdminUserDto>>> LoadAdminUserAsync(bool onlyActive)
|
||||
{
|
||||
/*
|
||||
List<AdminUserDto> resultList = new List<AdminUserDto>();
|
||||
try
|
||||
{
|
||||
var it = await _context.AdminUsers.AsQueryable().ToListAsync();
|
||||
|
||||
AdminUserDto dto;
|
||||
for (int i = 0; i < it.Count; i++)
|
||||
{
|
||||
dto = FillAdminUserDto(it[i]);
|
||||
resultList.Add(dto);
|
||||
}
|
||||
//var it = await Task.Run(() => _list);
|
||||
|
||||
return new ResultModel<List<AdminUserDto>>()
|
||||
{
|
||||
Data = resultList,
|
||||
StateCode = 1
|
||||
};
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
*/
|
||||
for (int i =0; i < 10; i++)
|
||||
{
|
||||
AdminUserDto dto = new AdminUserDto();
|
||||
dto.Id = i;
|
||||
dto.Name = $"Name {i}";
|
||||
dto.RoleType = AdminRole.Admin;
|
||||
dto.StafflinkNo = $"{i+40000}";
|
||||
dto.Active = true;
|
||||
dto.AddedOn = DateTime.Today.AddDays(i);
|
||||
dto.AddedBy = "ddfed";
|
||||
_resultList.Add(dto);
|
||||
}
|
||||
return new ResultModel<List<AdminUserDto>>()
|
||||
{
|
||||
Data = _resultList,
|
||||
StatusCode = 1
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id)
|
||||
{
|
||||
AdminUserDto result = null;
|
||||
/*
|
||||
try
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
AdminUser model = await _context.AdminUsers.FindAsync(id);
|
||||
result = FillAdminUserDto(model);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
*/
|
||||
int idx = _resultList.FindIndex(x => x.Id == id);
|
||||
if (idx > -1)
|
||||
{
|
||||
result = _resultList[idx];
|
||||
}
|
||||
|
||||
return new ResultModel<AdminUserDto>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = 1
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<int>> SaveAdminUserAsync(AdminUserDto item)
|
||||
{
|
||||
int result = default(int);
|
||||
try
|
||||
{
|
||||
AdminUser model;
|
||||
if (item.Id > 0)
|
||||
{
|
||||
model = await _context.AdminUsers.FindAsync(item.Id);
|
||||
model = FillAdminUser(item, model);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new AdminUser();
|
||||
model = FillAdminUser(item, model);
|
||||
_context.AdminUsers.Add(model);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
result = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = -1;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = 1
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public async Task<ResultModel<bool>> DeleteAdminUserAsync(int id)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
try
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
AdminUser model = await _context.AdminUsers.FindAsync(id);
|
||||
model.Active = false;
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = false;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = 1
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
//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 readonly AppSettings _appSettings;
|
||||
|
||||
|
||||
public AdminUserRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
private AdminUserDto FillAdminUserDto(AdminUser model)
|
||||
{
|
||||
AdminUserDto dto = new AdminUserDto();
|
||||
dto.Id = model.UserID;
|
||||
dto.Name = model.Name;
|
||||
dto.RoleType = model.RoleType;
|
||||
dto.StafflinkNo = model.StafflinkNo;
|
||||
dto.Active = model.Active;
|
||||
dto.AddedBy = model.AddedBy;
|
||||
dto.AddedOn = model.AddedOn;
|
||||
return dto;
|
||||
}
|
||||
|
||||
private AdminUser FillAdminUser(AdminUserDto dto, AdminUser model)
|
||||
{
|
||||
|
||||
model.UserID = dto.Id;
|
||||
model.Name = dto.Name;
|
||||
model.RoleType = dto.RoleType;
|
||||
model.StafflinkNo = dto.StafflinkNo;
|
||||
model.Active = dto.Active;
|
||||
model.AddedBy = dto.AddedBy;
|
||||
model.AddedOn = dto.AddedOn;
|
||||
return model;
|
||||
}
|
||||
|
||||
public async Task<ResultModel<List<AdminUserDto>>> LoadAdminUserAsync(bool onlyActive)
|
||||
{
|
||||
List<AdminUserDto> resultList = new List<AdminUserDto>();
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
//var list = await _context.AdminUsers.Where(x => x.Active == onlyActive).ToListAsync();
|
||||
var list = await _context.AdminUsers.AsQueryable().ToListAsync();
|
||||
|
||||
AdminUserDto dto;
|
||||
AdminUser user;
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
user = list[i];
|
||||
dto = FillAdminUserDto(user);
|
||||
resultList.Add(dto);
|
||||
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = 0;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return new ResultModel<List<AdminUserDto>>()
|
||||
{
|
||||
Data = resultList,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id)
|
||||
{
|
||||
AdminUserDto result = null;
|
||||
int statuscode = 0;
|
||||
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 = 0;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
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);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new AdminUser();
|
||||
model = FillAdminUser(item, model);
|
||||
_context.AdminUsers.Add(model);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
result = 1;
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = -1;
|
||||
error = ex.ToString();
|
||||
statuscode = 0;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
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;
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = 0;
|
||||
result = false;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
//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 readonly AppSettings _appSettings;
|
||||
|
||||
public ConcessionTypeRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
private ConcessionTypeDto FillConcessionTypeDto(ConcessionType model)
|
||||
{
|
||||
ConcessionTypeDto dto = new ConcessionTypeDto();
|
||||
dto.Active = model.Active;
|
||||
dto.Description = model.ConcessionDesc;
|
||||
dto.Display = model.ConcessionDisplay;
|
||||
dto.Id = model.ConcessionTypeID;
|
||||
return dto;
|
||||
}
|
||||
private ConcessionType FillConcessionType(ConcessionTypeDto dto, ConcessionType model)
|
||||
{
|
||||
model.Active = dto.Active;
|
||||
model.ConcessionDesc = dto.Description;
|
||||
model.ConcessionDisplay = dto.Display;
|
||||
model.ConcessionTypeID = dto.Id;
|
||||
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.ConcessionTypeID,
|
||||
Description = x.ConcessionDesc,
|
||||
Display = x.ConcessionDisplay,
|
||||
Active = x.Active
|
||||
}).ToListAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = null;
|
||||
error = ex.ToString();
|
||||
statuscode = 0;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return new ResultModel<List<ConcessionTypeDto>>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
public async Task<ResultModel<ConcessionTypeDto>> LoadConcessionTypeByIdAsync(int id)
|
||||
{
|
||||
ConcessionType result = null;
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
ConcessionTypeDto dto;
|
||||
try
|
||||
{
|
||||
result = await _context.ConcessionTypes.FindAsync(id);
|
||||
dto = FillConcessionTypeDto(result);
|
||||
//result = _list.Find(x => x.Id == id);
|
||||
//var dto = await Task.Run(() => result);
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = 0;
|
||||
throw ex;
|
||||
}
|
||||
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);
|
||||
await _context.SaveChangesAsync();
|
||||
result = item.Id;
|
||||
}
|
||||
else //new record
|
||||
{
|
||||
model = new ConcessionType();
|
||||
model = FillConcessionType(item, model);
|
||||
_context.ConcessionTypes.Add(model);
|
||||
var id = await _context.SaveChangesAsync();
|
||||
result = id;
|
||||
item.Id = id;
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = 0;
|
||||
throw ex;
|
||||
}
|
||||
//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 = 0;
|
||||
throw;
|
||||
}
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
//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 readonly AppSettings _appSettings;
|
||||
|
||||
public ConcessionValidationRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
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.ValidationID;
|
||||
dto.StafflinkNo = model.StafflinkNo;
|
||||
dto.ValidateDate = model.ValidateDate;
|
||||
dto.ValidationPointId = model.ValidationPointID;
|
||||
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.ValidationID;
|
||||
dto.StafflinkNo = model.StafflinkNo;
|
||||
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;
|
||||
model.ConcessionExpiry = dto.ConcessionExpiry;
|
||||
model.ConcessionHolder = dto.ConcessionHolder;
|
||||
model.ConcessionTypeID = dto.ConcessionTypeId;
|
||||
model.ValidationID = dto.Id;
|
||||
model.StafflinkNo = dto.StafflinkNo;
|
||||
model.ValidateDate = dto.ValidateDate;
|
||||
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 = 0;
|
||||
error = ex.ToString();
|
||||
throw;
|
||||
}
|
||||
|
||||
return new ResultModel<List<ConcessionValidationExtDto>>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ResultModel<List<ConcessionValidationExtDto>>> LoadConcessionValidationStaffLinkNoAsync(string staffLinkNo, DateTime currentDate)
|
||||
{
|
||||
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, currentDate, currentDate);
|
||||
/*
|
||||
//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;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
statuscode = 0;
|
||||
error = ex.ToString();
|
||||
throw;
|
||||
}
|
||||
|
||||
return new ResultModel<List<ConcessionValidationExtDto>>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
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 = 0;
|
||||
error = ex.ToString();
|
||||
throw;
|
||||
}
|
||||
|
||||
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 = "";
|
||||
try
|
||||
{
|
||||
ConcessionValidation model;
|
||||
if (item.Id > 0)
|
||||
{
|
||||
model = await _context.ConcessionValidations.FindAsync(item.Id);
|
||||
model = FillConcessionValidation(item, model);
|
||||
result = await _context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new ConcessionValidation();
|
||||
model = FillConcessionValidation(item, model);
|
||||
_context.ConcessionValidations.Add(model);
|
||||
result = await _context.SaveChangesAsync();
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
statuscode = 0;
|
||||
error = ex.ToString();
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = false;
|
||||
statuscode = 0;
|
||||
error = ex.ToString();
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
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";
|
||||
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,92 @@
|
||||
//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.ConcessionTypeID,
|
||||
Description = x.ConcessionDesc,
|
||||
|
||||
}).ToListAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
statuscode = 0;
|
||||
error = ex.ToString();
|
||||
throw;
|
||||
}
|
||||
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.ValidationPointID,
|
||||
Description = x.Description
|
||||
}).ToListAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
statuscode = 0;
|
||||
error = ex.ToString();
|
||||
throw;
|
||||
}
|
||||
return new ResultModel<List<LookupCodeDto>>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
//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 UserFakeRepository : IUserService
|
||||
{
|
||||
private DataContext _context;
|
||||
private IJwtUtils _jwtUtils;
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public UserFakeRepository(
|
||||
DataContext context,
|
||||
IJwtUtils jwtUtils,
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_jwtUtils = jwtUtils;
|
||||
_appSettings = appSettings.Value;
|
||||
|
||||
}
|
||||
public AuthenticateResponse Authenticate(AuthenticateRequest model)
|
||||
{
|
||||
var user = _context.Users.SingleOrDefault(x => x.Username == model.Username);
|
||||
|
||||
// validate
|
||||
// if (user == null || !BCryptNet.Verify(model.Password, user.PasswordHash))
|
||||
if (user == null || (model.Password != user.PasswordHash))
|
||||
throw new System.Exception("Username or password is incorrect");
|
||||
|
||||
// authentication successful so generate jwt token
|
||||
var jwtToken = _jwtUtils.GenerateJwtToken(user);
|
||||
|
||||
return new AuthenticateResponse(user, 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 = AdminRole.Admin;
|
||||
user.Username = model.Username;
|
||||
}
|
||||
else
|
||||
{
|
||||
user.Username = model.Username;
|
||||
user.FirstName = model.Username;
|
||||
user.LastName = " LS Normal";
|
||||
user.Role = AdminRole.Normal;
|
||||
}
|
||||
|
||||
// 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.UserID;
|
||||
}
|
||||
else
|
||||
myUser.Role = 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<List<User>>> GetAllUsers()
|
||||
{
|
||||
var retval = await _context.Users.ToListAsync();
|
||||
return new ResultModel<List<User>>()
|
||||
{
|
||||
Data = retval,
|
||||
StatusCode = 1
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public async Task<ResultModel<User>> GetById(int id)
|
||||
{
|
||||
var user = await _context.Users.FindAsync(id);
|
||||
if (user == null) throw new KeyNotFoundException("User not found");
|
||||
return new ResultModel<User>()
|
||||
{
|
||||
Data = user,
|
||||
StatusCode = 1
|
||||
};
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
ADStaffLink staffLink = new ADStaffLink(adConfig);
|
||||
MyADObject myADObj = staffLink.SearchStaff(username);
|
||||
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)
|
||||
{
|
||||
|
||||
ADStaffLink staffLink = new ADStaffLink(adConfig);
|
||||
MyADObject myADObj = staffLink.CheckADCredentials(username,password);
|
||||
User user = new()
|
||||
{
|
||||
Username = myADObj.StafflinkNo,
|
||||
Email = myADObj.Email,
|
||||
FirstName = myADObj.FirstName,
|
||||
LastName = myADObj.LastName
|
||||
};
|
||||
// myADObj.JobTitle;
|
||||
return user;
|
||||
|
||||
// return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
//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 UserRepository : IUserService
|
||||
{
|
||||
private DataContext _context;
|
||||
private IJwtUtils _jwtUtils;
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public UserRepository(
|
||||
DataContext context,
|
||||
IJwtUtils jwtUtils,
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_jwtUtils = jwtUtils;
|
||||
_appSettings = appSettings.Value;
|
||||
|
||||
}
|
||||
|
||||
public AuthenticateResponse Authenticate(AuthenticateRequest model)
|
||||
{
|
||||
var user = _context.Users.SingleOrDefault(x => x.Username == model.Username);
|
||||
|
||||
// validate
|
||||
// if (user == null || !BCryptNet.Verify(model.Password, user.PasswordHash))
|
||||
if (user == null || (model.Password != user.PasswordHash))
|
||||
throw new System.Exception("Username or password is incorrect");
|
||||
|
||||
// authentication successful so generate jwt token
|
||||
var jwtToken = _jwtUtils.GenerateJwtToken(user);
|
||||
|
||||
return new AuthenticateResponse(user, jwtToken);
|
||||
}
|
||||
|
||||
public async Task<ResultModel<AuthenticateResponse>> LoginApiAD(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.UserID;
|
||||
}
|
||||
else
|
||||
myUser.Role = 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<List<User>>> GetAllUsers()
|
||||
{
|
||||
var retval = await _context.Users.ToListAsync();
|
||||
return new ResultModel<List<User>>()
|
||||
{
|
||||
Data = retval,
|
||||
StatusCode = 1
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public async Task<ResultModel<User>> GetById(int id)
|
||||
{
|
||||
var user = await _context.Users.FindAsync(id);
|
||||
if (user == null) throw new KeyNotFoundException("User not found");
|
||||
return new ResultModel<User>()
|
||||
{
|
||||
Data = user,
|
||||
StatusCode = 1
|
||||
};
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
ADStaffLink staffLink = new ADStaffLink(adConfig);
|
||||
MyADObject myADObj = staffLink.SearchStaff(username);
|
||||
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)
|
||||
{
|
||||
|
||||
ADStaffLink staffLink = new ADStaffLink(adConfig);
|
||||
MyADObject myADObj = staffLink.CheckADCredentials(username,password);
|
||||
User user = new()
|
||||
{
|
||||
Username = myADObj.StafflinkNo,
|
||||
Email = myADObj.Email,
|
||||
FirstName = myADObj.FirstName,
|
||||
LastName = myADObj.LastName
|
||||
};
|
||||
// myADObj.JobTitle;
|
||||
return user;
|
||||
|
||||
// return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
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 ValidationPointFakeRepository : IValidationPoint
|
||||
{
|
||||
private DataContext _context;
|
||||
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
private List<ValidationPointDto> _list = new List<ValidationPointDto>();
|
||||
|
||||
public ValidationPointFakeRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
private ValidationPointDto FillValidationDto(ValidationPoint item)
|
||||
{
|
||||
ValidationPointDto dto = new ValidationPointDto();
|
||||
dto.Active = item.Active;
|
||||
dto.Description = item.Description;
|
||||
dto.Display = item.DisplayName;
|
||||
dto.Id = item.ValidationPointID;
|
||||
return dto;
|
||||
}
|
||||
|
||||
private ValidationPoint FillValidationModel(ValidationPointDto item, ValidationPoint model) {
|
||||
|
||||
model.Active = item.Active;
|
||||
model.Description = item.Description;
|
||||
model.DisplayName = item.Display;
|
||||
model.ValidationPointID = item.Id;
|
||||
return model;
|
||||
}
|
||||
|
||||
public async Task<ResultModel<List<ValidationPointDto>>> LoadValidationPointAsync(bool onlyActive)
|
||||
{
|
||||
try
|
||||
{
|
||||
/*
|
||||
var it = await _context.Validations.AsQueryable().ToListAsync();
|
||||
*/
|
||||
|
||||
ValidationPointDto dto;
|
||||
ValidationPoint val;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
val = new ValidationPoint()
|
||||
{
|
||||
ValidationPointID = i,
|
||||
Description = $"Validation {i}",
|
||||
DisplayName = $"Display {i}",
|
||||
Active = true,
|
||||
|
||||
|
||||
};
|
||||
|
||||
dto = FillValidationDto(val);
|
||||
_list.Add(dto);
|
||||
}
|
||||
//var it = await Task.Run(() => _list);
|
||||
|
||||
return new ResultModel<List<ValidationPointDto>>()
|
||||
{
|
||||
Data = _list,
|
||||
StatusCode = 1
|
||||
};
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
|
||||
}
|
||||
public async Task<ResultModel<ValidationPointDto>> LoadValidationPointByIdAsync(int id)
|
||||
{
|
||||
ValidationPoint result = null;
|
||||
try
|
||||
{
|
||||
ValidationPointDto dto;
|
||||
result = await _context.Validations.FindAsync(id);
|
||||
dto = FillValidationDto(result);
|
||||
//result = _list.Find(x => x.Id == id);
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<ValidationPointDto>()
|
||||
{
|
||||
Data = dto,
|
||||
StatusCode = 1
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
public async Task<ResultModel<int>> SaveValidationPointAsync(ValidationPointDto item)
|
||||
{
|
||||
int result = default(int);
|
||||
try
|
||||
{
|
||||
ValidationPoint model;
|
||||
if (item.Id > 0)
|
||||
{
|
||||
model = await _context.Validations.FindAsync(item.Id);
|
||||
model = FillValidationModel(item, model);
|
||||
await _context.SaveChangesAsync();
|
||||
result = item.Id;
|
||||
}
|
||||
else //new record
|
||||
{
|
||||
model = new ValidationPoint();
|
||||
model = FillValidationModel(item, model);
|
||||
_context.Validations.Add(model);
|
||||
var id = await _context.SaveChangesAsync();
|
||||
result = id;
|
||||
item.Id = id;
|
||||
}
|
||||
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = 1
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
/*
|
||||
ConcessionTypeDA dataAccess = new ConcessionTypeDA();
|
||||
try
|
||||
{
|
||||
result = await dataAccess.InsertConcessionTypeAsync(item);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async Task<ResultModel<bool>> DeleteValidationPointAsync(int id)
|
||||
{
|
||||
bool result = true;
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
ValidationPoint model;
|
||||
if (id > 0)
|
||||
{
|
||||
model = await _context.Validations.FindAsync(id);
|
||||
model.Active = false;
|
||||
//_context.Validations.Remove(model);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = 1
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
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 List<ValidationPointDto> _list = new List<ValidationPointDto>();
|
||||
|
||||
public ValidationPointRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
private ValidationPointDto FillValidationDto(ValidationPoint item)
|
||||
{
|
||||
ValidationPointDto dto = new ValidationPointDto();
|
||||
dto.Active = item.Active;
|
||||
dto.Description = item.Description;
|
||||
dto.Display = item.DisplayName;
|
||||
dto.Id = item.ValidationPointID;
|
||||
return dto;
|
||||
}
|
||||
|
||||
private ValidationPoint FillValidationModel(ValidationPointDto item, ValidationPoint model) {
|
||||
|
||||
model.Active = item.Active;
|
||||
model.Description = item.Description;
|
||||
model.DisplayName = item.Display;
|
||||
model.ValidationPointID = item.Id;
|
||||
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);
|
||||
}
|
||||
|
||||
statuscode = 1;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = 0;
|
||||
throw ex;
|
||||
}
|
||||
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 = 0;
|
||||
}
|
||||
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);
|
||||
await _context.SaveChangesAsync();
|
||||
result = item.Id;
|
||||
}
|
||||
else //new record
|
||||
{
|
||||
model = new ValidationPoint();
|
||||
model = FillValidationModel(item, model);
|
||||
_context.Validations.Add(model);
|
||||
var id = await _context.SaveChangesAsync();
|
||||
result = id;
|
||||
item.Id = id;
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = 0;
|
||||
}
|
||||
//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 = 0;
|
||||
throw;
|
||||
}
|
||||
//var dto = await Task.Run(() => result);
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
using CarParkValidationAPI.Authorization;
|
||||
using CarParkValidationAPI.Datas;
|
||||
using CarParkValidationAPI.Entities;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using CarParkValidationAPI.Models;
|
||||
using CarParkValidationAPI.Repository;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarParkValidationAPI
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllers();
|
||||
//** security
|
||||
var appSettingsSection = Configuration.GetSection("AppSettings");
|
||||
services.Configure<AppSettings>(appSettingsSection);
|
||||
|
||||
var appSettings = appSettingsSection.Get<AppSettings>();
|
||||
var key = Encoding.ASCII.GetBytes(appSettings.Secret);
|
||||
//***
|
||||
services.AddDbContext<DataContext>();
|
||||
services.AddCors();
|
||||
//***
|
||||
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
|
||||
};
|
||||
});
|
||||
|
||||
//**
|
||||
//publish need to take comment out
|
||||
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
// c.ResolveConflictingActions(api => api.First());
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "CarParkValidationAPI", Version = "v1" });
|
||||
});
|
||||
/*
|
||||
services.AddSwaggerGen(option =>
|
||||
{
|
||||
option.UseAllOfForInheritance();
|
||||
option.UseAllOfToExtendReferenceSchemas();
|
||||
option.IgnoreObsoleteActions();
|
||||
option.IgnoreObsoleteProperties();
|
||||
option.ResolveConflictingActions(api => api.First());
|
||||
});
|
||||
*/
|
||||
services.AddScoped<IJwtUtils, JwtUtils>();
|
||||
services.AddScoped<IUserService, UserFakeRepository>();
|
||||
services.AddScoped<IConcessionType, ConcessionTypeRepository>();
|
||||
services.AddScoped<IValidationPoint, ValidationPointRepository>();
|
||||
services.AddScoped<IAdminUser, AdminUserRepository>();
|
||||
services.AddScoped<IConcessionValidation, ConcessionValidationRepository>();
|
||||
services.AddScoped<ILookupCode, LookupCodeRepository>();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataContext context)
|
||||
{
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
||||
}
|
||||
|
||||
app.UseSwagger();
|
||||
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "CarParkValidationAPI v1");
|
||||
});
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
// global cors policy
|
||||
app.UseCors(x => x
|
||||
.SetIsOriginAllowed(origin => true)
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.AllowCredentials());
|
||||
|
||||
// global error handler
|
||||
//app.UseMiddleware<ErrorHandlerMiddleware>();
|
||||
|
||||
// custom jwt auth middleware
|
||||
app.UseMiddleware<JwtMiddleware>();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"AppSettings": {
|
||||
"Secret": "Nepean Blue Mountain Super Secret SIGN AND VERIFY JWT TOKENS, BEARER TOKEN USE WHEN CALLING THIS API.",
|
||||
"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;",
|
||||
"LDAPPath": "LDAP://ldap.nswhealth.net:389/OU=Accounts,DC=nswhealth,DC=net",
|
||||
"LDAPUser": "SRV-NBMS-BIDSPMS",
|
||||
"LDAPPassword": "42Ytp2AE3nN16eBoyia86UZH6",
|
||||
"ADTimeOut": "30",
|
||||
"LoginWebAPI": "http://NEPHMDB-SQL007/CommonWebApiAD/api/AD"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
/*Positive~1
|
||||
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": "Server=tcp:10.60.207.82,1433;Initial Catalog=CarParkValidation;Persist Security Info=False;User ID=bids_admin;Password=Password4BI;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;",
|
||||
"LDAPPath": "LDAP://ldap.nswhealth.net:389/OU=Accounts,DC=nswhealth,DC=net",
|
||||
"LDAPUser": "SRV-NBMS-BIDSPMS",
|
||||
"LDAPPassword": "42Ytp2AE3nN16eBoyia86UZH6",
|
||||
"ADTimeOut": "30",
|
||||
"LoginWebAPI": "http://NEPHMDB-SQL007/CommonWebApiAD/api/AD"
|
||||
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"OLDLoginWebAPI": "http://virtapp-mdb048/CommonAPI/api/AD/",
|
||||
"LADP": "http://NEPHMDB-SQL007/CommonWebApiAD/api/AD/",
|
||||
"AllowedHosts": "*",
|
||||
"SQLConnectionStringold": "Server=tcp:10.60.207.82,1433;Initial Catalog=CarParkValidation;Persist Security Info=False;User ID=bids_admin;Password=Password4BI;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;"
|
||||
}
|
||||
@@ -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