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
+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
};
}
}
}