UpdateUpsUseCase.cs 645 B

12345678910111213141516171819202122232425
  1. using RackPeek.Domain.Resources.Hardware.Models;
  2. namespace RackPeek.Domain.Resources.Hardware.UpsUnits;
  3. public class UpdateUpsUseCase(IHardwareRepository repository)
  4. {
  5. public async Task ExecuteAsync(
  6. string name,
  7. string? model = null,
  8. int? va = null
  9. )
  10. {
  11. var ups = await repository.GetByNameAsync(name) as Ups;
  12. if (ups == null)
  13. throw new InvalidOperationException($"UPS '{name}' not found.");
  14. if (!string.IsNullOrWhiteSpace(model))
  15. ups.Model = model;
  16. if (va.HasValue)
  17. ups.Va = va.Value;
  18. await repository.UpdateAsync(ups);
  19. }
  20. }