diff --git a/src/WorkFlowCheck.API/Controllers/SyncController.cs b/src/WorkFlowCheck.API/Controllers/SyncController.cs index ee3795d..ed370af 100644 --- a/src/WorkFlowCheck.API/Controllers/SyncController.cs +++ b/src/WorkFlowCheck.API/Controllers/SyncController.cs @@ -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>> GetAllCheckListTemplateHeaderAsync() + [HttpGet("GetAllCheckListTemplateHeader/{userId}")] + public async Task>> GetAllCheckListTemplateHeaderAsync(int userId) { var retVal = new ApiResponseDTO>() { 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>> GetAllCheckListHeaderAsync(int userId) + { + var retVal = new ApiResponseDTO>() + { + IsSuccess = true, + }; + var response = await _syncService.GetAllCheckListAsync(userId); if (response != null) { @@ -249,10 +273,10 @@ namespace WorkFlowCheck.API.Controllers return retVal; } - - - - + + + + } } diff --git a/src/WorkFlowCheck.BL/Services/Interfaces/ISyncService.cs b/src/WorkFlowCheck.BL/Services/Interfaces/ISyncService.cs index f51b516..915ee14 100644 --- a/src/WorkFlowCheck.BL/Services/Interfaces/ISyncService.cs +++ b/src/WorkFlowCheck.BL/Services/Interfaces/ISyncService.cs @@ -20,6 +20,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces Task UpdateEquipmentAsync(EquipmentDTO EquipmentDTO); - Task> GetAllCheckListTemplateAsync(); + Task> GetAllCheckListTemplateAsync(int userId); + Task> GetAllCheckListAsync(int userId); } } diff --git a/src/WorkFlowCheck.BL/Services/SyncService.cs b/src/WorkFlowCheck.BL/Services/SyncService.cs index 3cbe307..7b4e7b0 100644 --- a/src/WorkFlowCheck.BL/Services/SyncService.cs +++ b/src/WorkFlowCheck.BL/Services/SyncService.cs @@ -101,9 +101,9 @@ namespace WorkFlowCheck.BL.Services return retVal; } - - - + + + public async Task> GetAllLocationAsync() { var retVal = new List(); @@ -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(LocationDTO); + res = _mapper.Map(LocationDTO); await _dbContext.SaveChangesAsync(); @@ -260,18 +260,54 @@ namespace WorkFlowCheck.BL.Services return retVal; } - public async Task> GetAllCheckListTemplateAsync() + public async Task> GetAllCheckListTemplateAsync(int userId) { var retVal = new List(); 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>(res); + + } + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + + return retVal; + } + public async Task> GetAllCheckListAsync(int userId) + { + var retVal = new List(); + + 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>(res); - + retVal = _mapper.Map>(res); } } catch (Exception ex) diff --git a/src/WorkFlowCheck.DL/AppDbContext.cs b/src/WorkFlowCheck.DL/AppDbContext.cs index 4d16440..0a17fa7 100644 --- a/src/WorkFlowCheck.DL/AppDbContext.cs +++ b/src/WorkFlowCheck.DL/AppDbContext.cs @@ -45,7 +45,7 @@ namespace WorkFlowCheck.DL public DbSet Users { get; set; } = null!; public DbSet UserRoles { get; set; } = null!; - public DbSet UsersCheckListTemplateHeaders { get; set; } = null!; + public DbSet RoleCheckListTemplateHeaders { get; set; } = null!; #endregion