public IActionResult Index(string username = null, string manualLoginUsername = null, string manualLoginCode = null, string message = null) { if (Log.IsEnabled(LogLevel.Debug)) { Log.LogDebug("GET: /Geeks/Index"); } TimeZoneInfo gmtTimeZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"); var viewModel = new GeeksIndexViewModel() { ManualLoginUsername = manualLoginUsername, ManualLoginCode = manualLoginCode, Message = message, IsGmtInDaylightSaving = gmtTimeZone.IsDaylightSavingTime(DateTime.UtcNow) }; GeekViewModel geekViewModel = GetGeek(username); viewModel.Geek = geekViewModel; if (!string.IsNullOrWhiteSpace(username) && !geekViewModel.DoesGeekExist) { ModelState.AddModelError("Geek.Username", "No geek has been found with that username"); } return(View(viewModel)); }
GeekViewModel GetGeek(string username) { GeekViewModel geekViewModel = new GeekViewModel(); if (username != null) { try { var geek = _geekService.GetGeekByUsername(username); geekViewModel = new GeekViewModel(geek); } catch (Exception ex) when(ex is ObjectDisposedException || ex is MySqlException) { // The database connection occasionally times out when this is hosted on a free // Microsoft Azure instance. The second request should work and this saves // us having to ask the user to reload the page string errorMessage = "Got exception when trying to get the geek from the database. " + "Assuming it's just a timeout and repeating the database call, {0}"; Log.LogError(errorMessage, ex); var geek = _geekService.GetGeekByUsername(username); geekViewModel = new GeekViewModel(geek); } } geekViewModel.AlwaysShowPingTimes = _appSettings.AlwaysShowPingTimes; return(geekViewModel); }