Пример #1
0
        private async void AddToWish_Click(object sender, EventArgs e)
        {
            var attributes = await HasAttributes(SelectedProduct.Id);

            if (!attributes)
            {
                StackPanel     s        = new StackPanel();
                PhoneTextBox   Quantity = new PhoneTextBox();
                InputScope     scope    = new InputScope();
                InputScopeName number   = new InputScopeName();

                number.NameValue = InputScopeNameValue.Number;
                scope.Names.Add(number);
                Quantity.Hint       = "Quantity";
                Quantity.InputScope = scope;
                s.Children.Add(Quantity);
                CustomMessageBox messageBox = new CustomMessageBox()
                {
                    Caption            = "Select Quantity",
                    Message            = "Select how many " + SelectedProduct.Name + " do you want?",
                    LeftButtonContent  = "Add To Wishlist",
                    Content            = s,
                    RightButtonContent = "Cancel"
                };
                messageBox.Show();
                messageBox.Dismissed += async(s1, e1) =>
                {
                    switch (e1.Result)
                    {
                    case CustomMessageBoxResult.LeftButton:
                        var Customer = await api.GetCustomersByEmail(Helper.CurrentCustomer());

                        if (Quantity.Text == "")
                        {
                            Quantity.Text = "1";
                        }
                        var AddResult = await api.AddToCart(Customer.First().Email, SelectedProduct.Id, Int32.Parse(Quantity.Text), new String[] { "" }, ShoppingCartType.Wishlist);

                        if (AddResult)
                        {
                            CustomMessageBox SuccessToast = new CustomMessageBox()
                            {
                                Caption           = "Added Successfully",
                                Message           = "The product was added to your wishlist sucessfuly",
                                LeftButtonContent = "Dismiss"
                            };
                            SuccessToast.Show();
                            await Task.Delay(2000);

                            SuccessToast.Dismiss();
                        }
                        break;
                    }
                };
            }
            else
            {
                NavigationService.Navigate(new Uri("/Pages/ProductDetails.xaml?ProdId=" + SelectedProduct.Id, UriKind.Relative));
            }
        }
Пример #2
0
        private async void AddToCustomerCart(object sender, RoutedEventArgs e)
        {
            DependencyObject tappedElement = e.OriginalSource as UIElement;
            var         List       = this.FindParentOfType <ItemsControl>(tappedElement);
            var         ListName   = List.Name;
            var         TappedItem = this.FindParentOfType <ContentPresenter>(tappedElement);
            ProductData item       = null;

            if (ListName.Equals("BestsellersList"))
            {
                item = BestsellersList.ItemContainerGenerator.ItemFromContainer(TappedItem) as ProductData;
            }
            else
            {
                item = FeaturedProducts.ItemContainerGenerator.ItemFromContainer(TappedItem) as ProductData;
            }
            var Prod = await api.GetProductById(item.Id);

            if (Prod.Attributes.Count > 0)
            {
                NavigationService.Navigate(new Uri("/Pages/ProductDetails.xaml?ProdId=" + Prod.Id, UriKind.Relative));
            }
            else
            {
                StackPanel     s        = new StackPanel();
                PhoneTextBox   Quantity = new PhoneTextBox();
                InputScope     scope    = new InputScope();
                InputScopeName number   = new InputScopeName();

                number.NameValue = InputScopeNameValue.Number;
                scope.Names.Add(number);
                Quantity.Hint       = "Quantity";
                Quantity.InputScope = scope;
                s.Children.Add(Quantity);
                CustomMessageBox messageBox = new CustomMessageBox()
                {
                    Caption            = "Select Quantity",
                    Message            = "Select how many " + item.ProductName + " do you want?",
                    LeftButtonContent  = "Add To Cart",
                    Content            = s,
                    RightButtonContent = "Cancel"
                };
                messageBox.Show();
                messageBox.Dismissed += async(s1, e1) =>
                {
                    switch (e1.Result)
                    {
                    case CustomMessageBoxResult.LeftButton:
                        if (Quantity.Text == "")
                        {
                            Quantity.Text = "1";
                        }
                        var AddResult = await api.AddToCart(Customer.Email, item.Id, Int32.Parse(Quantity.Text), new String [] { "" }, ShoppingCartType.ShoppingCart);

                        if (AddResult)
                        {
                            CustomMessageBox SuccessToast = new CustomMessageBox()
                            {
                                Caption           = "Added Successfully",
                                Message           = "The product was added to your cart sucessfuly",
                                LeftButtonContent = "Dismiss"
                            };
                            SuccessToast.Show();
                            await Task.Delay(2500);

                            SuccessToast.Dismiss();
                        }
                        RefreshCart();
                        break;
                    }
                };
            }
        }
Пример #3
0
        private void AddToWishlist_Click(object sender, EventArgs e)
        {
            StackPanel     s        = new StackPanel();
            PhoneTextBox   Quantity = new PhoneTextBox();
            InputScope     scope    = new InputScope();
            InputScopeName number   = new InputScopeName();

            number.NameValue = InputScopeNameValue.Number;
            scope.Names.Add(number);
            Quantity.Hint       = "Quantity";
            Quantity.InputScope = scope;
            s.Children.Add(Quantity);
            CustomMessageBox messageBox = new CustomMessageBox()
            {
                Caption            = "Select Quantity",
                Message            = "Select how many " + Product.Name + " do you want?",
                LeftButtonContent  = "Add To Cart",
                Content            = s,
                RightButtonContent = "Cancel"
            };

            messageBox.Show();
            messageBox.Dismissed += async(s1, e1) =>
            {
                switch (e1.Result)
                {
                case CustomMessageBoxResult.LeftButton:
                    var Current    = "";
                    var allChecked = true;
                    UserSettings.TryGetValue <string>("current_user", out Current);
                    var AttributesArray = new List <string>();
                    for (int i = 0; i < Product.Attributes.Count; i++)
                    {
                        switch (Product.Attributes[i].AttributeControl)
                        {
                        case AttributeControlType.TextBox:
                            var TmpText = (PhoneTextBox)Controls[i];
                            if (TmpText.Text.Equals("") && Product.Attributes[i].isRequired)
                            {
                                MessageBox.Show("You must fill " + Product.Attributes[i].Name);
                                allChecked = false;
                            }
                            AttributesArray.Add(TmpText.Text);
                            break;

                        case AttributeControlType.DropdownList:
                            var TmpDrop = (ListPicker)Controls[i];
                            if (TmpDrop.SelectedItem == null && Product.Attributes[i].isRequired)
                            {
                                MessageBox.Show("You must select " + Product.Attributes[i].Name);
                                allChecked = false;
                            }
                            AttributesArray.Add(TmpDrop.SelectedItem.ToString());
                            break;

                        case AttributeControlType.MultilineTextbox:
                            var TmpTextM = (PhoneTextBox)Controls[i];
                            if (TmpTextM.Text.Equals("") && Product.Attributes[i].isRequired)
                            {
                                MessageBox.Show("You must fill " + Product.Attributes[i].Name);
                                allChecked = false;
                            }
                            AttributesArray.Add(TmpTextM.Text);
                            break;

                        case AttributeControlType.RadioList:
                            var TmpRadio = (List <RadioButton>)Controls[i];
                            var Count    = 0;
                            foreach (RadioButton r in TmpRadio)
                            {
                                if ((bool)r.IsChecked)
                                {
                                    AttributesArray.Add(r.Content.ToString());
                                    Count++;
                                }
                            }
                            if (Count == 0 && Product.Attributes[i].isRequired)
                            {
                                MessageBox.Show("You must select " + Product.Attributes[i].Name);
                                allChecked = false;
                            }
                            break;

                        case AttributeControlType.Checkboxes:
                            var TmpCheck   = (List <CheckBox>)Controls[i];
                            var CountCheck = 0;
                            foreach (CheckBox r in TmpCheck)
                            {
                                if ((bool)r.IsChecked)
                                {
                                    AttributesArray.Add(r.Content.ToString());
                                    CountCheck++;
                                }
                            }
                            if (CountCheck == 0 && Product.Attributes[i].isRequired)
                            {
                                MessageBox.Show("You must select " + Product.Attributes[i].Name);
                                allChecked = false;
                            }
                            break;
                        }
                    }
                    if (allChecked)
                    {
                        if (Quantity.Text == "")
                        {
                            Quantity.Text = "1";
                        }
                        var AddResult = await api.AddToCart(Current, Product.Id, Int32.Parse(Quantity.Text), AttributesArray.ToArray(), ShoppingCartType.Wishlist);

                        if (AddResult)
                        {
                            RefreshCart = true;
                            CustomMessageBox SuccessToast = new CustomMessageBox()
                            {
                                Caption           = "Added Successfully",
                                Message           = "The product was added to your wishlist sucessfuly",
                                LeftButtonContent = "Dismiss"
                            };
                            SuccessToast.Show();
                            await Task.Delay(2500);

                            SuccessToast.Dismiss();
                        }
                    }
                    break;
                }
            };
        }