private void GenerateOrdersPage(List <Order> orders)
        {
            // Generating page of orders
            Label header = new Label {
                Text              = "Your Cart:",
                FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center
            };

            ActivityIndicator AI = new ActivityIndicator();

            AI.IsRunning = false;

            // Adding all food items to imagecells
            List <ImageCell> orderDBLinks = new List <ImageCell>();

            foreach (Order order in orders)
            {
                ImageCell cellItem = new ImageCell {
                    // Some differences with loading images in initial release.
                    ImageSource = new Uri("http://www.lexingtoncolony.com/wp-content/uploads/2014/07/dinner-thumbnail.png"),
                    Text        = $"Your Order [ {order.Date} ] - Total: ${order.TotalPrice}",
                    Detail      = $"Food Items: {order.FoodNames}"
                };
                cellItem.Tapped += async(sender, args) => {
                    var answer = await DisplayAlert($"Cancel Order", "Would you like to cancel this order?", "Yes", "No");

                    if (answer)
                    {
                        // Remove it from database
                        await AzureManager.AzureManagerInstance.CancelOrder(order);

                        orders.Remove(order);
                        await DisplayAlert("SUCCESS", "Successfuly cancelled your order", "OK");

                        if (orders.Count == 0)
                        {
                            MenuPage.ChangePage(new NavigationPage(new TabbedPage {
                                Children = { new OrderPage(), new PlacedOrdersPage() }
                            }));                                                                                                                    // FIX THIS
                        }
                        else
                        {
                            OnAppearing();
                        }
                    }
                };
                orderDBLinks.Add(cellItem);
            }

            TableView tableView = new TableView {
                Intent = TableIntent.Form,
                Root   = new TableRoot {
                    new TableSection {
                        orderDBLinks
                    }
                }
            };

            // Build the page.
            Content = new StackLayout {
                Children = { header, tableView, AI }
            };
        }
예제 #2
0
        private void Change(object sender, EventArgs e)
        {
            Label passLbl = new Label {
                Text     = "Enter curent password:"******"Password*",
                IsPassword  = true
            };
            Entry pass2 = new Entry {
                Placeholder = "Current Password*",
                IsPassword  = true
            };
            Button confirm = new Button {
                Text              = "Confirm",
                TextColor         = Color.White,
                BackgroundColor   = Color.Green,
                Font              = Font.SystemFontOfSize(NamedSize.Large),
                BorderWidth       = 1,
                HorizontalOptions = LayoutOptions.StartAndExpand,
            };

            confirm.Clicked += async(sender2, e2) => {
                if (pass1.Text == null || pass2.Text == null || pass1.Text.Length < 1 || pass2.Text.Length < 1)
                {
                    await DisplayAlert("Incomplete Information", "Please complete the password fields", "OK");
                }
                else if (pass1.Text != pass2.Text)
                {
                    await DisplayAlert("Password mismatch error", "Please enter identical passwords in the displayed fields", "OK");
                }
                else if (pass1.Text != User.CurrentUserInstance.Password)
                {
                    await DisplayAlert("Password Incorrect", "Please enter correct current password", "OK");
                }
                else
                {
                    // CHECK IF USER WITH SAME EMAIL EXISTS TO PREVENT CLASHES/DUPLICATES
                    User changedUser = new User()
                    {
                        ID       = User.CurrentUserInstance.ID,
                        Name     = usernameEntry.Text ?? User.CurrentUserInstance.Name,
                        Email    = (emailEntry.Text == null || emailEntry.Text.Length < 1) ? User.CurrentUserInstance.Email : emailEntry.Text,
                        Password = (passwordEntry.Text == null || passwordEntry.Text.Length < 1) ? User.CurrentUserInstance.Password : passwordEntry.Text,
                        Photo    = User.CurrentUserInstance.Photo,
                        Phone    = phoneEntry.Text ?? User.CurrentUserInstance.Phone,
                        Address  = addressEntry.Text ?? User.CurrentUserInstance.Address,
                        Date     = DateTime.Now
                    };
                    await AzureManager.AzureManagerInstance.UpdateUser(changedUser);
                    await DisplayAlert("SUCCESS", "Successfuly changed your details", "OK");

                    MenuPage.GoHomeAfterLogin(changedUser);
                }
            };
            Button goBack = new Button {
                Text              = "Back",
                TextColor         = Color.White,
                BackgroundColor   = Color.Red,
                Font              = Font.SystemFontOfSize(NamedSize.Large),
                BorderWidth       = 1,
                HorizontalOptions = LayoutOptions.EndAndExpand,
            };

            goBack.Clicked += (sender2, e2) => {
                MenuPage.ChangePage(MenuPage.pages[5]);
            };
            MenuPage.ChangePage(new NavigationPage(new ContentPage {
                Content = new StackLayout {
                    Children = { passLbl, pass1, pass2, new Grid {
                                     Children = { confirm,goBack }
                                 } }
                }
            }));
        }
        private Page GenerateItemPage(Food item)
        {
            Label category = new Label {
                Text      = $"{item.Category.ToUpper()}",
                TextColor = Color.Blue,
                FontSize  = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                HorizontalTextAlignment = TextAlignment.Center
            };
            Image image = new Image {
                Source = item.Photo,
                Aspect = Aspect.AspectFit
            };
            Label name = new Label {
                Text      = $"{item.Name}",
                TextColor = Color.Blue,
                FontSize  = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                HorizontalTextAlignment = TextAlignment.Center
            };
            Label description = new Label {
                Text     = $"{item.Description}",
                FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                HorizontalTextAlignment = TextAlignment.Center
            };

            Label price = new Label {
                Text      = $"Cost: ${ item.Price}",
                TextColor = Color.Red,
                FontSize  = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                Margin    = 20,
                HorizontalTextAlignment = TextAlignment.End
            };
            Button addToCart = new Button {
                Text              = "ADD TO CART",
                BackgroundColor   = Color.Green,
                Font              = Font.SystemFontOfSize(NamedSize.Large),
                BorderWidth       = 1,
                HorizontalOptions = LayoutOptions.Fill,
            };

            addToCart.Clicked += async(sender, e) => {
                if (User.CurrentUserInstance.Name != null)
                {
                    Food.CartInstance.Add(item);
                    await DisplayAlert("Success", $"Successfully added {item.Name} to cart", "OK");
                }
                else
                {
                    var res = await DisplayAlert("Failed", "Please login to place an order", "Login", "Cancel");

                    if (res)
                    {
                        MenuPage.ChangePage(MenuPage.pages[3], 3);
                    }
                }
            };
            Button toCartBtn = new Button {
                Text              = "View Cart",
                TextColor         = Color.White,
                BackgroundColor   = Color.Blue,
                Font              = Font.SystemFontOfSize(NamedSize.Small),
                BorderWidth       = 1,
                HorizontalOptions = LayoutOptions.Fill,
            };

            toCartBtn.Clicked += (sender, e) => {
                MenuPage.ChangePage(MenuPage.pages[2], 2);
            };
            Button backToMenu = new Button {
                Text              = "BACK",
                BackgroundColor   = Color.Red,
                Font              = Font.SystemFontOfSize(NamedSize.Small),
                BorderWidth       = 1,
                HorizontalOptions = LayoutOptions.End,
            };

            backToMenu.Clicked += (sender, e) => {
                MenuPage.ChangePage(MenuPage.pages[1]);
            };

            return(new NavigationPage(new ContentPage {
                Content = new StackLayout {
                    Children = { category, image, name, description, price, addToCart, toCartBtn, backToMenu }
                }
            }));
        }
예제 #4
0
 private void LogoutClicked(object sender, EventArgs e)
 {
     MenuPage.Logout();
     OnAppearing();
 }