public IActionResult Index() { var allHosts = _store().FindAllHosts(); var addDaemonHostViewModel = new AddDaemonHostViewModel { Hosts = allHosts }; return(View(addDaemonHostViewModel)); }
public async Task <IActionResult> AddDaemonHostUrl(AddDaemonHostViewModel viewModel) { try { var url = viewModel.DaemonHostUrl; if (string.IsNullOrEmpty(url)) { return(RedirectToAction(nameof(Index))); } if (!url.Contains(':') && !url.Contains('/')) { url = _configuration.WebApiUrlTemplate.Replace("{hostName}", url); } var uri = new Uri(url); // try to parse url, if not valid, just fail. url = uri.ToString(); var daemonHost = _store().Find(url); if (daemonHost == null) { var isAliveApi = _restApiProvider.Get <IIsAliveApi>(url); await isAliveApi.Get(); daemonHost = new DaemonHost { Name = viewModel.DaemonHostUrl, Url = url }; _store().Upsert(daemonHost); } return(RedirectToAction(nameof(ListDaemons), new { hostId = daemonHost.Id })); } catch (Exception ex) { viewModel.Error = ex.Message; return(View(nameof(Index), viewModel)); } }