Esempio n. 1
0
        protected override void OnResume()
        {
            mPage = new Ecombeta.Views.Home("Mica Market")
            {
            };


            MainPage = new NavigationPage(mPage);

            CrossFirebasePushNotification.Current.Subscribe("general");
            CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine($"TOKEN REC: {p.Token}");
            };


            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
                try
                {
                    System.Diagnostics.Debug.WriteLine("Received");
                    if (p.Data.ContainsKey("body") && p.Data.ContainsKey("title"))
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            mPage.Message      = $"{p.Data["body"]}";
                            mPage.TitleMessage = $"{p.Data["title"]}";
                        });
                    }
                }
                catch (Exception ex)
                {
                }
            };
            CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
            {
                //System.Diagnostics.Debug.WriteLine(p.Identifier);

                System.Diagnostics.Debug.WriteLine("Opened");
                foreach (var data in p.Data)
                {
                    System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
                }

                if (!string.IsNullOrEmpty(p.Identifier))
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        mPage.Message = p.Identifier;
                    });
                }
                else if (p.Data.ContainsKey("color"))
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        mPage.Navigation.PushAsync(new ContentPage()
                        {
                            BackgroundColor = Color.FromHex($"{p.Data["color"]}")
                        });
                    });
                }
                else if (p.Data.ContainsKey("title"))
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        mPage.TitleMessage = $"{p.Data["title"]}";
                    });
                }
            };

            CrossFirebasePushNotification.Current.OnNotificationAction += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("Action");

                if (!string.IsNullOrEmpty(p.Identifier))
                {
                    System.Diagnostics.Debug.WriteLine($"ActionId: {p.Identifier}");
                    foreach (var data in p.Data)
                    {
                        System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
                    }
                }
            };

            CrossFirebasePushNotification.Current.OnNotificationDeleted += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("Dismissed");
            };

            MainPage = new NavigationPage(mPage);
        }
Esempio n. 2
0
        private async void ImageButton_Clicked(object sender, EventArgs e)
        {
            //You cant checkout if your not logged in There are no Guest Checkouts(I can But would rather not)
            if (Users.Loggedin == true)
            {
                if (Lineitems == null)
                {
                    Lineitems = new List <OrderLineItem>();
                }

                RestAPI rest = new RestAPI("http://mm-app.co.za/wp-json/wc/v2/", "ck_a25f96835aabfc64b09613eb8ec4a8c9bcd5dcd0", "cs_8f247c22353f25b905c96171379b89714f8f4003");
                WooCommerceNET.WooCommerce.v2.WCObject wc = new WooCommerceNET.WooCommerce.v2.WCObject(rest);
                Check();
                var order = new WooCommerceNET.WooCommerce.v2.Order()
                {
                    status = "on-hold", customer_id = Users.CId
                };
                foreach (var item in z)
                {
                    var a = Convert.ToInt32(item.Pquantity);
                    if (item.variation_id <= 0)
                    {
                        item.variation_id = item.PId;
                    }

                    if (item.StockQuantity == 0)
                    {
                        NoMore = true;
                        Productname.Add(item.Pname);
                    }
                    order.line_items = order.line_items ?? new List <OrderLineItem>();
                    order.line_items.Add(new OrderLineItem()
                    {
                        product_id = item.PId, variation_id = item.variation_id, quantity = a
                    });
                }

                if (NoMore)
                {
                    var yx = await DisplayAlert("Order Cant be Placed", $"Not enough stock for {Productname}", "Back to Cart", "Home");

                    if (yx)
                    {
                    }
                    else
                    {
                        await Navigation.PushAsync(new Home("Mica Market"));
                    }
                }
                else
                {
                    if (items != null)
                    {
                        await wc.Order.Add(order);

                        var masterDetailPage = new Home("");
                        masterDetailPage.Detail      = new NavigationPage(new Checkedout());
                        Application.Current.MainPage = masterDetailPage;
                    }
                    else
                    {
                        var masterDetailPage = new Home("");
                        masterDetailPage.Detail      = new NavigationPage(new CartEmprty());
                        Application.Current.MainPage = masterDetailPage;
                    }
                }
            }
            else
            {
                var y = await DisplayAlert("Woops", "Please Login to check Out", "Login", "Home");

                if (y)
                {
                    var masterDetailPage = new Home("");
                    masterDetailPage.Detail      = new NavigationPage(new Login());
                    Application.Current.MainPage = masterDetailPage;
                }
                else
                {
                    await Navigation.PushAsync(new Home("Mica Market"));
                }
            }
        }