public ActionResult YearlyStatistics() { var participantsPerYearCount = 0; var sessionsForYear = _sessionManager.GetAllSessions().Where(n => n.StartDate < DateTime.Today) .Include(n => n.Activity) .OrderBy(n => n.Id) .ToList(); var totalSessionCount = sessionsForYear.Count; var sessionStatisticsRowsList = new List <SessionStatisticsRow>(); foreach (var session in sessionsForYear) { var participantCount = _personManager.GetAllParticipantsForSession(session.Id).Count(); sessionStatisticsRowsList.Add(new SessionStatisticsRow { NumberOfParticipants = participantCount, Session = session }); participantsPerYearCount += participantCount; } var viewModel = new SessionSummaryStatisticsViewModel { SessionStatisticsRows = sessionStatisticsRowsList, TotalPaticipants = participantsPerYearCount, TotalSessions = totalSessionCount, SelectedYear = 0, }; return(View(viewModel)); }
public ActionResult YearlyStatistics(string yearsList) { int yearInInt; var participantsPerYear = 0; var sessionscount = 0; var selectedyear = 0; var sessionStatisticsRowsList = new List <SessionStatisticsRow>(); if (string.IsNullOrEmpty(yearsList)) { return(RedirectToAction("YearlyStatistics")); } if (int.TryParse(yearsList, out yearInInt)) { selectedyear = yearInInt; //years = Enumerable.Range(2011, DateTime.Now.AddYears(1).Year - 2010).ToList(); var sessionsForYear = _sessionManager.GetAllSessionsForYear(selectedyear).Where(n => n.StartDate < DateTime.Today) .Include(n => n.Activity) .ToList() .OrderBy(n => n.Id); sessionscount = sessionsForYear.Count(); foreach (var session in sessionsForYear) { var participantCount = _personManager.GetAllParticipantsForSession(session.Id).Count(); sessionStatisticsRowsList.Add(new SessionStatisticsRow { NumberOfParticipants = participantCount, Session = session }); participantsPerYear = participantsPerYear + participantCount; } } var viewModel = new SessionSummaryStatisticsViewModel { //Years = years, SessionStatisticsRows = sessionStatisticsRowsList, TotalPaticipants = participantsPerYear, TotalSessions = sessionscount, SelectedYear = selectedyear, }; return(View(viewModel)); }