public async Task <ActionResult <IEnumerable <Account> > > GetAllAccountsByUserID(int id) { try { IEnumerable <Account> result = null; _logger?.LogInformation(string.Format("Start GetAllAccountsByUserID: {0}", id.ToString())); result = await _repo?.GetAllAccountsByUserId(id) ?? null; result = result?.Where(a => !a.IsClosed).ToList() ?? null; // Check if returned list has any elements. if (result == null || result?.Count() < 1) { // Return NotFound 404 response on empty list. _logger?.LogWarning(string.Format("No Accounts found for UserID: {0}", id.ToString())); return(NotFound(null)); } // Return list of accounts on successful find. _logger?.LogInformation(string.Format("GetAllAccountsByUserID: {0} Succeeded.", id.ToString())); return(Ok(result.ToList())); } catch (Exception WTF) { // Return Internal Server Error 500 on general exception. _logger?.LogError(WTF, "Unexpected Error in GetAllAccountsByUserID!"); return(StatusCode(StatusCodes.Status500InternalServerError)); } }