add new RoleType and validationPoint to AdminUser
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user