UpdateSwitchUseCase.cs 826 B

1234567891011121314151617181920212223242526272829
  1. using RackPeek.Domain.Resources.Hardware.Models;
  2. namespace RackPeek.Domain.Resources.Hardware.Switchs;
  3. public class UpdateSwitchUseCase(IHardwareRepository repository)
  4. {
  5. public async Task ExecuteAsync(
  6. string name,
  7. string? model = null,
  8. bool? managed = null,
  9. bool? poe = null
  10. )
  11. {
  12. var switchResource = await repository.GetByNameAsync(name) as Switch;
  13. if (switchResource == null)
  14. throw new InvalidOperationException($"Switch '{name}' not found.");
  15. if (!string.IsNullOrWhiteSpace(model))
  16. switchResource.Model = model;
  17. if (managed.HasValue)
  18. switchResource.Managed = managed.Value;
  19. if (poe.HasValue)
  20. switchResource.Poe = poe.Value;
  21. await repository.UpdateAsync(switchResource);
  22. }
  23. }