Controller javítása userId-vel
This commit is contained in:
@@ -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)
|
||||
{
|
||||
@@ -249,10 +273,10 @@ namespace WorkFlowCheck.API.Controllers
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,9 +101,9 @@ namespace WorkFlowCheck.BL.Services
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public async Task<List<LocationDTO>> GetAllLocationAsync()
|
||||
{
|
||||
var retVal = new List<LocationDTO>();
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user