UpdateDesktopDriveUseCase.cs 739 B

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