RoleCheckListHeaderTemplate befejezése új/módosítás

This commit is contained in:
2025-03-28 12:55:10 +01:00
parent f119b196ea
commit ddc898cc2e
11 changed files with 419 additions and 8 deletions
@@ -22,8 +22,10 @@ namespace WorkFlowCheck.BL.Services.Interfaces
Task<List<UserRoleDTO>> GetAllUserRoleAsync();
Task<UserRoleDTO> UpdateUserRoleAsync(UserRoleDTO userRoleDTO);
Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplateHeadersAsync();
Task<RoleCheckListTemplateHeaderDTO> GetRoleCheckListTemplateHeaderAsync(int Id);
Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplateHeadersAsync();
Task<RoleCheckListTemplateHeaderDTO> UpdateRoleCheckListTemplateHeaderAsync(RoleCheckListTemplateHeaderDTO roleCheckListTemplateHeaderDTO);
string GenerateJwtToken(UserDTO userDTO);
}
}
@@ -340,6 +340,24 @@ namespace WorkFlowCheck.BL.Services
return retVal;
}
public async Task<RoleCheckListTemplateHeaderDTO> GetRoleCheckListTemplateHeaderAsync(int Id)
{
var retVal = new RoleCheckListTemplateHeaderDTO();
try
{
var userRole = await _dbContext.RoleCheckListTemplateHeaders.Where(w => w.Id == Id).FirstOrDefaultAsync();
if (userRole != null)
{
retVal = _mapper.Map<RoleCheckListTemplateHeaderDTO>(userRole);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplateHeadersAsync()
{
var retVal = new List<RoleCheckListTemplateHeaderDTO>();
@@ -361,5 +379,55 @@ namespace WorkFlowCheck.BL.Services
}
return retVal;
}
public async Task<RoleCheckListTemplateHeaderDTO> UpdateRoleCheckListTemplateHeaderAsync(RoleCheckListTemplateHeaderDTO roleCheckListTemplateHeaderDTO)
{
var retVal = new RoleCheckListTemplateHeaderDTO();
try
{
if (roleCheckListTemplateHeaderDTO.Id == 0)
{
var roleCheckListTemplateHeader_Exists = await _dbContext.RoleCheckListTemplateHeaders
.Where(w => w.RoleId == roleCheckListTemplateHeaderDTO.RoleId &&
w.CheckListTemplateHeaderId == roleCheckListTemplateHeaderDTO.CheckListTemplateHeaderId)
.FirstOrDefaultAsync();
if (roleCheckListTemplateHeader_Exists == null)
{
var roleCheckListTemplateHeader = new RoleCheckListTemplateHeader();
roleCheckListTemplateHeader.CheckListTemplateHeaderId = roleCheckListTemplateHeaderDTO.CheckListTemplateHeaderId;
roleCheckListTemplateHeader.RoleId = roleCheckListTemplateHeaderDTO.RoleId;
roleCheckListTemplateHeader.Enabled = roleCheckListTemplateHeaderDTO.Enabled;
_dbContext.RoleCheckListTemplateHeaders.Add(roleCheckListTemplateHeader);
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<RoleCheckListTemplateHeaderDTO>(roleCheckListTemplateHeader);
}
else
{
retVal = _mapper.Map<RoleCheckListTemplateHeaderDTO>(roleCheckListTemplateHeader_Exists);
}
}
else
{
var roleCheckListTemplateHeader = await _dbContext.RoleCheckListTemplateHeaders.Where(w => w.Id == roleCheckListTemplateHeaderDTO.Id).FirstOrDefaultAsync();
if (roleCheckListTemplateHeader != null)
{
roleCheckListTemplateHeader.CheckListTemplateHeaderId = roleCheckListTemplateHeaderDTO.CheckListTemplateHeaderId;
roleCheckListTemplateHeader.RoleId = roleCheckListTemplateHeaderDTO.RoleId;
roleCheckListTemplateHeader.Enabled = roleCheckListTemplateHeaderDTO.Enabled;
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<RoleCheckListTemplateHeaderDTO>(roleCheckListTemplateHeader);
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
}
}