public async void DeleteItem(object Index)
        {
            try
            {
                OrdersItems = await client.GetAllOfflineSyncItemsAsync <OrderItems>(OrdersItemsTable);

                Item  item   = CartItems[(int)Index];
                Order Order  = Orders.FirstOrDefault(o => (o.UserID == SharedUser.ID && (o.SubmittedOffline == false || o.SubmittedOnline == false)));
                var   orderi = OrdersItems.FirstOrDefault(oi => oi.ItemID == item.ID && oi.OrderID == Order.ID);
                OrdersItems.Remove(orderi);

                await client.DeleteOfflineSyncObjectAsync(orderi, OrdersItemsTable);

                if (CartItems.Contains(CartItems[(int)Index]))
                {
                    CartItems.Remove(CartItems[(int)Index]);
                    if (CartItems.Count == 0)
                    {
                        IsCartNotEmpty = false;
                    }
                }
                await Application.Current.MainPage.Navigation.PopAsync();

                await NavigationHelper.NavigateToPageAsync(new ShoppingCartPage());
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Message : {ex.Message} \n StackTrace : {ex.StackTrace}");
            }
        }
Esempio n. 2
0
        public IActionResult OnGetBuy(int id)
        {
            var product = productData.GetProductById(id);

            if (HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems") != null)
            {
                CartItems = HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems").ToList();
                var productiInCart = CartItems.SingleOrDefault(x => x.Product.Id == id);

                if (CartItems.Contains(productiInCart))
                {
                    return(RedirectToPage("./ShoppingCart"));
                }
            }
            CartItems.Add(cartBL.AddCartItem(product));

            HttpContext.Session.SetObjectAsJson("CartItems", CartItems);
            CartItems = HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems").ToList();
            return(RedirectToPage("./ShoppingCart"));
            //return Page();
        }
        public async void DeleteItemFromSQLLite(object Index)
        {
            try
            {
                await _connection.DeleteAsync(SQLITEItems[(int)Index]);

                if (CartItems.Contains(CartItems[(int)Index]))
                {
                    CartItems.Remove(CartItems[(int)Index]);
                    if (CartItems.Count == 0)
                    {
                        IsCartNotEmpty = false;
                    }
                }
                await Application.Current.MainPage.Navigation.PopAsync();

                await NavigationHelper.NavigateToPageAsync(new ShoppingCartPage());
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Message : {ex.Message} \n StackTrace : {ex.StackTrace}");
            }
        }
Esempio n. 4
0
 public bool Contains(CartItem item)
 {
     return(CartItems.Contains(item));
 }