Exemplo n.º 1
0
        private void LoadFoodLog()
        {
            ProgressBar.Visibility = Visibility.Visible;

            context = new FoodContext();
            FoodLogGrid.ItemsSource = context.FoodLogEntries;

            context.Load <FoodLogEntry>(context.GetFoodLogEntriesQuery(Globals.CurrentUser.id, Globals.SelectedDate, true),
                                        (EntriesLoaded) => { ProgressBar.Visibility = Visibility.Collapsed; }, null);
        }
        private void LoadPublicJournal()
        {
            if (settings != null)
            {
                if (settings.share_foods)
                {
                    foodContext.Load <FoodLogEntry>(foodContext.GetFoodLogEntriesQuery(settings.user_id, Calendar.SelectedDate.Value, false));
                    FoodLogGrid.Visibility = Visibility.Visible;
                }
                else
                {
                    FoodLogGrid.Visibility = Visibility.Collapsed;
                }

                if (settings.share_exercises)
                {
                    exerciseContext.Load <ExerciseLogEntry>(exerciseContext.GetExerciseLogEntriesQuery(Calendar.SelectedDate.Value, settings.user_id),
                                                            LoadBehavior.RefreshCurrent, (EntriesLoaded) =>
                    {
                        if (!EntriesLoaded.HasError)
                        {
                            CardioLogGrid.ItemsSource         = EntriesLoaded.Entities.Where(ev => ev.Exercise.exercise_type == 1);
                            WeightTrainingLogGrid.ItemsSource = EntriesLoaded.Entities.Where(ev => ev.Exercise.exercise_type == 2);
                            ActivityLogGrid.ItemsSource       = EntriesLoaded.Entities.Where(ev => ev.Exercise.exercise_type == 3);
                        }
                    }, null);

                    CardioLogGrid.Visibility         = Visibility.Visible;
                    WeightTrainingLogGrid.Visibility = Visibility.Visible;
                    ActivityLogGrid.Visibility       = Visibility.Visible;
                }
                else
                {
                    CardioLogGrid.Visibility         = Visibility.Collapsed;
                    WeightTrainingLogGrid.Visibility = Visibility.Collapsed;
                    ActivityLogGrid.Visibility       = Visibility.Collapsed;
                }

                if (settings.share_measurements)
                {
                    measurementContext.Load <MeasurementLogEntry>(measurementContext.GetMeasurementLogEntriesQuery(settings.user_id, Calendar.SelectedDate.Value));
                    MeasurementLogGrid.Visibility = Visibility.Visible;
                }
                else
                {
                    MeasurementLogGrid.Visibility = Visibility.Collapsed;
                }

                if (settings.share_images)
                {
                    measurementContext.Load <MeasurementImage>(measurementContext.GetMeasurementImageQuery(settings.user_id, Calendar.SelectedDate.Value),
                                                               LoadBehavior.RefreshCurrent, (ImageLoaded) =>
                    {
                        if (!ImageLoaded.HasError)
                        {
                            BitmapImage updatedImage      = null;
                            MeasurementImage currentImage = ImageLoaded.Entities.FirstOrDefault <MeasurementImage>();

                            if (currentImage != null)
                            {
#if DEBUG
                                updatedImage = new BitmapImage(new Uri(String.Format("http://localhost:32490/UploadedImages/{0}",
                                                                                     ImageLoaded.Entities.First <MeasurementImage>()), UriKind.Absolute));
#else
                                updatedImage = new BitmapImage(new Uri(String.Format("http://fitnesstrackerplus.com/UploadedImages/{0}",
                                                                                     finalFileName), UriKind.Absolute));
#endif
                                // This is necessary to ensure that Silverlight refreshes the image even though the file name remains the same

                                updatedImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                                CurrentImage.Source        = updatedImage;
                            }
                            else
                            {
                                CurrentImage.Source = new BitmapImage(new Uri("/Images/image_unavailable.png", UriKind.Relative));
                            }
                        }
                    }, null);

                    CurrentImage.Visibility = Visibility.Visible;
                }
                else
                {
                    CurrentImage.Visibility = Visibility.Collapsed;
                }

                if (settings.enable_comments)
                {
                    HtmlPage.Document.GetElementById("comment_area").SetStyleAttribute("display", "");
                    HtmlPage.Document.GetElementById("comment_editor").SetStyleAttribute("display", "");

                    LoadComments();

                    CommentForm.Visibility = Visibility.Visible;
                }
                else
                {
                    HtmlPage.Document.GetElementById("comment_area").SetStyleAttribute("display", "none");
                    HtmlPage.Document.GetElementById("comment_editor").SetStyleAttribute("display", "none");

                    CommentForm.Visibility = Visibility.Collapsed;
                }

                AboutText.Text = settings.about_text;
            }
        }