add new RoleType and validationPoint to AdminUser
This commit is contained in:
@@ -21,6 +21,27 @@ namespace CarParkValidationAPI.Entities
|
||||
public bool Active { get; set; }
|
||||
|
||||
public AdminRole RoleType { get; set; }
|
||||
|
||||
public int ValidationPointId { get; set; }
|
||||
#endregion
|
||||
}
|
||||
public class AdminUserViewDto
|
||||
{
|
||||
#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 string RoleType { get; set; }
|
||||
|
||||
public string ValidationPoint { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace CarParkValidationAPI.Interface
|
||||
{
|
||||
public interface IAdminUser
|
||||
{
|
||||
Task<ResultModel<List<AdminUserDto>>> LoadAdminUserAsync(bool OnlyActive);
|
||||
Task<ResultModel<List<AdminUserViewDto>>> LoadAdminUserAsync(bool OnlyActive);
|
||||
Task<ResultModel<int>> SaveAdminUserAsync(AdminUserDto item);
|
||||
Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id);
|
||||
Task<ResultModel<bool>> DeleteAdminUserAsync(int id);
|
||||
|
||||
@@ -56,6 +56,8 @@ namespace CarParkValidationAPI.Models
|
||||
public bool Active { get; set; }
|
||||
|
||||
public AdminRole RoleType { get; set; }
|
||||
|
||||
public int? ValidationPointID { get; set; }
|
||||
public DateTime? LastModified { get; set; }
|
||||
public string? LastModifiedId { get; set; }
|
||||
#endregion
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace CarParkValidationAPI.Models
|
||||
public string Email { get; set; }
|
||||
public string Username { get; set; }
|
||||
public AdminRole Role { get; set; }
|
||||
public int ValidationPointId { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public string PasswordHash { get; set; }
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace CarParkValidationAPI.Models.Users
|
||||
public string LastName { get; set; }
|
||||
public string Username { get; set; }
|
||||
public AdminRole Role { get; set; }
|
||||
public int ValidationPointId { get; set; }
|
||||
public string Token { get; set; }
|
||||
public string Email { get; set; }
|
||||
public AuthenticateResponse(User user, string token)
|
||||
@@ -20,6 +21,7 @@ namespace CarParkValidationAPI.Models.Users
|
||||
Email = user.Email;
|
||||
Role = user.Role;
|
||||
Token = token;
|
||||
ValidationPointId = user.ValidationPointId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
private DataContext _context;
|
||||
private string _currentUser = "";
|
||||
List<AdminUserDto> _resultList = new List<AdminUserDto>();
|
||||
List<AdminUserViewDto> _resultList = new List<AdminUserViewDto>();
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace CarParkValidationAPI.Repository
|
||||
return model;
|
||||
}
|
||||
|
||||
public async Task<ResultModel<List<AdminUserDto>>> LoadAdminUserAsync(bool onlyActive)
|
||||
public async Task<ResultModel<List<AdminUserViewDto>>> LoadAdminUserAsync(bool onlyActive)
|
||||
{
|
||||
/*
|
||||
List<AdminUserDto> resultList = new List<AdminUserDto>();
|
||||
@@ -91,17 +91,17 @@ namespace CarParkValidationAPI.Repository
|
||||
*/
|
||||
for (int i =0; i < 10; i++)
|
||||
{
|
||||
AdminUserDto dto = new AdminUserDto();
|
||||
AdminUserViewDto dto = new AdminUserViewDto();
|
||||
dto.Id = i;
|
||||
dto.Name = $"Name {i}";
|
||||
dto.RoleType = AdminRole.Admin;
|
||||
dto.RoleType = AdminRole.Admin.ToString();
|
||||
dto.StafflinkNo = $"{i+40000}";
|
||||
dto.Active = true;
|
||||
dto.AddedOn = DateTime.Today.AddDays(i);
|
||||
dto.AddedBy = "ddfed";
|
||||
_resultList.Add(dto);
|
||||
}
|
||||
return new ResultModel<List<AdminUserDto>>()
|
||||
return new ResultModel<List<AdminUserViewDto>>()
|
||||
{
|
||||
Data = _resultList,
|
||||
StatusCode = 1
|
||||
@@ -125,11 +125,7 @@ namespace CarParkValidationAPI.Repository
|
||||
throw ex;
|
||||
}
|
||||
*/
|
||||
int idx = _resultList.FindIndex(x => x.Id == id);
|
||||
if (idx > -1)
|
||||
{
|
||||
result = _resultList[idx];
|
||||
}
|
||||
|
||||
|
||||
return new ResultModel<AdminUserDto>()
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace CarParkValidationAPI.Repository
|
||||
private DataContext _context;
|
||||
private string _currentUser = "";
|
||||
private readonly AppSettings _appSettings;
|
||||
private Dictionary<int, string> _ValidationPointDic = null;
|
||||
|
||||
|
||||
public AdminUserRepository(
|
||||
@@ -34,6 +35,26 @@ namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
private string GetValidtionPointDesc(int id)
|
||||
{
|
||||
string result = "";
|
||||
if (_ValidationPointDic != null && _ValidationPointDic.ContainsKey(id))
|
||||
result = _ValidationPointDic[id];
|
||||
return result;
|
||||
}
|
||||
private AdminUserViewDto FillAdminUserViewDto(AdminUser model)
|
||||
{
|
||||
AdminUserViewDto dto = new AdminUserViewDto();
|
||||
dto.Id = model.UserID;
|
||||
dto.Name = model.Name;
|
||||
dto.RoleType = model.RoleType.ToString();
|
||||
dto.StafflinkNo = model.StafflinkNo;
|
||||
dto.Active = model.Active;
|
||||
dto.AddedBy = model.AddedBy;
|
||||
dto.AddedOn = model.AddedOn;
|
||||
dto.ValidationPoint = GetValidtionPointDesc(model.ValidationPointID??0);
|
||||
return dto;
|
||||
}
|
||||
private AdminUserDto FillAdminUserDto(AdminUser model)
|
||||
{
|
||||
AdminUserDto dto = new AdminUserDto();
|
||||
@@ -44,12 +65,12 @@ namespace CarParkValidationAPI.Repository
|
||||
dto.Active = model.Active;
|
||||
dto.AddedBy = model.AddedBy;
|
||||
dto.AddedOn = model.AddedOn;
|
||||
dto.ValidationPointId = model.ValidationPointID ?? 0;
|
||||
return dto;
|
||||
}
|
||||
|
||||
private AdminUser FillAdminUser(AdminUserDto dto, AdminUser model)
|
||||
{
|
||||
|
||||
model.UserID = dto.Id;
|
||||
model.Name = dto.Name;
|
||||
model.RoleType = dto.RoleType;
|
||||
@@ -57,25 +78,28 @@ namespace CarParkValidationAPI.Repository
|
||||
model.Active = dto.Active;
|
||||
model.AddedBy = dto.AddedBy;
|
||||
model.AddedOn = dto.AddedOn;
|
||||
model.ValidationPointID = dto.ValidationPointId;
|
||||
return model;
|
||||
}
|
||||
|
||||
public async Task<ResultModel<List<AdminUserDto>>> LoadAdminUserAsync(bool onlyActive)
|
||||
public async Task<ResultModel<List<AdminUserViewDto>>> LoadAdminUserAsync(bool onlyActive)
|
||||
{
|
||||
List<AdminUserDto> resultList = new List<AdminUserDto>();
|
||||
List<AdminUserViewDto> resultList = new List<AdminUserViewDto>();
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
_ValidationPointDic = await _context.Validations.Where(x => x.Active == true).ToDictionaryAsync((x) => x.ValidationPointID, y => y.Description);
|
||||
|
||||
//var list = await _context.AdminUsers.Where(x => x.Active == onlyActive).ToListAsync();
|
||||
var list = await _context.AdminUsers.AsQueryable().ToListAsync();
|
||||
|
||||
AdminUserDto dto;
|
||||
AdminUserViewDto dto;
|
||||
AdminUser user;
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
user = list[i];
|
||||
dto = FillAdminUserDto(user);
|
||||
dto = FillAdminUserViewDto(user);
|
||||
resultList.Add(dto);
|
||||
|
||||
}
|
||||
@@ -88,7 +112,7 @@ namespace CarParkValidationAPI.Repository
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return new ResultModel<List<AdminUserDto>>()
|
||||
return new ResultModel<List<AdminUserViewDto>>()
|
||||
{
|
||||
Data = resultList,
|
||||
StatusCode = statuscode,
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
private readonly IOptions<AppSettings> _appSettings;
|
||||
const string DateFormat = "dd-MM-yyyy";
|
||||
const string DateFormat = "dd-MM-yyyy HH:mm";
|
||||
public ConcessionValidationReportRepository(
|
||||
DataContext context, IOptions<AppSettings> appSettings)
|
||||
{
|
||||
@@ -60,10 +60,10 @@ namespace CarParkValidationAPI.Repository
|
||||
sl.SetCellValue(row, col++, "Expiry date checked");
|
||||
sl.SetCellValue(row, col++, "ConcessionType");
|
||||
sl.SetCellValue(row, col++, "Validation Piont");
|
||||
sl.SetCellValue(row, col++, "StaffLink No");
|
||||
sl.SetCellValue(row, col++, "Staff First name");
|
||||
sl.SetCellValue(row, col++, "Staff Last name");
|
||||
sl.SetCellValue(row, col++, "Staff Email");
|
||||
// sl.SetCellValue(row, col++, "StaffLink No");
|
||||
sl.SetCellValue(row, col++, "Enter by");
|
||||
// sl.SetCellValue(row, col++, "Staff Last name");
|
||||
// sl.SetCellValue(row, col++, "Staff Email");
|
||||
sl.FreezePanes(row, col - 1); //frozen the row.
|
||||
//wrap text on is concession Expiry
|
||||
style = sl.CreateStyle();
|
||||
@@ -73,19 +73,19 @@ namespace CarParkValidationAPI.Repository
|
||||
//format date
|
||||
|
||||
style = sl.CreateStyle();
|
||||
style.FormatCode = "dd/mm/yyyy";
|
||||
style.FormatCode = "dd/MM/yyyy HH:MM";
|
||||
sl.SetColumnStyle(1, style);
|
||||
//make column width
|
||||
sl.SetColumnWidth(1, 20);
|
||||
sl.SetColumnWidth(2, 18);
|
||||
sl.SetColumnWidth(3, 25);
|
||||
sl.SetColumnWidth(4, 20);
|
||||
sl.SetColumnWidth(5, 30);
|
||||
sl.SetColumnWidth(5, 50);
|
||||
sl.SetColumnWidth(6, 40);
|
||||
sl.SetColumnWidth(7, 20);
|
||||
sl.SetColumnWidth(8, 20);
|
||||
sl.SetColumnWidth(9, 20);
|
||||
sl.SetColumnWidth(10, 20);
|
||||
sl.SetColumnWidth(7, 40);
|
||||
// sl.SetColumnWidth(8, 20);
|
||||
// sl.SetColumnWidth(9, 20);
|
||||
// sl.SetColumnWidth(10, 20);
|
||||
int startRowFrom = startTitleRow+1;
|
||||
var list = await _context.SelectConcessionValidationByDate(true, fromDate.ToLocalTime(), toDate.ToLocalTime());
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
@@ -99,10 +99,10 @@ namespace CarParkValidationAPI.Repository
|
||||
sl.SetCellValue(row, col++, item.ConcessionExpiry ? "Yes": "No");
|
||||
sl.SetCellValue(row, col++, item.ConcessionType);
|
||||
sl.SetCellValue(row, col++, item.ValidationPoint);
|
||||
sl.SetCellValue(row, col++, item.StafflinkNo);
|
||||
sl.SetCellValue(row, col++, item.StaffFirstName);
|
||||
sl.SetCellValue(row, col++, item.StaffLastName);
|
||||
sl.SetCellValue(row, col++, item.StaffEmail);
|
||||
// sl.SetCellValue(row, col++, item.StafflinkNo);
|
||||
sl.SetCellValue(row, col++, item.StaffFirstName + " " + item.StaffLastName);
|
||||
// sl.SetCellValue(row, col++, item.StaffLastName);
|
||||
// sl.SetCellValue(row, col++, item.StaffEmail);
|
||||
}
|
||||
byte[] array;
|
||||
// sl.SaveAs("C:\\Temp\\Report\\ConcessionValidationDate" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xlsx");
|
||||
|
||||
@@ -69,18 +69,22 @@ namespace CarParkValidationAPI.Repository
|
||||
&& x.Active == true);
|
||||
if (user != null)
|
||||
{
|
||||
myUser.Role = AdminRole.Admin; //user.RoleType;
|
||||
myUser.Role = user.RoleType;
|
||||
myUser.Id = user.UserID;
|
||||
myUser.ValidationPointId = user.ValidationPointID??0;
|
||||
statuscode = 1;
|
||||
}
|
||||
else
|
||||
else //not allow
|
||||
{
|
||||
statuscode = 0;
|
||||
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;
|
||||
//statuscode = 1;
|
||||
retval = new AuthenticateResponse(myUser, jwtToken);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user