protected void Page_Load(object sender, EventArgs e) { using (TrainingDataEntities context = new TrainingDataEntities()) { DataTotals totals = DataAccess.GetDataTotals(context); eventCountSpan.InnerText = totals.EventTotal.ToString(); mileCountSpan.InnerText = string.Format("{0:F1}", totals.MileTotal); hourCountSpan.InnerText = string.Format("{0} Hours and {1} Minutes", totals.TimeTotal.Hours, totals.TimeTotal.Minutes); } }
public static DataTotals GetDataTotals(TrainingDataEntities entityContext) { DataTotals totals = new DataTotals(); totals.EventTotal = entityContext.Events.Count(); // we need to iterate to work out the distance and time totals foreach (Event ev in entityContext.Events) { // work out the total time by summing the OverallTime values totals.TimeTotal += ev.OverallTime; // work out the total miles by using the navigation properties EventType type = ev.EventType; totals.MileTotal += (type.SwimMiles + type.CycleMiles + type.RunMiles); } return(totals); }