SystemEditModel.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using RackPeek.Domain.Resources.SystemResources;
  2. namespace Shared.Rcl.Systems;
  3. public sealed class SystemEditModel {
  4. private string? _type;
  5. public string Name { get; init; } = default!;
  6. public string? Type {
  7. get => _type;
  8. set => _type = string.IsNullOrWhiteSpace(value)
  9. ? null
  10. : value.Trim().ToLowerInvariant();
  11. }
  12. public string? Ip { get; set; }
  13. public string? Os { get; set; }
  14. public int? Cores { get; set; }
  15. public double? Ram { get; set; }
  16. public List<string> RunsOn { get; set; } = new();
  17. public string? Notes { get; set; }
  18. public static SystemEditModel From(SystemResource system) {
  19. return new SystemEditModel {
  20. Name = system.Name,
  21. // The type dropdown has no empty option, so a system without a
  22. // type still displays the first choice; default to it so what the
  23. // user sees is what gets saved (#306).
  24. Type = system.Type ?? SystemResource.ValidSystemTypes[0],
  25. Os = system.Os,
  26. Cores = system.Cores,
  27. Ram = system.Ram,
  28. Ip = system.Ip,
  29. RunsOn = system.RunsOn,
  30. Notes = system.Notes
  31. };
  32. }
  33. }