public Logbook(DateTime day) { LogbookService = new LogbookService(); InitializeComponent(); var binding = new LogbookBinding(); var listItems = LogbookService.GetLogbookItems().Where(x => x.GlucoseMeasurement.BaseTime.Date == day.Date).ToObservableCollection(); if (!listItems.Any()) { LogbookItems.IsVisible = false; NoItems.IsVisible = true; } else { LogbookItems.IsVisible = true; NoItems.IsVisible = false; foreach (var item in listItems) { binding.LogbookListItems.Add(new LogbookItemViewModel(item)); } } BindingContext = binding; LogbookItems.ItemTemplate = new DataTemplate(typeof(ViewCells.LogbookItemCell)); Title = "Logbook"; //AddMeasurement.Clicked += AddMeasurement_Clicked; }
public LogbookDates() { LogbookService = new LogbookService(); InitializeComponent(); var binding = new LogbookBinding(); var listItems = LogbookService.GetLogbookItems(); var dates = listItems.Select(x => x.GlucoseMeasurement.BaseTime).DistinctBy(x => x.ToShortDateString()).OrderByDescending(x => x.Ticks).ToObservableCollection(); if (!listItems.Any()) { LogbookItems.IsVisible = false; NoItems.IsVisible = true; } else { LogbookItems.IsVisible = true; NoItems.IsVisible = false; foreach (var item in dates) { var num = listItems.Count(x => x.GlucoseMeasurement.BaseTime.ToShortDateString() == item.ToShortDateString()); var stars = (int)Math.Round((((decimal)num / (decimal)Session.User.NumberOfMeasurements) * 3)); binding.LogbookListItems.Add(new LogbookDateViewModel(item, stars)); } LogbookItems.ItemTapped += (sender, e) => { var item = ((LogbookDateViewModel)e.Item); Navigation.PushAsync(new Logbook(item.Date) { Title = item.DateString }); }; } BindingContext = binding; LogbookItems.ItemTemplate = new DataTemplate(typeof(ViewCells.LogbookDateCell)); Title = "Logbook"; //AddMeasurement.Clicked += AddMeasurement_Clicked; }