public async Task <ActionResult> Index() { try { List <Application> allApps = await ApplicationBusiness.FindAllAsync(); User user = AccountBusiness.GetCurrentUser(); if (user == null) { return(RedirectToAction("Login", "Account")); } IEnumerable <long> appIds = (await ApplicationBusiness.GetAppsOfUserAsync(user.Id)).Select(p => p.Id); Util.Clear <GaugeData>(Code.Classes.Util.GetLayoutViewModel().Gauges); Code.Classes.Util.GetLayoutViewModel().Lines.Clear(); var viewModel = new ApplicationViewModel(); foreach (int appId in appIds) { Application app = await ApplicationBusiness.GetByIdAsync(appId); if (app.Id > 0) { ApplicationStatus appStatus = await ApplicationBusiness.GetAppStatusAsync(app.Id); ApplicationTrends appTrend = await ApplicationBusiness.GetApplicationTrendAsync(app.Id); app.Status = appStatus; app.Trend = appTrend; viewModel.Applications.Add(app); } } return(View("Index", viewModel)); } catch (Exception exception) { Logger.LogError(exception); throw; } }
public async Task <ApplicationTrends> GetApplicationTrendAsync(long id) { if (UnitOfWork == null) { throw new InvalidOleVariantTypeException("Unit of work is not provided."); } var result = new ApplicationTrends(); const string getAppByIdSprocName = "GetEventTrendOfApp"; using (DbConnection connection = UnitOfWork.Connection) { await connection.OpenAsync(); var command = connection.CreateCommand() as SqlCommand; if (command != null) { command.CommandType = CommandType.StoredProcedure; command.CommandText = getAppByIdSprocName; command.Parameters.AddWithValue("@AppId", id); using (SqlDataReader reader = await command.ExecuteReaderAsync()) { //Fatals while (await reader.ReadAsync()) { DateTime key = reader.GetDateTime(0).Date; int value = reader.GetInt32(1); if (!result.Fatals.ContainsKey(key)) { result.Fatals.TryAdd(key, value); } else { result.Fatals[key] = result.Fatals[key] + value; } } await reader.NextResultAsync(); // Errors while (await reader.ReadAsync()) { DateTime key = reader.GetDateTime(0).Date; int value = reader.GetInt32(1); if (!result.Fatals.ContainsKey(key)) { result.Errors.TryAdd(key, value); } else { result.Errors[key] = result.Fatals[key] + value; } } await reader.NextResultAsync(); // Warnings while (await reader.ReadAsync()) { DateTime key = reader.GetDateTime(0).Date; int value = reader.GetInt32(1); if (!result.Fatals.ContainsKey(key)) { result.Warnings.TryAdd(key, value); } else { result.Warnings[key] = result.Fatals[key] + value; } } } } } return(result); }