Van új és folytatható CheckLista

This commit is contained in:
2025-03-22 14:18:25 +01:00
parent 6d78762275
commit 3a4db4dd14
10 changed files with 232 additions and 26 deletions
+42 -3
View File
@@ -12,9 +12,10 @@ namespace WorkFlowCheck.MAUI.Services
{
public class SyncService : BaseService, ISyncService
{
public SyncService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper) : base(httpClient, configuration, dbContext, mapper)
private readonly IUserService _userService;
public SyncService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper, IUserService userService) : base(httpClient, configuration, dbContext, mapper)
{
_userService = userService;
}
public async Task SyncDatas()
{
@@ -22,6 +23,7 @@ namespace WorkFlowCheck.MAUI.Services
await SyncLocations();
await SyncEquipments();
await SyncCheckListTemplates();
await SyncCheckList();
}
public async Task SyncCheckPoints()
{
@@ -119,7 +121,8 @@ namespace WorkFlowCheck.MAUI.Services
{
await PrepareAuthenticatedRequestAsync();
// Az API végpont meghatározása
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckListTemplateHeader";
var userId = _userService.GetCurrentUser()?.Id;
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckListTemplateHeader/{userId}";
// HTTP GET kérés küldése
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<CheckListTemplateHeaderDTO>>>(endpoint);
@@ -143,5 +146,41 @@ namespace WorkFlowCheck.MAUI.Services
}
}
public async Task SyncCheckList()
{
try
{
await PrepareAuthenticatedRequestAsync();
if (_userService == null)
{
return;
}
// Az API végpont meghatározása
var userId = _userService.GetCurrentUser()?.Id;
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckListHeader/{userId}";
// HTTP GET kérés küldése
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<CheckListHeaderDTO>>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
var checkListHeaderList = await _dbContext.CheckListHeaders.ToListAsync();
var missingItems = response.Data.Where(f => !checkListHeaderList.Any(s => s.GuidNumber == f.GuidNumber)).ToList();
var missingCheckListHeaders = _mapper.Map<List<CheckListHeader>>(missingItems);
_dbContext.CheckListHeaders.AddRange(missingCheckListHeaders);
await _dbContext.SaveChangesAsync();
}
}
}
catch (Exception ex)
{
// Hiba visszaadása
}
}
}
}