update to .NET 6.0
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -5,6 +5,7 @@ using CarParkValidationAPI.Models.Users;
|
||||
using CarParkValidationAPI.Interface;
|
||||
using System.Threading.Tasks;
|
||||
using CarParkValidationAPI.Models;
|
||||
using System;
|
||||
|
||||
namespace CarParkValidationAPI.Controllers
|
||||
{
|
||||
@@ -78,5 +79,14 @@ namespace CarParkValidationAPI.Controllers
|
||||
var user = await _userService.GetById(id);
|
||||
return Ok(user);
|
||||
}
|
||||
/* download the excel file */
|
||||
[HttpGet("[action]")]
|
||||
public async Task<IActionResult> GetReportFile()
|
||||
{
|
||||
// this.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
var result = await _userService.GetAllUserReport(); // .GetReport(fromDate, toDate);
|
||||
string fileContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; //Map(result.Data.FileName);
|
||||
return File(result.Data.Content, fileContentType, result.Data.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace CarParkValidationAPI.Entities
|
||||
{
|
||||
public enum Role
|
||||
{
|
||||
Admin,
|
||||
User
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ namespace CarParkValidationAPI.Interface
|
||||
Task<ResultModel<int>> SaveConcessionTypeAsync(ConcessionTypeDto item);
|
||||
Task<ResultModel<ConcessionTypeDto>> LoadConcessionTypeByIdAsync(int id);
|
||||
Task<ResultModel<bool>> DeleteConcessionTypeAsync(int id);
|
||||
Task<ResultModel<Dictionary<int, LookupCodeDto>>> GetConcessionTypeDicAsync();
|
||||
void SetCurrentUser(string username);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace CarParkValidationAPI.Interface
|
||||
Task<ResultModel<int>> SaveConcessionValidationAsync(ConcessionValidationDto item);
|
||||
Task<ResultModel<ConcessionValidationDto>> LoadConcessionValidationByIdAsync(int id);
|
||||
Task<ResultModel<bool>> DeleteConcessionValidationAsync(int id);
|
||||
Task<ResultModel<FileContent>> GetReport(DateTime fromDate, DateTime toDate);
|
||||
|
||||
void SetCurrentUser(string username);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,6 @@ namespace CarParkValidationAPI.Interface
|
||||
Task<ResultModel<User>> GetById(int id);
|
||||
Task<ResultModel<User>> SearchApiStaff(string staffLinkNo);
|
||||
Task<ResultModel<User>> SearchADStaff(string staffLinkNo);
|
||||
Task<ResultModel<FileContent>> GetAllUserReport();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace CarParkValidationAPI.Interface
|
||||
Task<ResultModel<int>> SaveValidationPointAsync(ValidationPointDto item);
|
||||
Task<ResultModel<ValidationPointDto>> LoadValidationPointByIdAsync(int id);
|
||||
Task<ResultModel<bool>> DeleteValidationPointAsync(int id);
|
||||
Task<ResultModel<Dictionary<int, LookupCodeDto>>> GetValidationPointDicAsync();
|
||||
void SetCurrentUser(string username);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ using CarParkValidationAPI.Interface;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using CommonAD.Models;
|
||||
using CommonAD;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
@@ -132,7 +133,7 @@ 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;
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 = ""
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user