public static OrphanStatistics GetOrphanStatistics() { OrphanStatistics orphStats = new OrphanStatistics(); List <Orphan> orphanList = new List <Orphan>(); try { // Replace with API code using (var context = new SMSContext()) { orphanList = context.Orphans .ToList(); orphStats.TotalCount = orphanList.Count(); orphStats.ActiveCount = (from x in orphanList where x.LCMStatus == "Active" select x).Count(); orphStats.InactiveCount = (from x in orphanList where x.LCMStatus == "Inactive" select x).Count(); orphStats.UnknownCount = orphStats.TotalCount - (orphStats.ActiveCount + orphStats.InactiveCount); } } catch (Exception eSql) { // Your code may benefit from more robust error handling or logging. // This logging is just a reminder that you should handle exceptions when connecting to remote data. System.Diagnostics.Debug.WriteLine($"Exception: {eSql.Message} {eSql.InnerException?.Message}"); } return(orphStats); }
private void DisplayOrphanStats() { SfChart chart = new SfChart() { Header = "Orphan Statistics", FontSize = 18, Height = 300, Width = 500 }; OrphanStatistics OrphanStats = new OrphanStatistics(); //GuardianStatistics GuardianStats = new GuardianStatistics(); //NarrationStatistics NarrationStats = new NarrationStatistics(); OrphanStats = OrphanDataService.GetOrphanStatistics(); TotalOrphanCount = OrphanStats.TotalCount; ActiveSeries = new List <ActivePieModel>() { new ActivePieModel { Category = "Active", Value = OrphanStats.ActiveCount }, new ActivePieModel { Category = "Inactive", Value = OrphanStats.InactiveCount }, new ActivePieModel { Category = "Unspecified", Value = OrphanStats.UnknownCount }, //new ActivePieModel { Category = "Total", Value = OrphanStats.TotalCount} }; //Adding Legends for the chart ChartLegend legend = new ChartLegend(); chart.Legend = legend; PieSeries series = new PieSeries() { ItemsSource = ActiveSeries, XBindingPath = "Category", YBindingPath = "Value", ShowTooltip = true, Label = "Values", AdornmentsInfo = new ChartAdornmentInfo() { ShowLabel = true }, }; chart.Series.Add(series); stackOrphanStats.Children.Add(chart); TextBlock txtTotal = new TextBlock(); txtTotal.FontSize = 14; txtTotal.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center; txtTotal.Text = "Total Orphan Count: " + TotalOrphanCount.ToString(); stackOrphanStats.Children.Add(txtTotal); }