add lastmodified and lastmodifiedid to table also add code for modified and create
This commit is contained in:
@@ -18,6 +18,7 @@ namespace CarParkValidationAPI.Repository
|
||||
public class AdminUserFakeRepository : IAdminUser
|
||||
{
|
||||
private DataContext _context;
|
||||
private string _currentUser = "";
|
||||
List<AdminUserDto> _resultList = new List<AdminUserDto>();
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
@@ -31,7 +32,11 @@ namespace CarParkValidationAPI.Repository
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
private AdminUserDto FillAdminUserDto(AdminUser model)
|
||||
public void SetCurrentUser(string username)
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
private AdminUserDto FillAdminUserDto(AdminUser model)
|
||||
{
|
||||
AdminUserDto dto = new AdminUserDto();
|
||||
dto.Id = model.UserID;
|
||||
@@ -46,7 +51,6 @@ namespace CarParkValidationAPI.Repository
|
||||
|
||||
private AdminUser FillAdminUser(AdminUserDto dto, AdminUser model)
|
||||
{
|
||||
|
||||
model.UserID = dto.Id;
|
||||
model.Name = dto.Name;
|
||||
model.RoleType = dto.RoleType;
|
||||
|
||||
@@ -15,24 +15,27 @@ using System;
|
||||
|
||||
namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
public class AdminUserRepository : IAdminUser
|
||||
public class AdminUserRepository : IAdminUser
|
||||
{
|
||||
private DataContext _context;
|
||||
|
||||
private DataContext _context;
|
||||
private string _currentUser = "";
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
|
||||
public AdminUserRepository(
|
||||
DataContext context,
|
||||
public AdminUserRepository(
|
||||
DataContext context,
|
||||
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
private AdminUserDto FillAdminUserDto(AdminUser model)
|
||||
{
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
public void SetCurrentUser(string username)
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
private AdminUserDto FillAdminUserDto(AdminUser model)
|
||||
{
|
||||
AdminUserDto dto = new AdminUserDto();
|
||||
dto.Id = model.UserID;
|
||||
dto.Name = model.Name;
|
||||
@@ -42,7 +45,7 @@ namespace CarParkValidationAPI.Repository
|
||||
dto.AddedBy = model.AddedBy;
|
||||
dto.AddedOn = model.AddedOn;
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
||||
private AdminUser FillAdminUser(AdminUserDto dto, AdminUser model)
|
||||
{
|
||||
@@ -58,7 +61,7 @@ namespace CarParkValidationAPI.Repository
|
||||
}
|
||||
|
||||
public async Task<ResultModel<List<AdminUserDto>>> LoadAdminUserAsync(bool onlyActive)
|
||||
{
|
||||
{
|
||||
List<AdminUserDto> resultList = new List<AdminUserDto>();
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
@@ -71,10 +74,10 @@ namespace CarParkValidationAPI.Repository
|
||||
AdminUser user;
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
user = list[i];
|
||||
user = list[i];
|
||||
dto = FillAdminUserDto(user);
|
||||
resultList.Add(dto);
|
||||
|
||||
|
||||
}
|
||||
statuscode = 1;
|
||||
}
|
||||
@@ -98,22 +101,22 @@ namespace CarParkValidationAPI.Repository
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
{
|
||||
AdminUser model = await _context.AdminUsers.FindAsync(id);
|
||||
result = FillAdminUserDto(model);
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
{
|
||||
error = ex.ToString();
|
||||
statuscode = 0;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return new ResultModel<AdminUserDto>()
|
||||
}
|
||||
|
||||
return new ResultModel<AdminUserDto>()
|
||||
{
|
||||
Data = result,
|
||||
StatusCode = statuscode,
|
||||
@@ -126,16 +129,18 @@ namespace CarParkValidationAPI.Repository
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
try
|
||||
{
|
||||
{
|
||||
AdminUser model;
|
||||
if (item.Id > 0)
|
||||
{
|
||||
{
|
||||
model = await _context.AdminUsers.FindAsync(item.Id);
|
||||
model = FillAdminUser(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
model = new AdminUser();
|
||||
model = FillAdminUser(item, model);
|
||||
_context.AdminUsers.Add(model);
|
||||
@@ -143,15 +148,15 @@ namespace CarParkValidationAPI.Repository
|
||||
}
|
||||
result = 1;
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
{
|
||||
result = -1;
|
||||
error = ex.ToString();
|
||||
statuscode = 0;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new ResultModel<int>()
|
||||
{
|
||||
Data = result,
|
||||
@@ -159,7 +164,7 @@ namespace CarParkValidationAPI.Repository
|
||||
Message = error
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public async Task<ResultModel<bool>> DeleteAdminUserAsync(int id)
|
||||
{
|
||||
bool result = true;
|
||||
@@ -169,9 +174,11 @@ namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
AdminUser model = await _context.AdminUsers.FindAsync(id);
|
||||
model.Active = false;
|
||||
await _context.SaveChangesAsync();
|
||||
AdminUser model = await _context.AdminUsers.FindAsync(id);
|
||||
model.Active = false;
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
}
|
||||
@@ -182,7 +189,7 @@ namespace CarParkValidationAPI.Repository
|
||||
result = false;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
||||
return new ResultModel<bool>()
|
||||
{
|
||||
Data = result,
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace CarParkValidationAPI.Repository
|
||||
public class ConcessionTypeRepository : IConcessionType
|
||||
{
|
||||
private DataContext _context;
|
||||
|
||||
private readonly AppSettings _appSettings;
|
||||
private string _currentUser = "";
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public ConcessionTypeRepository(
|
||||
DataContext context,
|
||||
@@ -29,7 +29,10 @@ namespace CarParkValidationAPI.Repository
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
public void SetCurrentUser(string username)
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
private ConcessionTypeDto FillConcessionTypeDto(ConcessionType model)
|
||||
{
|
||||
ConcessionTypeDto dto = new ConcessionTypeDto();
|
||||
@@ -63,6 +66,7 @@ namespace CarParkValidationAPI.Repository
|
||||
Active = x.Active
|
||||
}).ToListAsync();
|
||||
statuscode = 1;
|
||||
result.Sort((x, y) => x.Description.CompareTo(y.Description));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -118,6 +122,8 @@ namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
model = await _context.ConcessionTypes.FindAsync(item.Id);
|
||||
model = FillConcessionType(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
await _context.SaveChangesAsync();
|
||||
result = item.Id;
|
||||
}
|
||||
@@ -125,6 +131,8 @@ namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
model = new ConcessionType();
|
||||
model = FillConcessionType(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
_context.ConcessionTypes.Add(model);
|
||||
var id = await _context.SaveChangesAsync();
|
||||
result = id;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarParkValidationAPI.Repository
|
||||
public class ConcessionValidationRepository : IConcessionValidation
|
||||
{
|
||||
private DataContext _context;
|
||||
|
||||
private string _currentUser = "";
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public ConcessionValidationRepository(
|
||||
@@ -29,6 +29,10 @@ namespace CarParkValidationAPI.Repository
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
public void SetCurrentUser(string username)
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
private ConcessionValidationDto FillConcessionValidationDto(ConcessionValidation model)
|
||||
{
|
||||
ConcessionValidationDto dto = new ConcessionValidationDto();
|
||||
@@ -167,7 +171,7 @@ namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
var anyRecord = await _context.SelectCheckConcessionValidationAsync(currentDate.ToLocalTime().Date, concessionCard, staffLinkNo);
|
||||
|
||||
if (anyRecord.Count > 0)
|
||||
if (anyRecord.Count > 1)
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
@@ -267,6 +271,7 @@ namespace CarParkValidationAPI.Repository
|
||||
int result = default(int);
|
||||
int statuscode = 0;
|
||||
string error = "";
|
||||
//_currentUser = item.StafflinkNo;
|
||||
try
|
||||
{
|
||||
ConcessionValidation model;
|
||||
@@ -274,12 +279,18 @@ namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
model = await _context.ConcessionValidations.FindAsync(item.Id);
|
||||
model = FillConcessionValidation(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
result = await _context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new ConcessionValidation();
|
||||
model = FillConcessionValidation(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
model.CreatedDate = DateTime.Now;
|
||||
model.CreatedId = _currentUser;
|
||||
_context.ConcessionValidations.Add(model);
|
||||
result = await _context.SaveChangesAsync();
|
||||
}
|
||||
@@ -312,8 +323,10 @@ namespace CarParkValidationAPI.Repository
|
||||
if (id > 0)
|
||||
{
|
||||
ConcessionValidation model = await _context.ConcessionValidations.FindAsync(id);
|
||||
// model.Active = false;
|
||||
_context.ConcessionValidations.Remove(model);
|
||||
model.Active = false;
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
//_context.ConcessionValidations.Remove(model);
|
||||
await _context.SaveChangesAsync();
|
||||
statuscode = 1;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ namespace CarParkValidationAPI.Repository
|
||||
|
||||
}).ToListAsync();
|
||||
statuscode = 1;
|
||||
result.Sort((x,y) => x.Description.CompareTo(y.Description));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -72,6 +73,7 @@ namespace CarParkValidationAPI.Repository
|
||||
Id = x.ValidationPointID,
|
||||
Description = x.Description
|
||||
}).ToListAsync();
|
||||
result.Sort((x, y) => x.Description.CompareTo(y.Description));
|
||||
statuscode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace CarParkValidationAPI.Repository
|
||||
private DataContext _context;
|
||||
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
private string _currentUser = "";
|
||||
private List<ValidationPointDto> _list = new List<ValidationPointDto>();
|
||||
|
||||
public ValidationPointFakeRepository(
|
||||
@@ -27,7 +27,10 @@ namespace CarParkValidationAPI.Repository
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
public void SetCurrentUser(string username)
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
private ValidationPointDto FillValidationDto(ValidationPoint item)
|
||||
{
|
||||
ValidationPointDto dto = new ValidationPointDto();
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace CarParkValidationAPI.Repository
|
||||
private DataContext _context;
|
||||
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
private string _currentUser = "";
|
||||
private List<ValidationPointDto> _list = new List<ValidationPointDto>();
|
||||
|
||||
public ValidationPointRepository(
|
||||
@@ -27,7 +27,10 @@ namespace CarParkValidationAPI.Repository
|
||||
_context = context;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
public void SetCurrentUser(string username)
|
||||
{
|
||||
_currentUser = username;
|
||||
}
|
||||
private ValidationPointDto FillValidationDto(ValidationPoint item)
|
||||
{
|
||||
ValidationPointDto dto = new ValidationPointDto();
|
||||
@@ -38,7 +41,7 @@ namespace CarParkValidationAPI.Repository
|
||||
return dto;
|
||||
}
|
||||
|
||||
private ValidationPoint FillValidationModel(ValidationPointDto item, ValidationPoint model) {
|
||||
private ValidationPoint FillValidationModel(ValidationPointDto item, ValidationPoint model) {
|
||||
|
||||
model.Active = item.Active;
|
||||
model.Description = item.Description;
|
||||
@@ -61,7 +64,7 @@ namespace CarParkValidationAPI.Repository
|
||||
dto = FillValidationDto(it[i]);
|
||||
_list.Add(dto);
|
||||
}
|
||||
|
||||
_list.Sort((x, y) => x.Description.CompareTo(y.Description));
|
||||
statuscode = 1;
|
||||
|
||||
}
|
||||
@@ -116,12 +119,16 @@ namespace CarParkValidationAPI.Repository
|
||||
{
|
||||
model = await _context.Validations.FindAsync(item.Id);
|
||||
model = FillValidationModel(item, model);
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
await _context.SaveChangesAsync();
|
||||
result = item.Id;
|
||||
}
|
||||
else //new record
|
||||
{
|
||||
model = new ValidationPoint();
|
||||
model.LastModified = DateTime.Now;
|
||||
model.LastModifiedId = _currentUser;
|
||||
model = FillValidationModel(item, model);
|
||||
_context.Validations.Add(model);
|
||||
var id = await _context.SaveChangesAsync();
|
||||
|
||||
Reference in New Issue
Block a user