コード例 #1
0
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            int Id = (int)e.NavigationParameter;

            this.progressRing.IsActive = true;

            var Item = await CoursesSource.GetCourseAsync(Id);

            this.progressRing.IsActive = false;

            if (Item == null)
            {
                if (Frame.CanGoBack)
                {
                    Frame.GoBack();

                    await ShowErrorAsync();
                }
                else
                {
                    if (!Frame.Navigate(typeof(MainPage), "FoodLook 2"))
                    {
                        throw new Exception();
                    }
                    Frame.BackStack.Clear();

                    await ShowErrorAsync();
                }
            }
            else
            {
                this.DefaultViewModel[CourseItem] = Item;
                this.DefaultViewModel[Label]      = Item.Label;

                this.LikeButtonToggle();
                this.FavoriteButtonToggle();

                if (Item.Vegetarian)
                {
                    this.Vegetarian.Text = ResourceLoader.GetForCurrentView("Resources").GetString("Vegetarian");
                }
                else
                {
                    this.Vegetarian.Text = ResourceLoader.GetForCurrentView("Resources").GetString("Unvegetarian");
                }

                this.CoursePageCommandBar.Visibility = Visibility.Visible;

                this.CoursePagePivot.Visibility = Visibility.Visible;
            }
        }
コード例 #2
0
        private async void FavoriteButton_Click(object sender, RoutedEventArgs e)
        {
            var Item = this.DefaultViewModel[CourseItem] as Course;

            var statusBar = StatusBar.GetForCurrentView();

            statusBar.ProgressIndicator.Text          = ResourceLoader.GetForCurrentView("Resources").GetString("UpdateMessage");
            statusBar.ProgressIndicator.ProgressValue = null;
            await statusBar.ProgressIndicator.ShowAsync();

            this.FavoriteButton.IsEnabled = false;

            if (Item.CourseSocial.FavoriteId == -1)
            {
                bool isSuccess = await CoursesSource.AddToFavoriteAsync(Item.Id);

                await statusBar.ProgressIndicator.HideAsync();

                if (isSuccess)
                {
                    ShowMessageAsync(ResourceLoader.GetForCurrentView("Resources").GetString("FavoriteSuccessfulAdding"));
                }
                else
                {
                    ShowMessageAsync(ResourceLoader.GetForCurrentView("Resources").GetString("ErrorMessage"));
                }

                FavoriteButtonToggle();
            }
            else
            {
                bool isSuccess = await CoursesSource.RemoveFromFavoriteAsync(Item.Id);

                await statusBar.ProgressIndicator.HideAsync();

                if (isSuccess)
                {
                    ShowMessageAsync(ResourceLoader.GetForCurrentView("Resources").GetString("FavoriteSuccessfulRemoving"));
                }
                else
                {
                    ShowMessageAsync(ResourceLoader.GetForCurrentView("Resources").GetString("ErrorMessage"));
                }

                FavoriteButtonToggle();
            }

            this.FavoriteButton.IsEnabled = true;
        }