using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; namespace Inventory.Core { public class UpdateWorkflow { private readonly DatabaseUpdater _databaseUpdater; private readonly SystemInfoCollector _collector; private readonly InventoryContext _db; private readonly SlurpitClient _slurpitClient; public UpdateWorkflow(DatabaseUpdater databaseUpdater, SystemInfoCollector collector, InventoryContext db, SlurpitClient slurpitClient) { _databaseUpdater = databaseUpdater; _collector = collector; _db = db; _slurpitClient = slurpitClient; } public async Task Run() { // This updates all properties EXCEPT printers. await _databaseUpdater.UpsertDevice(); // Fetch the final, complete device object from the database to send to Slurpit. // This ensures that when the agent runs, it sends the printer data that the AdminTool saved. var identifier = _databaseUpdater.GetLocalIdentifier(); if (!string.IsNullOrEmpty(identifier)) { var finalDevice = await _db.Devices.AsNoTracking().FirstOrDefaultAsync(d => d.HardwareIdentifier == identifier); if (finalDevice != null) await _slurpitClient.SendDeviceData(finalDevice); } } } }