commit change all folder

This commit is contained in:
Kham
2021-11-24 09:28:37 +11:00
parent 1131159112
commit 4e3cc0750c
58 changed files with 151 additions and 92 deletions
@@ -5,13 +5,14 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.9" /> <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.9" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.9" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.9" /> <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.12" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.12.0" /> <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.12.0" />
<PackageReference Include="SpreadsheetLight" Version="3.5.0" /> <PackageReference Include="SpreadsheetLight" Version="3.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.5" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.0" />
</ItemGroup> </ItemGroup>
-31
View File
@@ -1,31 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31515.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarParkValidationAPI", "CarParkValidationAPI\CarParkValidationAPI.csproj", "{FCD8F53F-967F-4E66-B42C-DCD0C83B2670}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonAD", "..\..\CommonAD\CommonAD.csproj", "{8FB49AA9-08D8-400E-BA06-250C479A2296}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FCD8F53F-967F-4E66-B42C-DCD0C83B2670}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FCD8F53F-967F-4E66-B42C-DCD0C83B2670}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCD8F53F-967F-4E66-B42C-DCD0C83B2670}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCD8F53F-967F-4E66-B42C-DCD0C83B2670}.Release|Any CPU.Build.0 = Release|Any CPU
{8FB49AA9-08D8-400E-BA06-250C479A2296}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FB49AA9-08D8-400E-BA06-250C479A2296}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FB49AA9-08D8-400E-BA06-250C479A2296}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FB49AA9-08D8-400E-BA06-250C479A2296}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B6C27BFF-4D28-4CB3-954C-F3B6C100B5EC}
EndGlobalSection
EndGlobal
+27
View File
@@ -0,0 +1,27 @@
using AutoMapper;
using CarParkValidationAPI.Entities;
using CarParkValidationAPI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CarParkValidationAPI.Datas
{
public class AutoMapping: Profile
{
public AutoMapping()
{
CreateMap<ConcessionType, ConcessionTypeDto>()
.ForMember( dest => dest.Id, opt => opt.MapFrom(src => src.ConcessionTypeID))
.ForMember(dest => dest.Description , opt=> opt.MapFrom(src=> src.ConcessionDesc))
.ForMember(dest => dest.Display, opt => opt.MapFrom(src => src.ConcessionDisplay))
.ReverseMap();
CreateMap<ValidationPoint, ValidationPointDto>()
.ForMember(dest => dest.Id , opt => opt.MapFrom(src => src.ValidationPointID))
.ForMember(dest => dest.Display, opt => opt.MapFrom(src => src.DisplayName))
.ReverseMap();
/*etc...*/
}
}
}
@@ -11,6 +11,7 @@ namespace CarParkValidationAPI.Interface
public interface IAdminUser public interface IAdminUser
{ {
Task<ResultModel<List<AdminUserViewDto>>> LoadAdminUserAsync(bool OnlyActive); Task<ResultModel<List<AdminUserViewDto>>> LoadAdminUserAsync(bool OnlyActive);
Task<ResultModel<bool>> CheckAdminUserByStaffLinkNoAsync(string staffLinkNo);
Task<ResultModel<int>> SaveAdminUserAsync(AdminUserDto item); Task<ResultModel<int>> SaveAdminUserAsync(AdminUserDto item);
Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id); Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id);
Task<ResultModel<bool>> DeleteAdminUserAsync(int id); Task<ResultModel<bool>> DeleteAdminUserAsync(int id);
@@ -60,7 +60,15 @@ namespace CarParkValidationAPI.Repository
model.AddedOn = dto.AddedOn; model.AddedOn = dto.AddedOn;
return model; return model;
} }
public async Task<ResultModel<bool>> CheckAdminUserByStaffLinkNoAsync(string staffLinkNo)
{
var list = await _context.AdminUsers.Where(x => x.StafflinkNo == staffLinkNo).ToListAsync();
return new ResultModel<bool>()
{
Data = false,
StatusCode = 1
};
}
public async Task<ResultModel<List<AdminUserViewDto>>> LoadAdminUserAsync(bool onlyActive) public async Task<ResultModel<List<AdminUserViewDto>>> LoadAdminUserAsync(bool onlyActive)
{ {
/* /*
@@ -89,7 +97,8 @@ namespace CarParkValidationAPI.Repository
throw ex; throw ex;
} }
*/ */
for (int i =0; i < 10; i++) var list = await _context.AdminUsers.Where(x => x.Active == onlyActive).ToListAsync();
for (int i =0; i < list.Count; i++)
{ {
AdminUserViewDto dto = new AdminUserViewDto(); AdminUserViewDto dto = new AdminUserViewDto();
dto.Id = i; dto.Id = i;
@@ -110,7 +119,7 @@ namespace CarParkValidationAPI.Repository
public async Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id) public async Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id)
{ {
AdminUserDto result = null; AdminUserDto result = null;
/*
try try
{ {
if (id > 0) if (id > 0)
@@ -124,8 +133,6 @@ namespace CarParkValidationAPI.Repository
{ {
throw ex; throw ex;
} }
*/
return new ResultModel<AdminUserDto>() return new ResultModel<AdminUserDto>()
{ {
@@ -119,6 +119,37 @@ namespace CarParkValidationAPI.Repository
Message = error Message = error
}; };
} }
public async Task<ResultModel<bool>> CheckAdminUserByStaffLinkNoAsync(string staffLinkNo)
{
bool result = false;
int statuscode = 0;
string error = "";
try
{
if (!string.IsNullOrEmpty(staffLinkNo))
{
var list = await _context.AdminUsers.Where( x=> x.StafflinkNo == staffLinkNo).ToListAsync();
if (list.Count > 0)
{
result = true;
statuscode = 1;
}
}
}
catch (Exception ex)
{
error = ex.ToString();
statuscode = 0;
throw ex;
}
return new ResultModel<bool>()
{
Data = result,
StatusCode = statuscode,
Message = error
};
}
public async Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id) public async Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id)
{ {
AdminUserDto result = null; AdminUserDto result = null;
@@ -162,18 +193,33 @@ namespace CarParkValidationAPI.Repository
model.LastModified = DateTime.Now; model.LastModified = DateTime.Now;
model.LastModifiedId = _currentUser; model.LastModifiedId = _currentUser;
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
result = model.UserID;
statuscode = 1;
} }
else else
{
ResultModel<bool> found = await CheckAdminUserByStaffLinkNoAsync(item.StafflinkNo);
if (!found.Data)
{ {
model = new AdminUser(); model = new AdminUser();
model = FillAdminUser(item, model); model = FillAdminUser(item, model);
_context.AdminUsers.Add(model); _context.AdminUsers.Add(model);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
}
result = model.UserID; result = model.UserID;
statuscode = 1; statuscode = 1;
} }
else
{
error = "staff link No '" + item.StafflinkNo + "' already in admin user";
statuscode = 0;
result = 0;
}
}
}
catch (Exception ex) catch (Exception ex)
{ {
result = -1; result = -1;
@@ -12,6 +12,7 @@ using CarParkValidationAPI.Datas;
using CarParkValidationAPI.Interface; using CarParkValidationAPI.Interface;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using AutoMapper;
namespace CarParkValidationAPI.Repository namespace CarParkValidationAPI.Repository
{ {
@@ -20,12 +21,13 @@ namespace CarParkValidationAPI.Repository
private DataContext _context; private DataContext _context;
private string _currentUser = ""; private string _currentUser = "";
private readonly AppSettings _appSettings; private readonly AppSettings _appSettings;
private readonly IMapper _mapper;
public ConcessionTypeRepository( public ConcessionTypeRepository(
DataContext context, DataContext context,
IMapper mapper,
IOptions<AppSettings> appSettings) IOptions<AppSettings> appSettings)
{ {
_mapper = mapper;
_context = context; _context = context;
_appSettings = appSettings.Value; _appSettings = appSettings.Value;
} }
@@ -57,6 +59,7 @@ namespace CarParkValidationAPI.Repository
string error = ""; string error = "";
try try
{ {
/*
result = await _context.ConcessionTypes.Select( result = await _context.ConcessionTypes.Select(
x => new ConcessionTypeDto() x => new ConcessionTypeDto()
{ {
@@ -65,6 +68,9 @@ namespace CarParkValidationAPI.Repository
Display = x.ConcessionDisplay, Display = x.ConcessionDisplay,
Active = x.Active Active = x.Active
}).ToListAsync(); }).ToListAsync();
*/
var olist = await _context.ConcessionTypes.ToListAsync();
result = _mapper.Map<List<ConcessionTypeDto>>(olist);
statuscode = 1; statuscode = 1;
result.Sort((x, y) => x.Description.CompareTo(y.Description)); result.Sort((x, y) => x.Description.CompareTo(y.Description));
} }
@@ -92,7 +98,8 @@ namespace CarParkValidationAPI.Repository
try try
{ {
result = await _context.ConcessionTypes.FindAsync(id); result = await _context.ConcessionTypes.FindAsync(id);
dto = FillConcessionTypeDto(result); dto = _mapper.Map<ConcessionTypeDto>(result);
//dto = FillConcessionTypeDto(result);
//result = _list.Find(x => x.Id == id); //result = _list.Find(x => x.Id == id);
//var dto = await Task.Run(() => result); //var dto = await Task.Run(() => result);
statuscode = 1; statuscode = 1;
@@ -89,10 +89,10 @@ namespace CarParkValidationAPI.Repository
if (loginInfo != null && loginInfo.result) if (loginInfo != null && loginInfo.result)
{ {
myUser = new User(); myUser = new User();
myUser.Email = loginInfo.Email; myUser.Email = loginInfo.email;
myUser.FirstName = loginInfo.FirstName; myUser.FirstName = loginInfo.firstName;
myUser.LastName = loginInfo.LastName; myUser.LastName = loginInfo.lastName;
myUser.Username = loginInfo.StafflinkNo; myUser.Username = loginInfo.stafflinkNo;
//now check the adminuser table //now check the adminuser table
var user = _context.AdminUsers.SingleOrDefault(x => x.StafflinkNo == model.Username); var user = _context.AdminUsers.SingleOrDefault(x => x.StafflinkNo == model.Username);
if (user != null) if (user != null)
@@ -178,10 +178,10 @@ namespace CarParkValidationAPI.Repository
if (loginInfo != null && loginInfo.result) if (loginInfo != null && loginInfo.result)
{ {
myUser = new User(); myUser = new User();
myUser.Email = loginInfo.Email; myUser.Email = loginInfo.email;
myUser.FirstName = loginInfo.FirstName; myUser.FirstName = loginInfo.firstName;
myUser.LastName = loginInfo.LastName; myUser.LastName = loginInfo.lastName;
myUser.Username = loginInfo.StafflinkNo; myUser.Username = loginInfo.stafflinkNo;
statuscode = 1; statuscode = 1;
} }
@@ -222,10 +222,10 @@ namespace CarParkValidationAPI.Repository
MyADObject myADObj = staffLink.SearchStaff(username); MyADObject myADObj = staffLink.SearchStaff(username);
User user = new() User user = new()
{ {
Username = myADObj.StafflinkNo, Username = myADObj.stafflinkNo,
Email = myADObj.Email, Email = myADObj.email,
FirstName = myADObj.FirstName, FirstName = myADObj.firstName,
LastName = myADObj.LastName LastName = myADObj.lastName
}; };
// myADObj.JobTitle; // myADObj.JobTitle;
return user; return user;
@@ -239,10 +239,10 @@ namespace CarParkValidationAPI.Repository
MyADObject myADObj = staffLink.CheckADCredentials(username,password); MyADObject myADObj = staffLink.CheckADCredentials(username,password);
User user = new() User user = new()
{ {
Username = myADObj.StafflinkNo, Username = myADObj.stafflinkNo,
Email = myADObj.Email, Email = myADObj.email,
FirstName = myADObj.FirstName, FirstName = myADObj.firstName,
LastName = myADObj.LastName LastName = myADObj.lastName
}; };
// myADObj.JobTitle; // myADObj.JobTitle;
return user; return user;
@@ -55,14 +55,14 @@ namespace CarParkValidationAPI.Repository
int statuscode = 0; int statuscode = 0;
string webAPIUrl = _appSettings.LoginWebAPI; string webAPIUrl = _appSettings.LoginWebAPI;
var loginInfo = await CommonAD.WebAPIUtil.GetLoginADAsync(webAPIUrl, "CheckADCredentials", model.Username, model.Password); var loginInfo = await CommonAD.WebAPIUtil.PostLoginADAsync(webAPIUrl, "CheckCredentials", model.Username, model.Password);
if (loginInfo != null && loginInfo.result) if (loginInfo != null && loginInfo.result)
{ {
myUser = new User(); myUser = new User();
myUser.Email = loginInfo.Email; myUser.Email = loginInfo.email;
myUser.FirstName = loginInfo.FirstName; myUser.FirstName = loginInfo.firstName;
myUser.LastName = loginInfo.LastName; myUser.LastName = loginInfo.lastName;
myUser.Username = loginInfo.StafflinkNo; myUser.Username = loginInfo.stafflinkNo;
//now check the adminuser table //now check the adminuser table
var user = _context.AdminUsers. var user = _context.AdminUsers.
SingleOrDefault(x => x.StafflinkNo == model.Username SingleOrDefault(x => x.StafflinkNo == model.Username
@@ -154,10 +154,10 @@ namespace CarParkValidationAPI.Repository
if (loginInfo != null && loginInfo.result) if (loginInfo != null && loginInfo.result)
{ {
myUser = new User(); myUser = new User();
myUser.Email = loginInfo.Email; myUser.Email = loginInfo.email;
myUser.FirstName = loginInfo.FirstName; myUser.FirstName = loginInfo.firstName;
myUser.LastName = loginInfo.LastName; myUser.LastName = loginInfo.lastName;
myUser.Username = loginInfo.StafflinkNo; myUser.Username = loginInfo.stafflinkNo;
statuscode = 1; statuscode = 1;
} }
@@ -198,10 +198,10 @@ namespace CarParkValidationAPI.Repository
MyADObject myADObj = staffLink.SearchStaff(username); MyADObject myADObj = staffLink.SearchStaff(username);
User user = new() User user = new()
{ {
Username = myADObj.StafflinkNo, Username = myADObj.stafflinkNo,
Email = myADObj.Email, Email = myADObj.email,
FirstName = myADObj.FirstName, FirstName = myADObj.firstName,
LastName = myADObj.LastName LastName = myADObj.lastName
}; };
// myADObj.JobTitle; // myADObj.JobTitle;
return user; return user;
@@ -215,10 +215,10 @@ namespace CarParkValidationAPI.Repository
MyADObject myADObj = staffLink.CheckADCredentials(username,password); MyADObject myADObj = staffLink.CheckADCredentials(username,password);
User user = new() User user = new()
{ {
Username = myADObj.StafflinkNo, Username = myADObj.stafflinkNo,
Email = myADObj.Email, Email = myADObj.email,
FirstName = myADObj.FirstName, FirstName = myADObj.firstName,
LastName = myADObj.LastName LastName = myADObj.lastName
}; };
// myADObj.JobTitle; // myADObj.JobTitle;
return user; return user;
@@ -66,6 +66,7 @@ namespace CarParkValidationAPI
}; };
}); });
services.AddAutoMapper(typeof(Startup));
//** //**
//publish need to take comment out //publish need to take comment out
@@ -2,9 +2,9 @@
"AppSettings": { "AppSettings": {
"Secret": "Nepean Blue Mountain Super Secret SIGN AND VERIFY JWT TOKENS, BEARER TOKEN USE WHEN CALLING THIS API.", "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;", "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", "LDAPPath": "",
"LDAPUser": "SRV-NBMS-BIDSPMS", "LDAPUser": "S",
"LDAPPassword": "42Ytp2AE3nN16eBoyia86UZH6", "LDAPPassword": "",
"ADTimeOut": "30", "ADTimeOut": "30",
"LoginWebAPI": "http://NEPHMDB-SQL007/CommonWebApiAD/api/AD" "LoginWebAPI": "http://NEPHMDB-SQL007/CommonWebApiAD/api/AD"
}, },
@@ -2,9 +2,9 @@
"AppSettings": { "AppSettings": {
"Secret": "Nepean Blue Mountain Super Secret SIGN AND VERIFY JWT TOKENS, BEARER TOKEN USE WHEN CALLING THIS API.", "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;", "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", "LDAPPath": "",
"LDAPUser": "SRV-NBMS-BIDSPMS", "LDAPUser": "S",
"LDAPPassword": "42Ytp2AE3nN16eBoyia86UZH6", "LDAPPassword": "",
"ADTimeOut": "30", "ADTimeOut": "30",
"LoginWebAPI": "http://NEPHMDB-SQL007/CommonWebApiAD/api/AD" "LoginWebAPI": "http://NEPHMDB-SQL007/CommonWebApiAD/api/AD"