update to .NET 6.0

This commit is contained in:
Kham
2022-12-02 15:53:33 +11:00
parent b32d02b001
commit 93fa738d72
12 changed files with 235 additions and 23 deletions
+29 -1
View File
@@ -195,7 +195,35 @@ namespace CarParkValidationAPI.Repository
Message = error
};
}
public async Task<ResultModel<Dictionary<int, LookupCodeDto>>> GetConcessionTypeDicAsync()
{
Dictionary<int, LookupCodeDto> resultList = new();
int statusCode = 0;
string error = "";
try
{
resultList = await _context.ConcessionTypes.Where(x => x.Active == true)
.Select(item => new LookupCodeDto { Id = item.ConcessionTypeID, Description = item.ConcessionDesc ?? "" })
.ToDictionaryAsync(x => x.Id);
}
statusCode = 1;
}
catch (Exception ex)
{
error = ex.ToString();
statusCode = 0;
throw ex;
}
return new ResultModel<Dictionary<int, LookupCodeDto>>()
{
Data = resultList,
StatusCode = statusCode,
Message = error
};
}
}
}
+18 -9
View File
@@ -13,6 +13,7 @@ using CarParkValidationAPI.Interface;
using Microsoft.EntityFrameworkCore;
using CommonAD.Models;
using CommonAD;
using Microsoft.AspNetCore.Http;
namespace CarParkValidationAPI.Repository
{
@@ -30,7 +31,7 @@ namespace CarParkValidationAPI.Repository
_context = context;
_jwtUtils = jwtUtils;
_appSettings = appSettings.Value;
}
public AuthenticateResponse Authenticate(AuthenticateRequest model)
{
@@ -84,7 +85,7 @@ namespace CarParkValidationAPI.Repository
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)
{
@@ -132,13 +133,13 @@ namespace CarParkValidationAPI.Repository
LDAPUser = _appSettings.LDAPUser,
ADTimeOutStr = _appSettings.ADTimeOut
};
myUser = await Task.Run(() => LoginADStaff(adConfig,model.Username, model.Password));
myUser = await Task.Run(() => LoginADStaff(adConfig, model.Username, model.Password));
if (!string.IsNullOrEmpty(myUser.Username))
{
statuscode = 1;
{
statuscode = 1;
// authentication successful so generate jwt token
var jwtToken = _jwtUtils.GenerateJwtToken(myUser);
retval = new AuthenticateResponse(myUser, jwtToken);
}
return new ResultModel<AuthenticateResponse>()
@@ -159,7 +160,7 @@ namespace CarParkValidationAPI.Repository
}
public async Task<ResultModel<User>> GetById(int id)
public async Task<ResultModel<User>> GetById(int id)
{
var user = await _context.Users.FindAsync(id);
if (user == null) throw new KeyNotFoundException("User not found");
@@ -190,7 +191,7 @@ namespace CarParkValidationAPI.Repository
Data = myUser,
StatusCode = statuscode
};
// return myUser;
// return myUser;
}
@@ -236,7 +237,7 @@ namespace CarParkValidationAPI.Repository
{
ADStaffLink staffLink = new ADStaffLink(adConfig);
MyADObject myADObj = staffLink.CheckADCredentials(username,password);
MyADObject myADObj = staffLink.CheckADCredentials(username, password);
User user = new()
{
Username = myADObj.stafflinkNo,
@@ -249,5 +250,13 @@ namespace CarParkValidationAPI.Repository
// return null;
}
public async Task<ResultModel<FileContent>> GetAllUserReport()
{
return new ResultModel<FileContent>
{
Data = null,
StatusCode = 1
};
}
}
}
+130 -1
View File
@@ -13,6 +13,9 @@ using CarParkValidationAPI.Interface;
using Microsoft.EntityFrameworkCore;
using CommonAD.Models;
using CommonAD;
using SpreadsheetLight;
using System.IO;
using System;
namespace CarParkValidationAPI.Repository
{
@@ -21,14 +24,18 @@ namespace CarParkValidationAPI.Repository
private DataContext _context;
private IJwtUtils _jwtUtils;
private readonly AppSettings _appSettings;
private readonly IValidationPoint _validationPoint;
private Dictionary<int, LookupCodeDto> _validationPointDic;
public UserRepository(
DataContext context,
IJwtUtils jwtUtils,
IValidationPoint validationPoint,
IOptions<AppSettings> appSettings)
{
_context = context;
_jwtUtils = jwtUtils;
_validationPoint = validationPoint;
_appSettings = appSettings.Value;
}
@@ -53,6 +60,7 @@ namespace CarParkValidationAPI.Repository
User myUser = null;
AuthenticateResponse retval = null;
int statuscode = 0;
string error = "";
string webAPIUrl = _appSettings.LoginWebAPI;
var loginInfo = await CommonAD.WebAPIUtil.PostLoginADAsync(webAPIUrl, "CheckCredentials", model.Username, model.Password);
@@ -77,6 +85,7 @@ namespace CarParkValidationAPI.Repository
else //not allow
{
statuscode = 0;
error = "username is not exist in admimuser.";
myUser.Role = AdminRole.Normal;
}
// validate
@@ -88,11 +97,14 @@ namespace CarParkValidationAPI.Repository
retval = new AuthenticateResponse(myUser, jwtToken);
}
else
error = "error username or password is invalid";
return new ResultModel<AuthenticateResponse>()
{
Data = retval,
StatusCode = statuscode
StatusCode = statuscode,
Message = error
};
}
@@ -225,5 +237,122 @@ namespace CarParkValidationAPI.Repository
// return null;
}
private string GetVPDesc(int? idn)
{
string result = "";
int id = idn ?? 1;
if (_validationPointDic.ContainsKey(id))
{
result = _validationPointDic[id].Description;
}
return result;
}
public async Task<ResultModel<FileContent>> GetAllUserReport()
{
//excel SLDocument sl = new SLDocument();
int statusCode = 1;
AdminUser item;
int col = 1;
int row = 1;
SLDocument sl = new SLDocument();
var ret = await _validationPoint.GetValidationPointDicAsync();
if (ret.StatusCode == 1)
_validationPointDic = ret.Data;
//first sheetName
sl.RenameWorksheet(SLDocument.DefaultFirstSheetName, "All User");
SLStyle style = sl.CreateStyle();
style.SetFontUnderline(DocumentFormat.OpenXml.Spreadsheet.UnderlineValues.Single);
style.SetFontBold(true);
style.SetFont("Arial Black", 16);
sl.SetCellStyle(1, 5, style);
sl.SetRowHeight(1, 1, 25);
sl.SetCellValue(row++, 5, "The User Report");
sl.SetCellValue(1, 6, " " + DateTime.Now.ToString("ddd dd/MM/yyyy HH:mm"));
int startTitleRow = 3;
row = startTitleRow;
//make the title bold
style = sl.CreateStyle();
style.Font.Bold = true;
sl.SetRowStyle(startTitleRow, style);
//set it height
sl.SetRowHeight(startTitleRow, startTitleRow, 25);
// add the title first
sl.SetCellValue(row, col++, "Stafflink ID");
sl.SetCellValue(row, col++, "Name");
sl.SetCellValue(row, col++, "Role");
sl.SetCellValue(row, col++, "Validation Point");
sl.SetCellValue(row, col++, "Active");
sl.FreezePanes(row,0); //frozen the row.
//wrap text on is concession Expiry
style = sl.CreateStyle();
style.SetWrapText(true);
sl.SetColumnStyle(4, style);
//format date
style = sl.CreateStyle();
style.FormatCode = "dd/MM/yyyy HH:MM";
sl.SetColumnStyle(1, style);
//make column width
sl.SetColumnWidth(1, 20);
sl.SetColumnWidth(2, 50);
sl.SetColumnWidth(3, 20);
sl.SetColumnWidth(4, 30);
sl.SetColumnWidth(5, 20);
/*
public enum AdminRole
{
Normal = 1,
Admin = 2
}
*/
int startRowFrom = startTitleRow + 1;
var list = await _context.AdminUsers.ToListAsync();
for (int i = 0; i < list.Count; i++)
{
col = 1;
item = list[i];
row = i + startRowFrom;
sl.SetCellValue(row, col++, item.StafflinkNo);
sl.SetCellValue(row, col++, item.Name);
sl.SetCellValue(row, col++, (int) item.RoleType == 1 ? "Normal": "Admin");
sl.SetCellValue(row, col++, GetVPDesc(item.ValidationPointID) );
sl.SetCellValue(row, col++, item.Active ? "Yes" : "No");
}
byte[] array;
// sl.SaveAs("C:\\Temp\\Report\\ConcessionValidationDate" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xlsx");
using (MemoryStream ws = new MemoryStream())
{
sl.SaveAs(ws);
array = ws.ToArray();
/*
using (FileStream fs = new FileStream("c:\\temp\\Report\\conReport.xlsx",FileMode.Create,FileAccess.Write))
{
ws.WriteTo(fs);
fs.Close();
}
*/
ws.Close();
}
var result = new FileContent
{
Content = array,
FileName = "UserReport" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm") + ".xlsx",
};
return new ResultModel<FileContent>
{
Data = result,
StatusCode = statusCode
};
}
}
}
+13 -1
View File
@@ -2,6 +2,8 @@
using CarParkValidationAPI.Entities;
using CarParkValidationAPI.Interface;
using CarParkValidationAPI.Models;
using DocumentFormat.OpenXml.VariantTypes;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using System;
@@ -189,7 +191,17 @@ namespace CarParkValidationAPI.Repository
}
}
public async Task<ResultModel<Dictionary<int, LookupCodeDto>>> GetValidationPointDicAsync()
{
Dictionary<int, LookupCodeDto> resultList = new();
return new ResultModel<Dictionary<int, LookupCodeDto>>()
{
Data = resultList,
StatusCode = 1,
Message = ""
};
}
}
}
}
+30 -1
View File
@@ -184,5 +184,34 @@ namespace CarParkValidationAPI.Repository
Message = error
};
}
}
public async Task<ResultModel<Dictionary<int, LookupCodeDto>>> GetValidationPointDicAsync()
{
Dictionary<int, LookupCodeDto> resultList = new();
int statusCode = 0;
string error = "";
try
{
resultList = await _context.Validations.Where(x => x.Active == true)
.Select(item => new LookupCodeDto { Id = item.ValidationPointID, Description = item.Description ?? "" })
.ToDictionaryAsync(x => x.Id);
statusCode = 1;
}
catch (Exception ex)
{
error = ex.ToString();
statusCode = 0;
throw ex;
}
return new ResultModel<Dictionary<int, LookupCodeDto>>()
{
Data = resultList,
StatusCode = statusCode,
Message = error
};
}
}
}