RemoveDesktopDriveUseCase.cs 773 B

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