UpdateSystemUseCase.cs 926 B

1234567891011121314151617181920212223242526272829303132333435
  1. namespace RackPeek.Domain.Resources.SystemResources.UseCases;
  2. public class UpdateSystemUseCase(ISystemRepository repository)
  3. {
  4. public async Task ExecuteAsync(
  5. string name,
  6. string? type = null,
  7. string? os = null,
  8. int? cores = null,
  9. int? ram = null,
  10. string? runsOn = null
  11. )
  12. {
  13. var system = await repository.GetByNameAsync(name);
  14. if (system is null)
  15. throw new InvalidOperationException($"System '{name}' not found.");
  16. if (!string.IsNullOrWhiteSpace(type))
  17. system.Type = type;
  18. if (!string.IsNullOrWhiteSpace(os))
  19. system.Os = os;
  20. if (cores.HasValue)
  21. system.Cores = cores.Value;
  22. if (ram.HasValue)
  23. system.Ram = ram.Value;
  24. if (!string.IsNullOrWhiteSpace(runsOn))
  25. system.RunsOn = runsOn;
  26. await repository.UpdateAsync(system);
  27. }
  28. }