add in the check user already exist.

This commit is contained in:
Kham
2021-11-05 09:29:10 +11:00
parent 1131159112
commit f409ff1afb
5 changed files with 492 additions and 12 deletions
@@ -60,7 +60,15 @@ namespace CarParkValidationAPI.Repository
model.AddedOn = dto.AddedOn;
return model;
}
public async Task<ResultModel<bool>> CheckAdminUserByStaffLinkNoAsync(string staffLinkNo)
{
var list = await _context.AdminUsers.Where(x => x.StafflinkNo == staffLinkNo).ToListAsync();
return new ResultModel<bool>()
{
Data = false,
StatusCode = 1
};
}
public async Task<ResultModel<List<AdminUserViewDto>>> LoadAdminUserAsync(bool onlyActive)
{
/*
@@ -89,7 +97,8 @@ namespace CarParkValidationAPI.Repository
throw ex;
}
*/
for (int i =0; i < 10; i++)
var list = await _context.AdminUsers.Where(x => x.Active == onlyActive).ToListAsync();
for (int i =0; i < list.Count; i++)
{
AdminUserViewDto dto = new AdminUserViewDto();
dto.Id = i;
@@ -110,7 +119,7 @@ namespace CarParkValidationAPI.Repository
public async Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id)
{
AdminUserDto result = null;
/*
try
{
if (id > 0)
@@ -124,9 +133,7 @@ namespace CarParkValidationAPI.Repository
{
throw ex;
}
*/
return new ResultModel<AdminUserDto>()
{
Data = result,
@@ -119,6 +119,37 @@ namespace CarParkValidationAPI.Repository
Message = error
};
}
public async Task<ResultModel<bool>> CheckAdminUserByStaffLinkNoAsync(string staffLinkNo)
{
bool result = false;
int statuscode = 0;
string error = "";
try
{
if (!string.IsNullOrEmpty(staffLinkNo))
{
var list = await _context.AdminUsers.Where( x=> x.StafflinkNo == staffLinkNo).ToListAsync();
if (list.Count > 0)
{
result = true;
statuscode = 1;
}
}
}
catch (Exception ex)
{
error = ex.ToString();
statuscode = 0;
throw ex;
}
return new ResultModel<bool>()
{
Data = result,
StatusCode = statuscode,
Message = error
};
}
public async Task<ResultModel<AdminUserDto>> LoadAdminUserByIdAsync(int id)
{
AdminUserDto result = null;
@@ -162,17 +193,32 @@ namespace CarParkValidationAPI.Repository
model.LastModified = DateTime.Now;
model.LastModifiedId = _currentUser;
await _context.SaveChangesAsync();
result = model.UserID;
statuscode = 1;
}
else
{
model = new AdminUser();
model = FillAdminUser(item, model);
_context.AdminUsers.Add(model);
await _context.SaveChangesAsync();
ResultModel<bool> found = await CheckAdminUserByStaffLinkNoAsync(item.StafflinkNo);
if (!found.Data)
{
model = new AdminUser();
model = FillAdminUser(item, model);
_context.AdminUsers.Add(model);
await _context.SaveChangesAsync();
result = model.UserID;
statuscode = 1;
}
else
{
error = "staff link No '" + item.StafflinkNo + "' already in admin user";
statuscode = 0;
result = 0;
}
}
result = model.UserID;
statuscode = 1;
}
catch (Exception ex)
{