public async Task <IActionResult> IndexAsync() { var currentUser = await _userManager.FindByNameAsync(User.Identity.Name).ConfigureAwait(false); var bugModels = await _userBug.GetAllBugsByUserAsync(currentUser).ConfigureAwait(false); var listingModel = bugModels .Select(result => new BugListingModel { Id = result.Id, Title = result.Title, Urgency = result.Urgency?.Level, Status = result.Status?.Name, Team = result.Owner?.Name, CreatedOn = result.CreatedOn, Project = result.ProjectAffected?.Name, AssignedTo = result.AssignedTo == null ? "" : result.AssignedTo.FirstName + " " + result.AssignedTo.LastName }); var model = new BugIndexModel() { Bugs = listingModel }; return(View(model)); }
public IActionResult Index(int Id) { // auto load latest stats: Error - Divide by Zero (Death Rate - global) ?? //DownStats(); var latest = _bug.GetLatestDownloadDate(); // default sort: Cases var bugModel = _bug.GetAll() .Where(d => d.DownloadDate == latest) .ToList().OrderByDescending(c => c.Cases); // sort by Country (1) if (Id == 1) { bugModel = _bug.GetAll() .Where(d => d.DownloadDate == latest) .ToList().OrderBy(c => c.Country); } // sort by Cases (2) if (Id == 2) { bugModel = _bug.GetAll() .Where(d => d.DownloadDate == latest) .ToList().OrderByDescending(c => c.Cases); } // sort by TodayCases (3) if (Id == 3) { bugModel = _bug.GetAll() .Where(d => d.DownloadDate == latest) .ToList().OrderByDescending(c => c.TodayCases); } // sort by Deaths (4) if (Id == 4) { bugModel = _bug.GetAll() .Where(d => d.DownloadDate == latest) .ToList().OrderByDescending(c => c.Deaths); } // sort by TodayDeaths (5) if (Id == 5) { bugModel = _bug.GetAll() .Where(d => d.DownloadDate == latest) .ToList().OrderByDescending(c => c.TodayDeaths); } // sort by Cases/M (6) if (Id == 6) { bugModel = _bug.GetAll() .Where(d => d.DownloadDate == latest) .ToList().OrderByDescending(c => c.CasesPerOneMillion); } // sort by Deaths/M (7) if (Id == 7) { bugModel = _bug.GetAll() .Where(d => d.DownloadDate == latest) .ToList().OrderByDescending(c => c.DeathsPerOneMillion); } // sort by Population (8) if (Id == 8) { bugModel = _bug.GetAll() .Where(d => d.DownloadDate == latest) .ToList().OrderByDescending(c => c.Population); } // sort by Death% (7) if (Id == 9) { bugModel = _bug.GetAll() .Where(d => d.DownloadDate == latest) .ToList().OrderByDescending(c => c.DeathPercentage); } var bugs = bugModel .Select(f => new BugListingModel { Id = f.Id, Country = f.Country, ScrAPI_Id = f.ScrAPI_Id, Lat = f.Lat, Long = f.Long, Flag = f.Flag, Iso3 = f.Iso3, Iso2 = f.Iso2, Cases = f.Cases, CaseStr = f.Cases.ToString("N0"), TodayCases = f.TodayCases, Deaths = f.Deaths, TodayDeaths = f.TodayDeaths, Recovered = f.Recovered, Active = f.Active, Critical = f.Critical, CasesPerOneMillion = f.CasesPerOneMillion, DeathsPerOneMillion = f.DeathsPerOneMillion, DownloadDate = f.DownloadDate, Population = f.Population, PopStr = f.Population.ToString("N0"), DeathPercentage = f.DeathPercentage } ).ToList(); var res = new BugIndexModel { BugListing = bugs, DownloadDate = latest, TotalActive = _bug.GetTotalActive(latest), TotalCases = _bug.GetTotalCases(latest), TotalCritical = _bug.GetTotalCritical(latest), TotalDeaths = _bug.GetTotalDeaths(latest), TotalRecovered = _bug.GetTotalRecovered(latest), TotalTodayCases = _bug.GetTotalTodayCases(latest), TotalTodayDeaths = _bug.GetTotalTodayDeaths(latest), DeathPercentage = _bug.GetDeathPercentage(latest), TotalActiveStr = _bug.GetTotalActive(latest).ToString("N0"), TotalCasesStr = _bug.GetTotalCases(latest).ToString("N0"), TotalCriticalStr = _bug.GetTotalCritical(latest).ToString("N0"), TotalDeathsStr = _bug.GetTotalDeaths(latest).ToString("N0"), TotalRecoveredStr = _bug.GetTotalRecovered(latest).ToString("N0"), TotalTodayCasesStr = _bug.GetTotalTodayCases(latest).ToString("N0"), TotalTodayDeathsStr = _bug.GetTotalTodayDeaths(latest).ToString("N0"), TotalCountries = _bug.GetTotalCountries(latest) }; return(View(res)); }