Controller javítása userId-vel

This commit is contained in:
2025-03-22 14:19:00 +01:00
parent 3a4db4dd14
commit d55dee91e9
4 changed files with 78 additions and 17 deletions
@@ -3,6 +3,7 @@ using Serilog;
using WorkFlowCheck.BL.Services;
using WorkFlowCheck.BL.Services.Interfaces;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.DL.Entities;
namespace WorkFlowCheck.API.Controllers
{
@@ -225,14 +226,37 @@ namespace WorkFlowCheck.API.Controllers
}
[HttpGet("GetAllCheckListTemplateHeader")]
public async Task<ApiResponseDTO<List<CheckListTemplateHeaderDTO>>> GetAllCheckListTemplateHeaderAsync()
[HttpGet("GetAllCheckListTemplateHeader/{userId}")]
public async Task<ApiResponseDTO<List<CheckListTemplateHeaderDTO>>> GetAllCheckListTemplateHeaderAsync(int userId)
{
var retVal = new ApiResponseDTO<List<CheckListTemplateHeaderDTO>>()
{
IsSuccess = true,
};
var response = await _syncService.GetAllCheckListTemplateAsync();
var response = await _syncService.GetAllCheckListTemplateAsync(userId);
if (response != null)
{
retVal.IsSuccess = true;
retVal.Data = response;
}
else
{
retVal.IsSuccess = false;
retVal.Errors.Add("No data!");
}
return retVal;
}
[HttpGet("GetAllCheckListHeader/{userId}")]
public async Task<ApiResponseDTO<List<CheckListHeaderDTO>>> GetAllCheckListHeaderAsync(int userId)
{
var retVal = new ApiResponseDTO<List<CheckListHeaderDTO>>()
{
IsSuccess = true,
};
var response = await _syncService.GetAllCheckListAsync(userId);
if (response != null)
{
@@ -20,6 +20,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
Task<EquipmentDTO> UpdateEquipmentAsync(EquipmentDTO EquipmentDTO);
Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateAsync();
Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateAsync(int userId);
Task<List<CheckListHeaderDTO>> GetAllCheckListAsync(int userId);
}
}
+41 -5
View File
@@ -164,7 +164,7 @@ namespace WorkFlowCheck.BL.Services
var res = await _dbContext.Locations.Where(w => w.Id == LocationDTO.Id).FirstOrDefaultAsync();
if (res != null)
{
res=_mapper.Map<Location>(LocationDTO);
res = _mapper.Map<Location>(LocationDTO);
await _dbContext.SaveChangesAsync();
@@ -260,18 +260,54 @@ namespace WorkFlowCheck.BL.Services
return retVal;
}
public async Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateAsync()
public async Task<List<CheckListTemplateHeaderDTO>> GetAllCheckListTemplateAsync(int userId)
{
var retVal = new List<CheckListTemplateHeaderDTO>();
try
{
var res = await _dbContext.CheckListTemplateHeaders.Include(i => i.CheckListTemplateRows).AsNoTracking().ToListAsync();
var user = _dbContext.Users.Where(w => w.Id == userId).FirstOrDefault();
if (user != null)
{
var res = await (from ur in _dbContext.UserRoles
join rth in _dbContext.RoleCheckListTemplateHeaders on ur.RoleId equals rth.RoleId
join header in _dbContext.CheckListTemplateHeaders on rth.CheckListTemplateHeaderId equals header.Id
where ur.UserId == userId
select header)
.Include(h => h.CheckListTemplateRows)
.Distinct()
.AsNoTracking()
.ToListAsync();
if (res != null)
{
retVal = _mapper.Map<List<CheckListTemplateHeaderDTO>>(res);
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<List<CheckListHeaderDTO>> GetAllCheckListAsync(int userId)
{
var retVal = new List<CheckListHeaderDTO>();
try
{
var res = await _dbContext.CheckListHeaders
.Where(w => w.IsEditable && w.UserId == userId)
.Include(i => i.CheckListRows)
.AsNoTracking()
.ToListAsync();
if (res != null)
{
retVal = _mapper.Map<List<CheckListTemplateHeaderDTO>>(res);
retVal = _mapper.Map<List<CheckListHeaderDTO>>(res);
}
}
catch (Exception ex)
+1 -1
View File
@@ -45,7 +45,7 @@ namespace WorkFlowCheck.DL
public DbSet<Entities.User> Users { get; set; } = null!;
public DbSet<Entities.UserRole> UserRoles { get; set; } = null!;
public DbSet<Entities.RoleCheckListTemplateHeader> UsersCheckListTemplateHeaders { get; set; } = null!;
public DbSet<Entities.RoleCheckListTemplateHeader> RoleCheckListTemplateHeaders { get; set; } = null!;
#endregion