UpdateDesktopDriveUseCase.cs 742 B

12345678910111213141516171819
  1. using RackPeek.Domain.Resources.Hardware.Models;
  2. namespace RackPeek.Domain.Resources.Hardware.Desktop;
  3. public class UpdateDesktopDriveUseCase(IHardwareRepository repository)
  4. {
  5. public async Task ExecuteAsync(string desktopName, int index, Drive updated)
  6. {
  7. var desktop = await repository.GetByNameAsync(desktopName) as Models.Desktop
  8. ?? throw new InvalidOperationException($"Desktop '{desktopName}' not found.");
  9. if (desktop.Drives == null || index < 0 || index >= desktop.Drives.Count)
  10. throw new InvalidOperationException($"Drive index {index} not found on desktop '{desktopName}'.");
  11. desktop.Drives[index] = updated;
  12. await repository.UpdateAsync(desktop);
  13. }
  14. }