49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
namespace UtopiaCanteenSystem.Services;
|
|
|
|
public class OfflineCacheSyncService : IOfflineCacheSyncService
|
|
{
|
|
private readonly IEmployeeRfidTagSyncService _employeeRfidTagSync;
|
|
private readonly IMealMenuCacheSyncService _mealMenuCacheSync;
|
|
|
|
public OfflineCacheSyncService(
|
|
IEmployeeRfidTagSyncService employeeRfidTagSync,
|
|
IMealMenuCacheSyncService mealMenuCacheSync)
|
|
{
|
|
_employeeRfidTagSync = employeeRfidTagSync;
|
|
_mealMenuCacheSync = mealMenuCacheSync;
|
|
}
|
|
|
|
public async Task<OfflineCacheSyncResult> SyncEmployeeAndMenuCacheAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
var employeeResult = await _employeeRfidTagSync.SyncAllAsync(cancellationToken).ConfigureAwait(false);
|
|
if (!employeeResult.Success)
|
|
{
|
|
return new OfflineCacheSyncResult
|
|
{
|
|
Success = false,
|
|
ErrorMessage = employeeResult.ErrorMessage ?? "Employee RFID cache sync failed.",
|
|
EmployeeSync = employeeResult
|
|
};
|
|
}
|
|
|
|
var mealMenuResult = await _mealMenuCacheSync.SyncAllAsync(cancellationToken).ConfigureAwait(false);
|
|
if (!mealMenuResult.Success)
|
|
{
|
|
return new OfflineCacheSyncResult
|
|
{
|
|
Success = false,
|
|
ErrorMessage = mealMenuResult.ErrorMessage ?? "Meal/menu cache sync failed.",
|
|
EmployeeSync = employeeResult,
|
|
MealMenuSync = mealMenuResult
|
|
};
|
|
}
|
|
|
|
return new OfflineCacheSyncResult
|
|
{
|
|
Success = true,
|
|
EmployeeSync = employeeResult,
|
|
MealMenuSync = mealMenuResult
|
|
};
|
|
}
|
|
}
|